Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions AdbExtension/AdbExtension.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>

<WindowsPackageType>None</WindowsPackageType>
<AppxPackageVersion>1.0.0.1</AppxPackageVersion>
<AppxPackageVersion>1.0.0.2</AppxPackageVersion>
<EnableMsixTooling>true</EnableMsixTooling>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down Expand Up @@ -87,12 +87,8 @@
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'!='Debug'">
<!-- In Release builds, trimming is enabled by default.
feel free to disable this if needed -->
<PublishTrimmed>true</PublishTrimmed>

<!-- In release, also ignore the aforementioned ILLink warning -->
<ILLinkTreatWarningsAsErrors>false</ILLinkTreatWarningsAsErrors>
<!-- Trimming disabled: Shmuelie.WinRTServer is not trim-safe and crashes at startup when trimmed -->
<PublishTrimmed>false</PublishTrimmed>
</PropertyGroup>


Expand Down
28 changes: 24 additions & 4 deletions AdbExtension/Helpers/Log.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
using System;
using System.Diagnostics;
using System.IO;

namespace AdbExtension;

internal static class Log
{
public static void Info(string message) => Write("INFO", message);
private static readonly string _logPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"AdbExtension", "logs", $"adbextension-{DateTime.Now:yyyy-MM-dd}.log");

static Log()
{
try { Directory.CreateDirectory(Path.GetDirectoryName(_logPath)!); }
catch { /* if we can't create the log dir, file writes will just fail silently */ }
}

public static void Info(string message) => Write("INFO", message, writeToFile: false);

public static void Error(string message, Exception? ex = null)
{
Write("ERROR", ex is null ? message : $"{message} — {ex.GetType().Name}: {ex.Message}");
var text = ex is null ? message : $"{message} — {ex.GetType().Name}: {ex.Message}\n{ex.StackTrace}";
Write("ERROR", text, writeToFile: true);
}

private static void Write(string level, string message)
=> Trace.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] [{level}] {message}");
private static void Write(string level, string message, bool writeToFile)
{
var line = $"[{DateTime.Now:HH:mm:ss.fff}] [{level}] {message}";
Trace.WriteLine(line);
if (writeToFile)
{
try { File.AppendAllText(_logPath, line + Environment.NewLine); }
catch { /* don't crash the app if logging fails */ }
}
}
}
2 changes: 1 addition & 1 deletion AdbExtension/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Identity
Name="AdbExtension"
Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US"
Version="1.0.0.1" />
Version="1.0.0.2" />
<!-- When you're ready to publish your extension, you'll need to change the
Publisher= to match your own identity -->

Expand Down
35 changes: 19 additions & 16 deletions AdbExtension/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,25 @@ public static void Main(string[] args)

if (args.Length > 0 && args[0] == "-RegisterProcessAsComServer")
{
global::Shmuelie.WinRTServer.ComServer server = new();

ManualResetEvent extensionDisposedEvent = new(false);

// We are instantiating an extension instance once above, and returning it every time the callback in RegisterExtension below is called.
// This makes sure that only one instance of SampleExtension is alive, which is returned every time the host asks for the IExtension object.
// If you want to instantiate a new instance each time the host asks, create the new instance inside the delegate.
AdbExtension extensionInstance = new(extensionDisposedEvent);
server.RegisterClass<AdbExtension, IExtension>(() => extensionInstance);
server.Start();

// This will make the main thread wait until the event is signalled by the extension class.
// Since we have single instance of the extension object, we exit as soon as it is disposed.
extensionDisposedEvent.WaitOne();
server.Stop();
server.UnsafeDispose();
Log.Info("RegisterProcessAsComServer mode detected.");
try
{
global::Shmuelie.WinRTServer.ComServer server = new();
ManualResetEvent extensionDisposedEvent = new(false);
AdbExtension extensionInstance = new(extensionDisposedEvent);
server.RegisterClass<AdbExtension, IExtension>(() => extensionInstance);
Log.Info("COM server registered. Starting...");
server.Start();
Log.Info("COM server started. Waiting for disposal signal.");
extensionDisposedEvent.WaitOne();
Log.Info("Disposal signal received. Stopping server.");
server.Stop();
server.UnsafeDispose();
}
catch (Exception ex)
{
Log.Error("COM server failed", ex);
}
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion AdbExtension/app.manifest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.1" name="AdbExtension.app"/>
<assemblyIdentity version="1.0.0.2" name="AdbExtension.app"/>

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
Expand Down
2 changes: 1 addition & 1 deletion AdbExtension/build-exe.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
param(
[string]$ExtensionName = "AdbExtension",
[string]$Configuration = "Release",
[string]$Version = "1.0.0.1",
[string]$Version = "1.0.0.2",
[string[]]$Platforms = @("x64", "arm64")
)

Expand Down
2 changes: 1 addition & 1 deletion AdbExtension/setup-template.iss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; Inno Setup Script for ADB Extension for Command Palette

#define AppVersion "1.0.0.1"
#define AppVersion "1.0.0.2"

[Setup]
AppId={{d857a76b-60ad-4db5-a14c-22f1d4f7bfaa}}
Expand Down
6 changes: 3 additions & 3 deletions publishing_checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The extension was scaffolded from Microsoft's template, which leaves several pla
### ~~Step 1 — Fixes you can do RIGHT NOW~~ ✅ DONE

**`AdbExtension/Package.appxmanifest`** — all updated:
- Version: `1.0.0.1`
- Version: `1.0.0.2`
- All display names: `ADB Extension for Command Palette`
- All descriptions: `Run ADB commands for connected Android devices directly from Command Palette.`

Expand Down Expand Up @@ -42,7 +42,7 @@ The extension was scaffolded from Microsoft's template, which leaves several pla
<Identity
Name="<from Partner Center>"
Publisher="<from Partner Center>"
Version="1.0.0.1" />
Version="1.0.0.2" />
<Properties>
<PublisherDisplayName><from Partner Center></PublisherDisplayName>
...
Expand All @@ -65,7 +65,7 @@ The extension was scaffolded from Microsoft's template, which leaves several pla
cd AdbExtension\AdbExtension
dotnet build --configuration Release -p:GenerateAppxPackageOnBuild=true -p:Platform=x64 -p:AppxPackageDir="AppPackages\x64\"
dotnet build --configuration Release -p:GenerateAppxPackageOnBuild=true -p:Platform=ARM64 -p:AppxPackageDir="AppPackages\ARM64\"
makeappx bundle /v /d bin\Release\ /p AdbExtensionForCommandPalette_1.0.0.1_Bundle.msixbundle
makeappx bundle /v /d bin\Release\ /p AdbExtensionForCommandPalette_1.0.0.2_Bundle.msixbundle
```

Upload `.msixbundle` to Partner Center. In the Store description, note that reviewer needs PowerToys + Command Palette installed.
Expand Down
Loading