-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ The app is now singleton, close #6
- Loading branch information
1 parent
7bb5752
commit 54446e6
Showing
7 changed files
with
164 additions
and
112 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
|
||
namespace RudeFox.ApplicationManagement | ||
{ | ||
public class EntryPoint | ||
{ | ||
// Note: | ||
// Rude Fox is a singleton application, meaning only one instance should be running at a time. | ||
// The implementation is based on the Microsoft's WPF samples | ||
// Link: https://github.com/Microsoft/WPF-Samples/tree/master/Application%20Management/SingleInstanceDetection | ||
|
||
[STAThread] | ||
public static void Main(string[] args) | ||
{ | ||
var manager = new SingletonManager(); | ||
manager.Run(args); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
RudeFox.FrontEnd/ApplicationManagement/SingletonManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualBasic.ApplicationServices; | ||
using RudeFox.Helpers; | ||
using RudeFox.Views; | ||
using RudeFox.Services; | ||
using NLog.Targets; | ||
|
||
namespace RudeFox.ApplicationManagement | ||
{ | ||
public class SingletonManager : WindowsFormsApplicationBase | ||
{ | ||
public SingletonManager() | ||
{ | ||
IsSingleInstance = true; | ||
} | ||
|
||
protected override bool OnStartup(StartupEventArgs e) | ||
{ | ||
// first time app is launched | ||
App.Instance.RegisterExceptionHandlingEvents(); | ||
InitializeComponents(); | ||
App.Instance.Run(); | ||
return false; | ||
} | ||
|
||
protected override async void OnStartupNextInstance(StartupNextInstanceEventArgs eventArgs) | ||
{ | ||
// subsequent launches | ||
Task deleteTask = App.Instance.ProcessCommandLineArgs(eventArgs.CommandLine?.ToList()); | ||
|
||
App.Instance.Activate(); | ||
|
||
if (deleteTask != null) | ||
await deleteTask; | ||
} | ||
|
||
private void InitializeComponents() | ||
{ | ||
// register sentry as NLog target | ||
Target.Register<Nlog.SentryTarget>("Sentry"); | ||
|
||
#if !DEBUG | ||
// check for updates | ||
UpdateManager.Initialize(Keys.DROPBOX_API_KEY); | ||
Task.Run(() => UpdateAfter(5)); | ||
#endif | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters