Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbd221c4

Browse files
authored
feat: add support for URI activations for coder scheme (#72)
relates to#52Adds support for Coder Desktop to handle the `coder:/` URI scheme by registering for this scheme and forwarding activations to the single instance of Coder Desktop.Also removes the `Package.appxmanifest`. It is unused since Coder Desktop is not a packaged app.
1 parenta5ab4f5 commitbd221c4

File tree

3 files changed

+47
-59
lines changed

3 files changed

+47
-59
lines changed

‎App/App.xaml.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
usingSystem;
22
usingSystem.Diagnostics;
3+
usingSystem.IO;
34
usingSystem.Threading;
45
usingSystem.Threading.Tasks;
56
usingCoder.Desktop.App.Models;
@@ -13,6 +14,8 @@
1314
usingMicrosoft.Extensions.Hosting;
1415
usingMicrosoft.UI.Xaml;
1516
usingMicrosoft.Win32;
17+
usingMicrosoft.Windows.AppLifecycle;
18+
usingWindows.ApplicationModel.Activation;
1619

1720
namespaceCoder.Desktop.App;
1821

@@ -82,7 +85,7 @@ public async Task ExitApplication()
8285
Environment.Exit(0);
8386
}
8487

85-
protectedoverridevoidOnLaunched(LaunchActivatedEventArgsargs)
88+
protectedoverridevoidOnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgsargs)
8689
{
8790
// Start connecting to the manager in the background.
8891
varrpcController=_services.GetRequiredService<IRpcController>();
@@ -138,4 +141,24 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
138141
trayWindow.AppWindow.Hide();
139142
};
140143
}
144+
145+
publicvoidOnActivated(object?sender,AppActivationArgumentsargs)
146+
{
147+
switch(args.Kind)
148+
{
149+
caseExtendedActivationKind.Protocol:
150+
varprotoArgs=args.DataasIProtocolActivatedEventArgs;
151+
HandleURIActivation(protoArgs.Uri);
152+
break;
153+
154+
default:
155+
// TODO: log
156+
break;
157+
}
158+
}
159+
160+
publicvoidHandleURIActivation(Uriuri)
161+
{
162+
// TODO: handle
163+
}
141164
}

‎App/Package.appxmanifest

Lines changed: 0 additions & 52 deletions
This file was deleted.

‎App/Program.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
usingSystem;
2+
usingSystem.Reflection;
23
usingSystem.Runtime.InteropServices;
34
usingSystem.Threading;
45
usingMicrosoft.UI.Dispatching;
@@ -26,7 +27,23 @@ private static void Main(string[] args)
2627
try
2728
{
2829
ComWrappersSupport.InitializeComWrappers();
29-
if(!CheckSingleInstance())return;
30+
AppInstancemainInstance=GetMainInstance();
31+
if(!mainInstance.IsCurrent)
32+
{
33+
varactivationArgs=AppInstance.GetCurrent().GetActivatedEventArgs();
34+
mainInstance.RedirectActivationToAsync(activationArgs).AsTask().Wait();
35+
return;
36+
}
37+
38+
// Register for URI handling (known as "protocol activation")
39+
#ifDEBUG
40+
conststringscheme="coder-debug";
41+
#else
42+
conststringscheme="coder";
43+
#endif
44+
varthisBin=Assembly.GetExecutingAssembly().Location;
45+
ActivationRegistrationManager.RegisterForProtocolActivation(scheme,thisBin+",1","Coder Desktop","");
46+
3047
Application.Start(p=>
3148
{
3249
varcontext=newDispatcherQueueSynchronizationContext(DispatcherQueue.GetForCurrentThread());
@@ -38,6 +55,9 @@ private static void Main(string[] args)
3855
e.Handled=true;
3956
ShowExceptionAndCrash(e.Exception);
4057
};
58+
59+
// redirections via RedirectActivationToAsync above get routed to the App
60+
mainInstance.Activated+=app.OnActivated;
4161
});
4262
}
4363
catch(Exceptione)
@@ -46,20 +66,17 @@ private static void Main(string[] args)
4666
}
4767
}
4868

49-
[STAThread]
50-
privatestaticboolCheckSingleInstance()
69+
privatestaticAppInstanceGetMainInstance()
5170
{
5271
#if!DEBUG
5372
conststringappInstanceName="Coder.Desktop.App";
5473
#else
5574
conststringappInstanceName="Coder.Desktop.App.Debug";
5675
#endif
5776

58-
varinstance=AppInstance.FindOrRegisterForKey(appInstanceName);
59-
returninstance.IsCurrent;
77+
returnAppInstance.FindOrRegisterForKey(appInstanceName);
6078
}
6179

62-
[STAThread]
6380
privatestaticvoidShowExceptionAndCrash(Exceptione)
6481
{
6582
conststringtitle="Coder Desktop Fatal Error";

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp