- Notifications
You must be signed in to change notification settings - Fork3
feat: add support for URI activations for coder scheme#72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using System; | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
using Microsoft.UI.Dispatching; | ||
@@ -26,7 +27,23 @@ private static void Main(string[] args) | ||
try | ||
{ | ||
ComWrappersSupport.InitializeComWrappers(); | ||
AppInstance mainInstance = GetMainInstance(); | ||
if (!mainInstance.IsCurrent) | ||
{ | ||
var activationArgs = AppInstance.GetCurrent().GetActivatedEventArgs(); | ||
mainInstance.RedirectActivationToAsync(activationArgs).AsTask().Wait(); | ||
return; | ||
} | ||
// Register for URI handling (known as "protocol activation") | ||
#if DEBUG | ||
const string scheme = "coder-debug"; | ||
#else | ||
const string scheme = "coder"; | ||
#endif | ||
var thisBin = Assembly.GetExecutingAssembly().Location; | ||
ActivationRegistrationManager.RegisterForProtocolActivation(scheme, thisBin + ",1", "Coder Desktop", ""); | ||
Comment on lines +38 to +45 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Is it typical for apps to register themselves? Or is it more common for it to be registered in the installer (not sure if this is even an option)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. The installer could do it, but I'm not sure it provides any advantage. One advantage of the App registering itself is that you don't need to install to debug, which is nice. We might want to cosiderunregistering in the uninstaller, which I can look into in another PR. | ||
Application.Start(p => | ||
{ | ||
var context = new DispatcherQueueSynchronizationContext(DispatcherQueue.GetForCurrentThread()); | ||
@@ -38,6 +55,9 @@ private static void Main(string[] args) | ||
e.Handled = true; | ||
ShowExceptionAndCrash(e.Exception); | ||
}; | ||
// redirections via RedirectActivationToAsync above get routed to the App | ||
mainInstance.Activated += app.OnActivated; | ||
}); | ||
} | ||
catch (Exception e) | ||
@@ -46,20 +66,17 @@ private static void Main(string[] args) | ||
} | ||
} | ||
private static AppInstance GetMainInstance() | ||
{ | ||
#if !DEBUG | ||
const string appInstanceName = "Coder.Desktop.App"; | ||
#else | ||
const string appInstanceName = "Coder.Desktop.App.Debug"; | ||
#endif | ||
return AppInstance.FindOrRegisterForKey(appInstanceName); | ||
} | ||
private static void ShowExceptionAndCrash(Exception e) | ||
{ | ||
const string title = "Coder Desktop Fatal Error"; | ||
Uh oh!
There was an error while loading.Please reload this page.