Skip to content

Commit

Permalink
feat(icon): add green icon on break
Browse files Browse the repository at this point in the history
  • Loading branch information
Dawid Janiga committed Apr 21, 2021
1 parent 69bd430 commit ac5c574
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 25 deletions.
18 changes: 4 additions & 14 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"test": "jest --watch",
"test:ci": "jest",
"release": "dotenv release-it -VV",
"dev": "concurrently \"BROWSER=none PORT=3007 yarn start\" \"wait-on http://localhost:3007 && electron . --inspect-brk\""
"dev": "concurrently \"BROWSER=none PORT=3007 yarn start\" \"wait-on http://localhost:3007 && electron . \""
},
"build": {
"appId": "com.dawidjaniga.pomoguru",
Expand All @@ -57,10 +57,7 @@
"mac": {
"category": "public.app-category.productivity"
},
"files": [
"build/**/*",
"node_modules/**/*"
],
"files": ["build/**/*", "node_modules/**/*"],
"directories": {
"buildResources": "build"
},
Expand All @@ -71,17 +68,10 @@
"url": "git+https://github.com/dawidjaniga/pomoguru.git"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
"extends": ["react-app", "react-app/jest"]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"production": [">0.2%", "not dead", "not op_mini all"],
"development": [
"last 1 chrome version",
"last 1 firefox version",
Expand Down
22 changes: 17 additions & 5 deletions packages/app/public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ ipcMain.on('set-timer', (event, timeLeft) => {
}
})

ipcMain.on('set-icon', (event, icon) => {
if (tray) {
const iconPath = getIconPath(icon)
console.log('Setting icon: ', iconPath)
tray.setImage(iconPath)
}
})

ipcMain.on('checkUpdateClicked', () => {
if (isDev) {
autoUpdater.checkForUpdates()
Expand Down Expand Up @@ -64,7 +72,7 @@ function createWindow () {
: `file://${path.join(__dirname, '../build/index.html')}`
)

tray = new Tray(path.join(__dirname, getAppIconPath()))
tray = new Tray(getIconPath('icon-red-small.png'))

tray.on('right-click', toggleWindow)
tray.on('double-click', toggleWindow)
Expand Down Expand Up @@ -121,17 +129,21 @@ app.on('window-all-closed', () => {
})

app.on('active', () => {
if (BrowserWin.getAllWindows().length === 0) {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})

app.whenReady().then(createWindow)

function getAppIconPath () {
function getIconPath (icon) {
let iconPath

if (isDev) {
return '../public/icon-small.png'
iconPath = '../public/' + icon
} else {
return '../build/icon-small.png'
iconPath = '../build/' + icon
}

return path.join(__dirname, iconPath)
}
Binary file added packages/app/public/icon-green-small.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/app/public/icon-red-small.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed packages/app/public/icon-small.png
Binary file not shown.
Binary file modified packages/app/public/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 12 additions & 4 deletions packages/app/src/core/mediator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,20 @@ export function useMediator () {
},
onStartClick () {
phase = Phase.focus
slack.goIntoFocus(focusTimeLeftMinutes)
ipcRenderer.send('set-icon', 'icon-red-small.png')

start()
setPhase(Phase.focus)

slack.goIntoFocus(focusTimeLeftMinutes)
notifications.notify({
body: 'All set! Focus time is on'
})
},
onPauseClick () {
phase = Phase.break
ipcRenderer.send('set-icon', 'icon-green-small.png')

pause()
setPhase(Phase.idle)

Expand All @@ -55,6 +58,8 @@ export function useMediator () {
},
onStopClick () {
phase = Phase.break
ipcRenderer.send('set-icon', 'icon-green-small.png')

stop()
setPhase(Phase.idle)

Expand All @@ -66,19 +71,22 @@ export function useMediator () {
},
onBreakPhaseEnd () {
phase = Phase.focus
setTimeLeft(focusPhaseDurationSeconds)
slack.goIntoFocus(focusTimeLeftMinutes)
setPhase(Phase.focus)
slack.goIntoFocus(focusTimeLeftMinutes)

setTimeLeft(focusPhaseDurationSeconds)
ipcRenderer.send('set-icon', 'icon-red-small.png')

notifications.notify({
body: 'All set! Focus time is on'
})
},
onFocusPhaseEnd () {
phase = Phase.break
slack.endFocus()
setPhase(Phase.break)
slack.endFocus()
setTimeLeft(breakPhaseDurationSeconds)
ipcRenderer.send('set-icon', 'icon-green-small.png')

notifications.notify({
body: 'Great job! Break time'
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/features/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function Home () {
return (
<>
<WindowTitle>
Pomoguru <img src='icon-small.png' alt='Pomoguru icon' />
Pomoguru <img src='icon-red-small.png' alt='Pomoguru icon' />
{version}
<button onClick={handleUpdateClick}>Check update</button>
</WindowTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exports[`Home View when Slack is not initialized should show "Connect to Slack"
Pomoguru
<img
alt="Pomoguru icon"
src="icon-small.png"
src="icon-red-small.png"
/>
</div>
<a
Expand Down

0 comments on commit ac5c574

Please sign in to comment.