Skip to content

Commit

Permalink
Merge pull request #23 from ste2425/singleinstance
Browse files Browse the repository at this point in the history
prevent multiple instances
  • Loading branch information
ste2425 authored Jul 17, 2019
2 parents 82283ad + 826d58f commit 38c8d05
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
8 changes: 4 additions & 4 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
## Version 0.2.1
## Version 1.0.0
---

Release highlights:

* Added tray icon
* Made single instance

---

# Tray Icon
# Single Instance

It is now possible to minimize Dotnet Runner to the system tray. A tray icon has been created, when minimized clicking the icon will maximize the application.
Dotnet Runner will now not allow multiple instances to be run. If an instance is already running that will instead be focused.
8 changes: 8 additions & 0 deletions app/DotnetRunnerApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ module.exports = class DotnetRunnerApp {
this._mainWindow.maximize();
}

onSecondInstance() {
if (this._mainWindow.isMinimized())
this._mainWindow.restore();

this._mainWindow.show();
this._mainWindow.focus();
}

once(...args) {
this._mainWindow.once(...args);
}
Expand Down
12 changes: 12 additions & 0 deletions app/SplashScreenApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ module.exports = class SplashScreenApp {

this.onReady;

this.ready = false;

autoUpdater.on('checking-for-update', () => {
this._splashWindow
.webContents.send('checking-for-update');
Expand Down Expand Up @@ -85,6 +87,14 @@ module.exports = class SplashScreenApp {
this._splashWindow.close();
}

onSecondInstance() {
if (this._splashWindow.isMinimized())
this._splashWindow.restore();

this._splashWindow.show();
this._splashWindow.focus();
}

_executeOnReady() {
const settings = {
upgradePerformed: upgradeState.isUpgradeActive()
Expand All @@ -93,6 +103,8 @@ module.exports = class SplashScreenApp {
if (settings.upgradePerformed)
upgradeState.markUpgradeFinished();

this.ready = true;

this.onReady(settings);
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dotnet-runner",
"version": "0.2.1",
"version": "1.0.0",
"description": "Electron application to launch dotnet applications",
"main": "startup.js",
"scripts": {
Expand Down
16 changes: 16 additions & 0 deletions startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ splashApp.onReady = function(settings) {

dotnetApp.run({ displayReleaseNotes: preferences.autoOpenReleasenotes && settings.upgradePerformed })
.once('ready-to-show', () => {

splashApp.close();
dotnetApp.show();

Expand All @@ -33,6 +34,21 @@ splashApp.onReady = function(settings) {
});
}
app.on('ready', () => {
const shouldQuit = !app.requestSingleInstanceLock();

if (shouldQuit) {
app.quit();
return;
} else {
app.on('second-instance', () => {
if (splashApp.ready) {
dotnetApp.onSecondInstance();
} else {
splashApp.onSecondInstance();
}
});
}

splashApp.run();
});

Expand Down

0 comments on commit 38c8d05

Please sign in to comment.