Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [1.2.2] - 2021-04-21

### Fixes & Improvements.
 - Fix error 'Unable to find required resource at Fonts/consola.ttf' when using logcat package with 2021.2.
 - Provide user friendly message when NDK directory is incorrect or is not set.
 - The NDK presence will only be checked when it's actually needed, for ex., when resolving stacktraces.
 - Don't show Add/Remove Tag menu item, if tag is empty.
 - Don't show Filter By Process Id menu item, if process id is invalid.
 - When using AutoRun, logcat will appear automatically if you're building only for Android, previously it would appear for any platform, which is undesired.
  • Loading branch information
Unity Technologies committed Apr 21, 2021
1 parent 817c1b2 commit 0f42611
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 69 deletions.
20 changes: 15 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.2.2] - 2021-04-21

### Fixes & Improvements.
- Fix error 'Unable to find required resource at Fonts/consola.ttf' when using logcat package with 2021.2.
- Provide user friendly message when NDK directory is incorrect or is not set.
- The NDK presence will only be checked when it's actually needed, for ex., when resolving stacktraces.
- Don't show Add/Remove Tag menu item, if tag is empty.
- Don't show Filter By Process Id menu item, if process id is invalid.
- When using AutoRun, logcat will appear automatically if you're building only for Android, previously it would appear for any platform, which is undesired.

## [1.2.1] - 2021-01-21

### Fix & Improvements.
### Fixes & Improvements.
- Removed limitation where Android Logcat could only be used while the active Editor platform is Android. Note: Android Support is still required to be installed for Android Logcat to work.
- Fix Memory Window on Android 11. Android 11 started dumping RSS memory, which was previously unexpected by Memory Window.
- Include RSS memory in Memory window.
Expand All @@ -22,7 +32,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [1.2.0] - 2020-08-18

### Fix & Improvements.
### Fixes & Improvements.
- Correctly resolve top activity when device is locked.
- Improved Stacktrace Utility, it's easier to set symbol paths and regexes.
- Consola font is now selectable in Logcat settings.
Expand All @@ -45,13 +55,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [1.1.1] - 2020-03-12

### Fix & Improvements.
### Fixes & Improvements.
- Fix warnings in scripts when active Editor platform is not Android.
- Fix regex issues with logcat messages.

## [1.1.0] - 2020-02-14

### Fix & Improvements.
### Fixes & Improvements.
- Added feature 'Filter by process id'
- Fixed addr2line functionality, when we try to resolve stacktrace
- Correctly open Terminal on macOS Catalina
Expand All @@ -72,7 +82,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [1.0.0] - 2019-07-18

### Fix & Improvements.
### Fixes & Improvements.
- Added Open Terminal button
- Use monospace font for displaying log messages, this makes text align properly when displaying addresses
- Fix performance issues whene there's no Android device attached, the device querying will happen on worker thread.
Expand Down
4 changes: 3 additions & 1 deletion Editor/AndroidLogcatCallbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ internal class AndroidLogcatCallbacks : IPostprocessBuildWithReport

public void OnPostprocessBuild(BuildReport report)
{
if ((report.summary.options & BuildOptions.AutoRunPlayer) != 0 && AndroidLogcatConsoleWindow.ShowDuringBuildRun)
if ((report.summary.options & BuildOptions.AutoRunPlayer) != 0 &&
report.summary.platform == BuildTarget.Android &&
AndroidLogcatConsoleWindow.ShowDuringBuildRun)
AndroidLogcatConsoleWindow.ShowNewOrExisting(true);
}
}
Expand Down
70 changes: 70 additions & 0 deletions Editor/AndroidLogcatContextMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using UnityEditor;
using UnityEngine;

namespace Unity.Android.Logcat
{
internal enum ContextMenuItem
{
None,
Copy,
SelectAll,
SaveSelection,
AddTag,
RemoveTag,
FilterByProcessId
}

class AndroidContextMenu
{
internal class MenuItemData
{
public ContextMenuItem Item { get; }
public string Name { get; }

public MenuItemData(ContextMenuItem item, string name)
{
Item = item;
Name = name;
}
}

public object UserData { set; get; }

private List<MenuItemData> m_Items = new List<MenuItemData>();

public void Add(ContextMenuItem item, string name)
{
m_Items.Add(new MenuItemData(item, name));
}

public void AddSplitter()
{
Add(ContextMenuItem.None, string.Empty);
}

public string[] Names => m_Items.Select(i => i.Name).ToArray();

public MenuItemData GetItemAt(int selected)
{
if (selected < 0 || selected > m_Items.Count - 1)
return null;
return m_Items[selected];
}

public void Show(Vector2 mousePosition, EditorUtility.SelectMenuItemFunction callback)
{
var enabled = Enumerable.Repeat(true, Names.Length).ToArray();
var separator = new bool[Names.Length];
EditorUtility.DisplayCustomMenuWithSeparators(new Rect(mousePosition.x, mousePosition.y, 0, 0),
Names,
enabled,
separator,
null,
callback,
this);
}
}
}
11 changes: 11 additions & 0 deletions Editor/AndroidLogcatContextMenu.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

106 changes: 59 additions & 47 deletions Editor/AndroidLogcatMessagesViews.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,27 +436,70 @@ void DoContextMenu(Event e)
continue;
entries.Add(m_LogEntries[si]);
}
var menuItems = new List<string>();
menuItems.AddRange(new[] { "Copy", "Select All", "", "Save Selection..." });

var contextMenu = new AndroidContextMenu();
contextMenu.Add(ContextMenuItem.Copy, "Copy");
contextMenu.Add(ContextMenuItem.SelectAll, "Select All");
contextMenu.AddSplitter();
contextMenu.Add(ContextMenuItem.SaveSelection, "Save Selection...");

if (entries.Count > 0)
{
menuItems.Add("");
menuItems.Add("Add tag '" + entries[0].tag + "'");
menuItems.Add("Remove tag '" + entries[0].tag + "'");
menuItems.Add("");
menuItems.Add("Filter by process id '" + entries[0].processId + "'");
var tag = entries[0].tag;
if (!string.IsNullOrEmpty(tag))
{
contextMenu.AddSplitter();
contextMenu.Add(ContextMenuItem.AddTag, $"Add tag '{tag}'");
contextMenu.Add(ContextMenuItem.RemoveTag, $"Remove tag '{tag}'");
}

var processId = entries[0].processId;
if (processId >= 0)
{
contextMenu.AddSplitter();
contextMenu.Add(ContextMenuItem.FilterByProcessId, $"Filter by process id '{processId}'");
}
}

var enabled = Enumerable.Repeat(true, menuItems.Count).ToArray();
var separator = new bool[menuItems.Count];
EditorUtility.DisplayCustomMenuWithSeparators(new Rect(e.mousePosition.x, e.mousePosition.y, 0, 0),
menuItems.ToArray(),
enabled,
separator,
null,
MenuSelection,
entries.ToArray());
contextMenu.UserData = entries.ToArray();
contextMenu.Show(e.mousePosition, MenuSelection);
}

private void MenuSelection(object userData, string[] options, int selected)
{
var contextMenu = (AndroidContextMenu)userData;
var entries = (AndroidLogcat.LogEntry[])contextMenu.UserData;
var item = contextMenu.GetItemAt(selected);
if (item == null)
return;

switch (item.Item)
{
// Copy
case ContextMenuItem.Copy:
EditorGUIUtility.systemCopyBuffer = LogEntriesToString(entries);
break;
// Select All
case ContextMenuItem.SelectAll:
SelectAll();
break;
// Save to File
case ContextMenuItem.SaveSelection:
SaveToFile(entries);
break;
// Add tag
case ContextMenuItem.AddTag:
AddTag(entries[0].tag);
break;
// Remove tag
case ContextMenuItem.RemoveTag:
RemoveTag(entries[0].tag);
break;
// Filter by process id
case ContextMenuItem.FilterByProcessId:
FilterByProcessId(entries[0].processId);
break;
}
}

private bool DoMouseEventsForLogEntry(Rect logEntryRect, int logEntryIndex, bool isLogEntrySelected, int keyboardControlId)
Expand Down Expand Up @@ -589,37 +632,6 @@ private string LogEntriesToString(AndroidLogcat.LogEntry[] entries)
return contents.ToString();
}

private void MenuSelection(object userData, string[] options, int selected)
{
switch (selected)
{
// Copy
case 0:
EditorGUIUtility.systemCopyBuffer = LogEntriesToString((AndroidLogcat.LogEntry[])userData);
break;
// Select All
case 1:
SelectAll();
break;
// Save to File
case 3:
SaveToFile((AndroidLogcat.LogEntry[])userData);
break;
// Add tag
case 5:
AddTag(((AndroidLogcat.LogEntry[])userData)[0].tag);
break;
// Remove tag
case 6:
RemoveTag(((AndroidLogcat.LogEntry[])userData)[0].tag);
break;
// Filter by process id
case 8:
FilterByProcessId(((AndroidLogcat.LogEntry[])userData)[0].processId);
break;
}
}

private void TryToOpenFileFromLogEntry(AndroidLogcat.LogEntry entry)
{
Regex re = new Regex(@"at.*\s([^\s]+):(\d+)");
Expand Down
15 changes: 14 additions & 1 deletion Editor/AndroidLogcatStacktraceWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,23 @@ void ResolveStacktraces()
m_ResolvedStacktraces = String.Empty;
if (string.IsNullOrEmpty(m_Text))
{
m_ResolvedStacktraces = string.Format(" <color={0}>(Please add some log with addresses first)</color>", m_RedColor);
m_ResolvedStacktraces = $"<color={m_RedColor}>Please add some log with addresses first.</color>";
return;
}

if (m_Runtime.Settings.StacktraceResolveRegex.Count == 0)
{
m_ResolvedStacktraces = $"<color={m_RedColor}>No stacktrace regular expressions found.\nClick <b>Configure Regex</b> and configure Stacktrace Regex.</color>";
return;
}

if (m_Runtime.UserSettings.SymbolPaths.Count == 0)
{
m_ResolvedStacktraces = $"<color={m_RedColor}>At least one symbol path needs to be specified.\nClick Configure Symbol Paths and add the necessary symbol path.</color>";
return;
}


var lines = m_Text.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
m_ResolvedStacktraces = ResolveAddresses(lines, m_Runtime.Settings.StacktraceResolveRegex, m_Runtime.UserSettings.SymbolPaths, m_Runtime.Tools);
}
Expand Down
2 changes: 1 addition & 1 deletion Editor/AndroidLogcatStyles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static class AndroidLogcatStyles

public static Font GetFont()
{
return (Font)EditorGUIUtility.LoadRequired(UnityEditor.Experimental.EditorResources.fontsPath + "consola.ttf");
return (Font)EditorGUIUtility.LoadRequired("Packages/com.unity.mobile.android-logcat/Editor/Resources/consola.ttf");
}

internal class StatusWheel
Expand Down
Loading

0 comments on commit 0f42611

Please sign in to comment.