Skip to content

Commit 38c8d05

Browse files
authored
Merge pull request #23 from ste2425/singleinstance
prevent multiple instances
2 parents 82283ad + 826d58f commit 38c8d05

File tree

5 files changed

+41
-5
lines changed

5 files changed

+41
-5
lines changed

ReleaseNotes.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
## Version 0.2.1
1+
## Version 1.0.0
22
---
33

44
Release highlights:
55

6-
* Added tray icon
6+
* Made single instance
77

88
---
99

10-
# Tray Icon
10+
# Single Instance
1111

12-
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.
12+
Dotnet Runner will now not allow multiple instances to be run. If an instance is already running that will instead be focused.

app/DotnetRunnerApp.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,14 @@ module.exports = class DotnetRunnerApp {
273273
this._mainWindow.maximize();
274274
}
275275

276+
onSecondInstance() {
277+
if (this._mainWindow.isMinimized())
278+
this._mainWindow.restore();
279+
280+
this._mainWindow.show();
281+
this._mainWindow.focus();
282+
}
283+
276284
once(...args) {
277285
this._mainWindow.once(...args);
278286
}

app/SplashScreenApp.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ module.exports = class SplashScreenApp {
1515

1616
this.onReady;
1717

18+
this.ready = false;
19+
1820
autoUpdater.on('checking-for-update', () => {
1921
this._splashWindow
2022
.webContents.send('checking-for-update');
@@ -85,6 +87,14 @@ module.exports = class SplashScreenApp {
8587
this._splashWindow.close();
8688
}
8789

90+
onSecondInstance() {
91+
if (this._splashWindow.isMinimized())
92+
this._splashWindow.restore();
93+
94+
this._splashWindow.show();
95+
this._splashWindow.focus();
96+
}
97+
8898
_executeOnReady() {
8999
const settings = {
90100
upgradePerformed: upgradeState.isUpgradeActive()
@@ -93,6 +103,8 @@ module.exports = class SplashScreenApp {
93103
if (settings.upgradePerformed)
94104
upgradeState.markUpgradeFinished();
95105

106+
this.ready = true;
107+
96108
this.onReady(settings);
97109
}
98110
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dotnet-runner",
3-
"version": "0.2.1",
3+
"version": "1.0.0",
44
"description": "Electron application to launch dotnet applications",
55
"main": "startup.js",
66
"scripts": {

startup.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ splashApp.onReady = function(settings) {
1717

1818
dotnetApp.run({ displayReleaseNotes: preferences.autoOpenReleasenotes && settings.upgradePerformed })
1919
.once('ready-to-show', () => {
20+
2021
splashApp.close();
2122
dotnetApp.show();
2223

@@ -33,6 +34,21 @@ splashApp.onReady = function(settings) {
3334
});
3435
}
3536
app.on('ready', () => {
37+
const shouldQuit = !app.requestSingleInstanceLock();
38+
39+
if (shouldQuit) {
40+
app.quit();
41+
return;
42+
} else {
43+
app.on('second-instance', () => {
44+
if (splashApp.ready) {
45+
dotnetApp.onSecondInstance();
46+
} else {
47+
splashApp.onSecondInstance();
48+
}
49+
});
50+
}
51+
3652
splashApp.run();
3753
});
3854

0 commit comments

Comments
 (0)