diff --git a/package-lock.json b/package-lock.json index be98286..f8cd840 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "quiet", - "version": "0.11.0", + "version": "0.12.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -697,6 +697,11 @@ } } }, + "clone": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz", + "integrity": "sha1-G39Ln1kfHo+DZwQBYANFoCiHQ18=" + }, "clone-response": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.2.tgz", @@ -1102,6 +1107,15 @@ } } }, + "electron-settings": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/electron-settings/-/electron-settings-3.2.0.tgz", + "integrity": "sha512-7U+vDKd5Gch4Z9K6FjGq80eB3Anwz2GuPc2h/6hOiuvZrS1w+UNPcAA0oAU8G1s9sWAVEadCsr4ZJR6J4iTdzA==", + "requires": { + "clone": "^2.1.1", + "jsonfile": "^4.0.0" + } + }, "electron-updater": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/electron-updater/-/electron-updater-4.3.1.tgz", @@ -1941,8 +1955,7 @@ "graceful-fs": { "version": "4.1.15", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz", - "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==", - "dev": true + "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==" }, "has": { "version": "1.0.3", @@ -2331,7 +2344,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", - "dev": true, "requires": { "graceful-fs": "^4.1.6" } diff --git a/package.json b/package.json index e836d9b..f488498 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "dependencies": { "electron-is-dev": "^1.2.0", "electron-log": "^4.1.1", + "electron-settings": "^3.2.0", "electron-updater": "^4.3.1", "play-sound": "^1.1.3" } diff --git a/src/ContextMenu.js b/src/ContextMenu.js index e19b269..0033b84 100644 --- a/src/ContextMenu.js +++ b/src/ContextMenu.js @@ -1,10 +1,11 @@ const EventEmitter = require("events"); +const settings = require("electron-settings"); const { getIconsByTheme } = require("./utils"); const { installUpdateAndRestart } = require("./updater"); class ContextMenu extends EventEmitter { - constructor() { + constructor(userSettings) { super(); const { playIcon, stopIcon, updateIcon } = getIconsByTheme(); @@ -38,12 +39,15 @@ class ContextMenu extends EventEmitter { }, { type: "separator" }, { - id: "settings", - label: "Settings", + id: "sound", + label: "Play Sound", + type: "checkbox", + checked: userSettings.playSound, click: () => { - this.emit("showSettings"); + settings.set("playSound", !userSettings.playSound); } }, + { type: "separator" }, { label: "Quit", role: "quit" } ]; } diff --git a/src/main.js b/src/main.js index ff4847d..b2b166e 100644 --- a/src/main.js +++ b/src/main.js @@ -7,10 +7,11 @@ const { Tray } = require("electron"); const log = require("electron-log"); +const settings = require("electron-settings"); const { showNotification } = require("./notifications"); const { checkForUpdates } = require("./updater"); -const { setProductionAppPreferences } = require("./utils"); +const { setProductionAppPreferences, loadSettings } = require("./utils"); setProductionAppPreferences(); @@ -21,44 +22,56 @@ const ContextMenu = require("./ContextMenu"); let player, contextMenu, menuTemplate; app.on("ready", () => { - function buildMenu(tray) { - contextMenu = new ContextMenu(); + const userSettings = loadSettings(); + + function buildMenu(tray, userSettings) { + contextMenu = new ContextMenu(userSettings); menuTemplate = Menu.buildFromTemplate(contextMenu.menuItems); tray.setContextMenu(menuTemplate); } + function handlePlay() { + if (settings.get("playSound")) { + player.play(); + } + + timer.start(); + + contextMenu.toggleStartStop(menuTemplate); + + showNotification({ + title: "Time to Work 👨‍💻", + body: "Get it done. It'll feel good later." + }); + } + function handleStop({ shouldReset }) { + if (settings.get("playSound")) { + player.stop(); + } + timer.resetTimer(shouldReset); - player.stop(); contextMenu.toggleStartStop(menuTemplate); } function handleBreak() { - player.stop(); + if (settings.get("playSound")) { + player.stop(); + } + timer.resetTimer(); timer.start(); showNotification({ title: "Break Time 🧘‍♀️", - body: "10 push ups then chill." - }); - } - - function handlePlay() { - timer.start(); - player.play(); - contextMenu.toggleStartStop(menuTemplate); - - showNotification({ - title: "Time to Work 👨‍💻", - body: "Get it done. It'll feel good later." + body: "15 pushups then chill." }); } const tray = new Tray(nativeImage.createEmpty()); const timer = new Timer(tray); player = new Player(tray); - buildMenu(tray); + buildMenu(tray, userSettings); contextMenu.on("play", handlePlay); contextMenu.on("stop", handleStop); diff --git a/src/utils.js b/src/utils.js index 67df4bf..bc7c29a 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,7 +1,19 @@ const { app, dialog, nativeTheme } = require("electron"); +const settings = require("electron-settings"); const path = require("path"); const isDev = require("electron-is-dev"); +const loadSettings = () => { + // Default play sound to true + if (!settings.has("playSound")) { + settings.set("playSound", true); + } + + return { + playSound: settings.get("playSound") + }; +}; + const joinPath = (relativePath, { extraResource = false } = {}) => { // Prod: assets is in the same directory (as Resources) so remove the ../ if (extraResource && !isDev) { @@ -66,6 +78,7 @@ const TIMES = { module.exports = { TIMES, + loadSettings, joinPath, getTimerDisplay, getIconsByTheme,