Skip to content

Commit 82283ad

Browse files
authored
Merge pull request #22 from ste2425/tray
Implemented minimize to tray.
2 parents 6b47911 + 92d3607 commit 82283ad

File tree

9 files changed

+97
-12
lines changed

9 files changed

+97
-12
lines changed

ReleaseNotes.md

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

44
Release highlights:
55

6-
* Added copying of logs to the clipboard
6+
* Added tray icon
77

88
---
99

10-
# Copying logs to the clipboard
10+
# Tray Icon
1111

12-
It is now possible to copy the entire log of a terminal to the systems clipboard. This also includes the selected text.
13-
14-
To copy only the selected text, first highlight the desired text then right click on the terminal.
15-
16-
To copy the entire log, select `Copy Log` from the drop down menu of each terminal.
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.

app/Components/runner/Runner.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ module.exports = class RunnerElement extends WebComponentBase {
163163
this._runningProccess.on('data', (d) => {
164164
this._terminalProcess.write(d);
165165
});
166+
167+
this._emitEvent('starting');
166168
}
167169

168170
clean() {
@@ -196,6 +198,8 @@ module.exports = class RunnerElement extends WebComponentBase {
196198
this.setState(RunnerElement.states.stopping);
197199

198200
this._runningProccess.kill();
201+
202+
this._emitEvent('stopped');
199203
}
200204

201205
exportLog() {
@@ -234,28 +238,49 @@ module.exports = class RunnerElement extends WebComponentBase {
234238
stateEl.textContent = 'Starting';
235239
stateEl.className = 'state badge badge-info';
236240
actionBtn.textContent = 'Stop';
241+
this._emitEvent('state-change', {
242+
state: RunnerElement.states.starting
243+
});
237244
break;
238245
case RunnerElement.states.running:
239246
stateEl.textContent = 'Running';
240247
stateEl.className = 'state badge badge-success';
241248
actionBtn.textContent = 'Stop';
242249
this._enableAction();
250+
this._emitEvent('state-change', {
251+
state: RunnerElement.states.running
252+
});
243253
break;
244254
case RunnerElement.states.stopping:
245255
stateEl.textContent = 'Stopping';
246256
stateEl.className = 'state badge badge-info';
247257
actionBtn.textContent = 'Start';
258+
this._emitEvent('state-change', {
259+
state: RunnerElement.states.stopping
260+
});
248261
break;
249262
case RunnerElement.states.stopped:
250263
stateEl.textContent = 'Stopped';
251264
stateEl.className = 'state badge badge-secondary';
252265
this._enableAction();
253266
this._enableClean();
254267
actionBtn.textContent = 'Start';
268+
this._emitEvent('state-change', {
269+
state: RunnerElement.states.stopped
270+
});
255271
break;
256272
}
257273
}
258274

275+
_emitEvent(key, data) {
276+
const e = new CustomEvent(key, {
277+
detail: data,
278+
bubbles: true
279+
});
280+
281+
this.dispatchEvent(e);
282+
}
283+
259284
static register() {
260285
customElements.define('runner-element', RunnerElement);
261286
}

app/DotnetRunnerApp.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,13 @@ module.exports = class DotnetRunnerApp {
213213
this._enableTasks();
214214
}
215215

216+
_handleMinimizeToTray() {
217+
this._mainWindow.on('minimize', (e) => {
218+
e.preventDefault();
219+
this._mainWindow.hide();
220+
});
221+
}
222+
216223
/**
217224
* @returns {Menu}
218225
*/
@@ -246,6 +253,8 @@ module.exports = class DotnetRunnerApp {
246253

247254
this._menu.setApplicationMenu(this.getMenu());
248255

256+
this._handleMinimizeToTray();
257+
249258
const eixstingApps = getApplications();
250259

251260
if (!eixstingApps || eixstingApps.length === 0) {
@@ -254,7 +263,7 @@ module.exports = class DotnetRunnerApp {
254263

255264
if (displayReleaseNotes)
256265
this._mainWindow.once('ready-to-show', () => this._displayReleaseNotes());
257-
266+
258267
return this;
259268
}
260269

@@ -267,4 +276,8 @@ module.exports = class DotnetRunnerApp {
267276
once(...args) {
268277
this._mainWindow.once(...args);
269278
}
279+
280+
on(...args) {
281+
ipcMain.on(...args);
282+
}
270283
}

app/assets/icon.ico

114 KB
Binary file not shown.

app/browserWindows/main/main.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ let apps = [];
2222

2323
document.addEventListener('DOMContentLoaded', onDomContentLoaded);
2424

25+
26+
document.addEventListener('state-change', () => {
27+
const running = apps.reduce((accu, cur) => cur.component.state !== Runner.states.stopped ? accu + 1 : accu, 0);
28+
29+
if (running === 0)
30+
ipcRenderer.send(ipcMessages.trayTooltipText, '');
31+
else
32+
ipcRenderer.send(ipcMessages.trayTooltipText, `(${running}) ${running ? 'app' : 'apps'} running`);
33+
});
34+
2535
ipcRenderer.on(ipcMessages.reloadApplications, onReloadDataIPC);
2636

2737
ipcRenderer.on(ipcMessages.displayReleaseNotes, onDisplayReleaseNotes);

app/ipcMessages.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ module.exports = Object.freeze({
66
reloadApplications: 'reload-apps',
77
displayReleaseNotes: 'display-release-notes',
88
displayPreferences: 'display-preferences',
9-
taskComplete: 'task-complete'
9+
taskComplete: 'task-complete',
10+
trayTooltipText: 'tray-tooltip-text'
1011
});

app/tray.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const { Tray, Menu } = require('electron');
2+
const path = require('path');
3+
4+
let trayInstance;
5+
6+
module.exports.create = function({
7+
onQuit,
8+
onClick
9+
}) {
10+
trayInstance = new Tray(path.join(__dirname, 'assets/icon.ico'));
11+
12+
const contextMenu = Menu.buildFromTemplate([
13+
{
14+
label: 'Quit', click: onQuit
15+
}
16+
]);
17+
18+
trayInstance.setContextMenu(contextMenu);
19+
20+
if (onClick)
21+
trayInstance.on('click', onClick);
22+
}
23+
24+
module.exports.setTooltip = function(tooltipText) {
25+
trayInstance.setToolTip(tooltipText);
26+
}

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.0",
3+
"version": "0.2.1",
44
"description": "Electron application to launch dotnet applications",
55
"main": "startup.js",
66
"scripts": {

startup.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ const SplashScreenApp = require('./app/SplashScreenApp');
55

66
const preferenceStore = require('./app/data/preferencesStore');
77

8+
const ipcMessages = require('./app/ipcMessages');
9+
10+
const tray = require('./app/tray');
11+
812
const splashApp = new SplashScreenApp();
913
const dotnetApp = new DotnetRunnerApp(BrowserWindow, Menu);
1014

@@ -15,9 +19,19 @@ splashApp.onReady = function(settings) {
1519
.once('ready-to-show', () => {
1620
splashApp.close();
1721
dotnetApp.show();
22+
23+
tray.create({
24+
onQuit() {
25+
app.quit();
26+
},
27+
onClick() {
28+
dotnetApp.show()
29+
}
30+
});
31+
32+
dotnetApp.on(ipcMessages.trayTooltipText, (e, t) => tray.setTooltip(t));
1833
});
1934
}
20-
2135
app.on('ready', () => {
2236
splashApp.run();
2337
});

0 commit comments

Comments
 (0)