From e618c4449beac19253eb43d5937c371132c11fb9 Mon Sep 17 00:00:00 2001 From: Yash Vyas Date: Sat, 11 May 2019 17:17:12 +0530 Subject: [PATCH 1/2] Added tray, app menu and tray menu for mac and refactored redundant code to separate functions. --- package.json | 5 +- src/main.js | 14 +++- src/state/timer-state.js | 8 ++- src/windows/img/trayIcon.png | Bin 0 -> 1281 bytes src/windows/img/trayIcon@2x.png | Bin 0 -> 2660 bytes src/windows/img/trayIcon@3x.png | Bin 0 -> 4742 bytes src/windows/menu-template.js | 119 ++++++++++++++++++++++++++++++++ src/windows/timer/index.js | 88 ++++++++++++++++++----- src/windows/windows.js | 72 ++++++++++++++++--- 9 files changed, 272 insertions(+), 34 deletions(-) mode change 100644 => 100755 src/main.js create mode 100644 src/windows/img/trayIcon.png create mode 100644 src/windows/img/trayIcon@2x.png create mode 100644 src/windows/img/trayIcon@3x.png create mode 100644 src/windows/menu-template.js mode change 100644 => 100755 src/windows/timer/index.js mode change 100644 => 100755 src/windows/windows.js diff --git a/package.json b/package.json index 3a53e76b..9b8f4883 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,8 @@ { "name": "mob-timer", "version": "1.0.0", - "description": "", + "productName": "Mob Timer", + "description": "A timer for mob programming.", "main": "src/main.js", "scripts": { "start": "electron .", @@ -18,7 +19,7 @@ "type": "git", "url": "git+https://github.com/pluralsight/mob-timer.git" }, - "author": "", + "author": "Pluralsight", "license": "ISC", "bugs": { "url": "https://github.com/pluralsight/mob-timer/issues" diff --git a/src/main.js b/src/main.js old mode 100644 new mode 100755 index 773e5be2..051658d2 --- a/src/main.js +++ b/src/main.js @@ -15,6 +15,7 @@ app.on('ready', () => { if (timerState.getState().shuffleMobbersOnStartup) { timerState.shuffleMobbers() } + windows.createTrayIconAndMenu() }) function onTimerEvent(event, data) { @@ -26,15 +27,22 @@ function onTimerEvent(event, data) { ipc.on('timerWindowReady', () => timerState.initialize()) ipc.on('configWindowReady', () => timerState.publishConfig()) -ipc.on('fullscreenWindowReady', () => timerState.publishConfig()) +ipc.on('fullscreenWindowReady', () => { + timerState.stopAlerts() + timerState.publishConfig() +}) +ipc.on('reset', () => timerState.reset(true)) ipc.on('pause', () => timerState.pause()) ipc.on('unpause', () => timerState.start()) ipc.on('skip', () => timerState.rotate()) -ipc.on('startTurn', () => timerState.start()) +ipc.on('startTurn', () => { + windows.closeFullscreenWindow() + timerState.start() +}) ipc.on('configure', () => { - windows.showConfigWindow() windows.closeFullscreenWindow() + windows.showConfigWindow() }) ipc.on('shuffleMobbers', () => timerState.shuffleMobbers()) diff --git a/src/state/timer-state.js b/src/state/timer-state.js index 948e4454..f72adf06 100644 --- a/src/state/timer-state.js +++ b/src/state/timer-state.js @@ -52,8 +52,13 @@ class TimerState { }) } - reset() { + reset(stop = false) { + if (stop) { + this.mainTimer.pause() + this.callback('turnEnded') + } this.mainTimer.reset(this.secondsPerTurn) + this.stopAlerts() this.dispatchTimerChange(this.secondsPerTurn) } @@ -65,6 +70,7 @@ class TimerState { stopAlerts() { this.alertsTimer.pause() + this.alertsTimer.reset(0) this.callback('stopAlerts') } diff --git a/src/windows/img/trayIcon.png b/src/windows/img/trayIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..336983195b3212e00f8fe129feb766489b161008 GIT binary patch literal 1281 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+1|-AI^@Rf|mUKs7M+SzC{oH>NS%G|oWRD45bDP46hOx7_4S6Fo+k-*%fF5l;AAzh%9Dc;1&j9Muu5) zBp4VNBQrxHN+NuHtdjF{^%7I^lT!66atnZ}85nFTtboki)RIJnirk#MVyg;UC9n!B zAR8pCucQE0Qj%?}6yY17;GAESs$i;TqGzCF$EBd4U{jQmW)z9|8>y;bpKhp88yV>WRp=I1=9MH?=;jqGLkxkLMfuL^+7WFhI$72aI=A0Z9t+{{zaLoK$}74 z+Zoz`RicPN?Xl4ZS&rlwh)=F>hYvzb^arq;>r&9Eby+#YiBK2-1+mIy- z*!On4NW6VC;P*sdv&>0n)pkG5zn6EZiSNw5?Vr=?K39LfXOoo1yULljDPmgcwbx%& zw})wm#a=J__om?OL(?+x^Ecb4uZ-C5qny8}$|cE?Icq$4y9$Ny*VsU`wck-KX^`JQi=h&Tu{2zEd`D9kb4B zllSw(&xH8?y8W`5hoRw8-u9cvzqvT*Gx0F7s-2PQ-lAxF`M|R*tGRW|`}>w%8mw6w}yMJ+>o!?eF`}j+{@4oBG;a8}#Ipq)? z9i1{u&DY=mG7H12UbeUI-c4HfuwlUw#>|t#R!GJOYCp*y>*o={3IMZ1P%9o z;b47sa;D>kh}K?<{=U9dQg7eBov8BB#{a7Jb>4yCZ37a=> z<~p!R=hnS@VGlNiCTemfa|*ZXNyc6FJFua%RkEk(VZiAVo(Dev+>@mC*zS-*h_OkV* zJwN9qHub<-Pdh%9QC*+B198 z&F#bD*626*Tv0mlPDVziU}ucn77m7gg7-iFc>ca<_qK0chj*vTem|FSMd?Gx)H0dn z3JF4;Z!0e>UN-ewhg3wBtJJLM`}-{3Eq)z%xrp=npBvFCXSok7PG@0Y2+}c(Y{{?XDGUZ3K~yWKbLh* G2~7ZfoC#F` literal 0 HcmV?d00001 diff --git a/src/windows/img/trayIcon@2x.png b/src/windows/img/trayIcon@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..de53f9d03f85b004940652aebafa4800e65cb720 GIT binary patch literal 2660 zcmY*bc|6qJ9{$OaZ7$i@jFBv5##&*lktJi_MRvy0$c&7#4zkT_Nkj+J^Eu~y&vTyd^L)SOuM=l%r~_i;V*~&Iq^GN8O4%=*PI@}Z zItyfEP&OJ54TJ^&R399e1OVK>2ms+x0I*Mi!dCzwKpFs69RWazlEdwn z-Dm=*Trl|Q+Moe|iT!j^0Z+4e0D#H{X>N_NMi?l$pnRcDt|(_WDAw1H!Uh01R*4e& zx?!BaSYMwzXeF!)3Sz@FJ=7>8rJJm_r8Pb#5q`m=v6?cJB~tqJtt_Iy!<*qf;z^GbeGm4oFpP!; zO_q$4KZm_hI9?=HMs!WKsUx@A)WvTK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MNuI=b5rs_;D(`RmaDMx{U8j zR94YTP_V<329bi}c338mfe$p%+ohCKr%4tMCy07|*zEWx`;oPi zWQg%s-(SBs>Un%yy-`#CWFcA4H-(AqMo~b-v7)&$z}Vdm%?IsZSm8m27;o=}*cnGCJgOLnl!_|C zG2kaIAY`+^8o8qQ-}7bt*Ha3@gHIi#!G#2W$pl)YLpG_6-pJiDh^B5Xb-Zgl*{B!Y zV@YL&{fJd0Z>*4VxGfCcO-?2X-!%)TZ1_GX9Vtzq)-KtO9H&4VoP+P|+dHar(tUCa zCq8eM6iQQ#v&wq=PzYk!p`q2o$s6XhVQsj5(M<+(#ymFi*p4D2X7afc$*2Bm_BgiL zr${rF`+0RQ?ZtWhmBY!$oJ^Tt)4c2ZJJra#c}D+Db9cU@;lCtPT^DtE*gw}hL51a} zrvvui0lk&PT{$=LU80n~Jm4x647qfr>E7G*BLDDWu~**9j#9krbB3VnVU0hlVYbko zSku8sh{DCv$6LZxG5Y_Qk2E^_rrXbEydf` znkiEAU_l=?s3cv6BJQ+6wm{l!@i?fS;GQ>mY~+#ybMk2btH1WA3g{eo=Ycw zfh5@A6H({Z#?xClsIXHe@6>28Px;H{JCV$g1VyHTu^-x~WCP^H+)ztc+rdwon6U!N zh{H_0#iLJzZ+`72K!2?3!B9Lm-%@rZ@cFCj)MFNFlCzo70`$i*mtZWHc z46o+u!#dnT%|Pd32ds&G)^B5`b-tJ}u<{ygH|)mrt0@%rN`lmoV<|E { +function drawInitialState() { + drawOverlays(true) + containerEl.classList.remove('isPaused') + containerEl.classList.add('isTurnEnded') +} + +function drawMobbers(data) { if (!data.current) { data.current = { name: 'Add a mobber' } } @@ -67,29 +73,61 @@ ipc.on('rotated', (event, data) => { } nextPicEl.src = data.next.image || '../img/sad-cyclops.png' nextEl.innerHTML = data.next.name +} + +function drawOverlays(isPaused) { + if (!paused && isPaused) { + containerEl.classList.remove('isTurnEnded') + containerEl.classList.add('isPaused') + } + paused = isPaused + if (!isPaused) { + containerEl.classList.remove('isTurnEnded') + containerEl.classList.remove('isPaused') + toggleBtn.classList.remove('play') + toggleBtn.classList.add('pause') + } else { + toggleBtn.classList.add('play') + toggleBtn.classList.remove('pause') + } +} + +ipc.on('rotated', (event, data) => { + drawMobbers(data) + drawOverlays(true) +}) + +ipc.on('skip', () => { + skip() +}) + +ipc.on('reset', () => { + drawOverlays(true) + containerEl.classList.remove('isPaused') + containerEl.classList.add('isTurnEnded') + reset() +}) + +ipc.on('pause', () => { + drawOverlays(true) + pause() +}) + +ipc.on('start', () => { + drawOverlays(false) + start() }) ipc.on('paused', () => { - paused = true - containerEl.classList.add('isPaused') - toggleBtn.classList.add('play') - toggleBtn.classList.remove('pause') + drawOverlays(true) }) ipc.on('started', () => { - paused = false - containerEl.classList.remove('isPaused') - containerEl.classList.remove('isTurnEnded') - toggleBtn.classList.remove('play') - toggleBtn.classList.add('pause') + drawOverlays(false) }) ipc.on('turnEnded', () => { - paused = true - containerEl.classList.remove('isPaused') - containerEl.classList.add('isTurnEnded') - toggleBtn.classList.add('play') - toggleBtn.classList.remove('pause') + drawInitialState() }) ipc.on('configUpdated', (event, data) => { @@ -109,9 +147,25 @@ ipc.on('stopAlerts', () => { }) toggleBtn.addEventListener('click', () => { - paused ? ipc.send('unpause') : ipc.send('pause') + paused ? start() : pause() }) -nextBtn.addEventListener('click', () => ipc.send('skip')) +nextBtn.addEventListener('click', () => skip()) configureBtn.addEventListener('click', () => ipc.send('configure')) +function skip() { + ipc.send('skip') +} + +function reset() { + ipc.send('reset') +} + +function pause() { + ipc.send('pause') +} + +function start() { + ipc.send('unpause') +} + ipc.send('timerWindowReady') diff --git a/src/windows/windows.js b/src/windows/windows.js old mode 100644 new mode 100755 index acca3a71..f53c8a0c --- a/src/windows/windows.js +++ b/src/windows/windows.js @@ -1,9 +1,12 @@ const electron = require('electron') -const { app } = electron +const { app, BrowserWindow, Menu, Tray } = electron const windowSnapper = require('./window-snapper') const path = require('path') +const menuTemplate = require('./menu-template') +const isMac = process.platform === 'darwin' +const trayMenu = Menu.buildFromTemplate(menuTemplate.trayMenuTemplate) -let timerWindow, configWindow, fullscreenWindow +let tray, timerWindow, configWindow, fullscreenWindow let snapThreshold, secondsUntilFullscreen, timerAlwaysOnTop exports.createTimerWindow = () => { @@ -12,11 +15,13 @@ exports.createTimerWindow = () => { } let { width, height } = electron.screen.getPrimaryDisplay().workAreaSize - timerWindow = new electron.BrowserWindow({ - x: width - 220, - y: height - 90, - width: 220, - height: 90, + const timerWinWidth = 220 + const timerWinHeight = 90 + timerWindow = new BrowserWindow({ + x: width - timerWinWidth, + y: height - timerWinHeight, + width: timerWinWidth, + height: timerWinHeight, resizable: false, alwaysOnTop: timerAlwaysOnTop, frame: false, @@ -25,6 +30,7 @@ exports.createTimerWindow = () => { timerWindow.loadURL(`file://${__dirname}/timer/index.html`) timerWindow.on('closed', () => (timerWindow = null)) + createApplicationMenu() timerWindow.on('move', () => { if (snapThreshold <= 0) { @@ -46,6 +52,7 @@ exports.createTimerWindow = () => { timerWindow.setPosition(snapTo.x, snapTo.y) } }) + exports.timerWindow = timerWindow } exports.showConfigWindow = () => { @@ -61,7 +68,7 @@ exports.createConfigWindow = () => { return } - configWindow = new electron.BrowserWindow({ + configWindow = new BrowserWindow({ width: 420, height: 500, autoHideMenuBar: true @@ -101,8 +108,13 @@ exports.dispatchEvent = (event, data) => { if (event === 'alert' && data === secondsUntilFullscreen) { exports.createFullscreenWindow() } - if (event === 'stopAlerts') { - exports.closeFullscreenWindow() + if (isMac) { + if (event === 'started' || event === 'paused' || event === 'turnEnded') { + const menu = Menu.getApplicationMenu() + const timerMenu = isMac ? menu.items[1].submenu : menu.items[0].submenu + configureTimerMenu(event, timerMenu) + configureTimerMenu(event, trayMenu.items[1].submenu) + } } if (timerWindow) { @@ -129,9 +141,39 @@ exports.setConfigState = data => { } } +exports.createTrayIconAndMenu = () => { + if (isMac) { + if (!tray) { + tray = new Tray(path.join(__dirname, '/../windows/img/trayIcon.png')) + tray.setToolTip('Mob Timer') + } + tray.setContextMenu(trayMenu) + } +} + +function configureTimerMenu(event, timerMenu) { + switch (event) { + case 'started': + timerMenu.items[0].visible = false + timerMenu.items[1].visible = true + timerMenu.items[2].visible = true + break + case 'paused': + timerMenu.items[0].visible = true + timerMenu.items[1].visible = false + timerMenu.items[2].visible = true + break + case 'turnEnded': + timerMenu.items[0].visible = true + timerMenu.items[1].visible = false + timerMenu.items[2].visible = false + break + } +} + function createAlwaysOnTopFullscreenInterruptingWindow(options) { return whileAppDockHidden(() => { - const window = new electron.BrowserWindow(options) + const window = new BrowserWindow(options) window.setAlwaysOnTop(true, 'screen-saver') return window }) @@ -149,3 +191,11 @@ function whileAppDockHidden(work) { } return result } + +function createApplicationMenu() { + if (isMac) { + const template = menuTemplate.appMenuTemplate + const menu = Menu.buildFromTemplate(template) + Menu.setApplicationMenu(menu) + } +} From 52c5f7282c22cdc5a4b2211b3aaeae95356eec8b Mon Sep 17 00:00:00 2001 From: Yash Vyas Date: Sat, 11 May 2019 17:48:57 +0530 Subject: [PATCH 2/2] Added tray, app menu and tray menu for mac and refactored redundant code to separate functions. --- src/windows/menu-template.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/windows/menu-template.js b/src/windows/menu-template.js index af5f330c..ff3ec98c 100644 --- a/src/windows/menu-template.js +++ b/src/windows/menu-template.js @@ -102,7 +102,7 @@ exports.trayMenuTemplate = [ { label: 'Preferences', accelerator: 'CommandOrControl+,', - click() { exports.showConfigWindow() } + click() { windows.showConfigWindow() } } ] },