diff --git a/locales/en.json b/locales/en.json index d7b2b2e..be8aa39 100644 --- a/locales/en.json +++ b/locales/en.json @@ -119,5 +119,7 @@ "snoretip": "Sometimes wnr sends notifications, which is able to be disabled in the system's settings. On Windows, we use SnoreToast to send tips. ", "default1": "Predefined", "default2": "tasks", - "edit": "Edit" + "edit": "Edit", + "isalarmtipon": "Tip for not using wnr: ", + "isalarmtipontip": "If it is enabled, wnr will send tips for you if you aren't really using wnr. " } \ No newline at end of file diff --git a/locales/zh.json b/locales/zh.json index 5b8cf2a..94e2f90 100644 --- a/locales/zh.json +++ b/locales/zh.json @@ -119,5 +119,7 @@ "snoretip": "wnr有时会发送通知(可以在系统设置中关闭或打开)。在Windows平台下使用了SnoreToast服务来发送通知。", "default1": "预设", "default2": "任务", - "edit": "编辑预设" + "edit": "编辑预设", + "isalarmtipon": "是否要让wnr发出使用提醒:", + "isalarmtipontip": "如果此项被选中,则wnr会在您一直不使用的时候提示您使用wnr,提高效率。" } \ No newline at end of file diff --git a/main.js b/main.js index 77a306e..bc7ad2d 100644 --- a/main.js +++ b/main.js @@ -57,16 +57,18 @@ function createWindow() { function alarmSet() { if (!resetAlarm) { resetAlarm = setInterval(function () { - if (win != null) win.flashFrame(true); - notifier.notify( - { - title: i18n.__('alarmtip'), - message: i18n.__('alarmtipmsg'), - sound: true, // Only Notification Center or Windows Toasters - wait: true // Wait with callback, until user action is taken against notification - } - ); - if (!win.isVisible()) win.show(); + if (store.get('alarmtip')) { + if (win != null) win.flashFrame(true); + notifier.notify( + { + title: i18n.__('alarmtip'), + message: i18n.__('alarmtipmsg'), + sound: true, // Only Notification Center or Windows Toasters + wait: true // Wait with callback, until user action is taken against notification + } + ); + if (win != null) if (!win.isVisible()) win.show(); + } }, 1200000)//不断提示使用wnr } } @@ -101,7 +103,7 @@ app.on('ready', () => { i18n.setLocale(store.get("i18n"));//国际化组件默认设置 const gotTheLock = app.requestSingleInstanceLock(); - if (!gotTheLock) { + if (!gotTheLock && win != null) { dialog.showMessageBox(win, { title: i18n.__('multiwnr'), type: "warning", @@ -115,14 +117,14 @@ app.on('ready', () => { }) }//不希望有多个wnr同时运行 - if (store.get("top") == true) win.setAlwaysOnTop(true); + if (store.get("top") == true && win != null) win.setAlwaysOnTop(true); if (!store.get('hotkey1')) store.set('hotkey1', 'W'); if (!store.get('hotkey2')) store.set('hotkey2', 'S'); globalShortcut.register('CommandOrControl+Shift+Alt+' + store.get('hotkey1'), () => { if (!isTimerWin || (isWorkMode && (!store.get('fullscreen-work')) || (!isWorkMode && (!store.get('fullscreen'))))) { - win.isVisible() ? win.hide() : win.show(); + if (win != null) win.isVisible() ? win.hide() : win.show(); if (settingsWin != null) settingsWin.isVisible() ? settingsWin.hide() : settingsWin.show(); if (aboutWin != null) aboutWin.isVisible() ? aboutWin.hide() : aboutWin.show(); if (tourWin != null) tourWin.isVisible() ? tourWin.hide() : tourWin.show(); @@ -153,7 +155,7 @@ app.on('ready', () => { label: i18n.__('startorstop'), enabled: false, click: function () { - win.webContents.send('startorstop') + if (win != null) win.webContents.send('startorstop') } }, { type: 'separator' @@ -176,7 +178,7 @@ app.on('ready', () => { type: 'separator' }, { label: i18n.__('showorhide'), click: () => { - win.isVisible() ? win.hide() : win.show(); + if (win != null) win.isVisible() ? win.hide() : win.show(); if (settingsWin != null) settingsWin.isVisible() ? settingsWin.hide() : settingsWin.show(); if (aboutWin != null) aboutWin.isVisible() ? aboutWin.hide() : aboutWin.show(); if (tourWin != null) tourWin.isVisible() ? tourWin.hide() : tourWin.show(); @@ -189,7 +191,7 @@ app.on('ready', () => { tray.setToolTip('wnr'); tray.setContextMenu(contextMenu); tray.on('click', () => { - win.isVisible() ? win.hide() : win.show(); + if (win != null) win.isVisible() ? win.hide() : win.show(); if (settingsWin != null) settingsWin.isVisible() ? settingsWin.hide() : settingsWin.show(); if (aboutWin != null) aboutWin.isVisible() ? aboutWin.hide() : aboutWin.show(); if (tourWin != null) tourWin.isVisible() ? tourWin.hide() : tourWin.show(); @@ -293,13 +295,13 @@ function isDarkMode() { if (process.platform == 'darwin') { if (systemPreferences.isDarkMode()) { store.set('isDarkMode', true); - win.backgroundColor = '#393939'; + if (win != null) win.backgroundColor = '#393939'; } systemPreferences.subscribeNotification( 'AppleInterfaceThemeChangedNotification', function theThemeHasChanged() { isDarkMode(); - win.webContents.send('darkModeChanges'); + if (win != null) win.webContents.send('darkModeChanges'); } ) } else if (process.platform == 'win32') { @@ -315,7 +317,7 @@ function isDarkMode() { if (items[i].name == 'AppsUseLightTheme') { if (items[i].value == "0x0") { store.set('isDarkMode', true); - win.backgroundColor = '#393939'; + if (win != null) win.backgroundColor = '#393939'; } } } @@ -334,8 +336,8 @@ app.on('activate', () => { }) ipcMain.on('focus-first', function () { - if (store.get("top") != true) win.setAlwaysOnTop(true);//全屏时恒定最上层 - win.setFullScreen(true); + if (store.get("top") != true && win != null) win.setAlwaysOnTop(true);//全屏时恒定最上层 + if (win != null) win.setFullScreen(true); macOSFullscreenSolution(true); isWorkMode = true; }) @@ -469,52 +471,54 @@ ipcMain.on('relauncher', function () { }) ipcMain.on('winhider', function () { - win.hide() + if (win != null) win.hide() }) ipcMain.on('minimizer', function () { - win.minimize() + if (win != null) win.minimize() }) function about() { if (app.isReady()) { - aboutWin = new BrowserWindow({ parent: win, width: 256, height: 233, resizable: false, frame: false, show: false, center: true, titleBarStyle: "hidden", webPreferences: { nodeIntegration: true } }); - aboutWin.loadFile("about.html"); - if (store.get("top") == true) aboutWin.setAlwaysOnTop(true); - aboutWin.once('ready-to-show', () => { - aboutWin.show(); - }) - aboutWin.on('closed', () => { - aboutWin = null - }) + if (win != null) { + aboutWin = new BrowserWindow({ parent: win, width: 256, height: 233, resizable: false, frame: false, show: false, center: true, titleBarStyle: "hidden", webPreferences: { nodeIntegration: true } }); + aboutWin.loadFile("about.html"); + if (store.get("top") == true) aboutWin.setAlwaysOnTop(true); + aboutWin.once('ready-to-show', () => { + aboutWin.show(); + }) + aboutWin.on('closed', () => { + aboutWin = null + }) + } } } ipcMain.on('about', about); function settings() { if (app.isReady()) { - settingsWin = new BrowserWindow({ parent: win, width: 729, height: 486, resizable: false, frame: false, show: false, center: true, webPreferences: { nodeIntegration: true }, titleBarStyle: "hidden" }); - settingsWin.loadFile("settings.html"); - if (store.get("top") == true) settingsWin.setAlwaysOnTop(true); - settingsWin.once('ready-to-show', () => { - settingsWin.show(); - }) - settingsWin.on('closed', () => { - if (win != null) { + if (win != null) { + settingsWin = new BrowserWindow({ parent: win, width: 729, height: 486, resizable: false, frame: false, show: false, center: true, webPreferences: { nodeIntegration: true }, titleBarStyle: "hidden" }); + settingsWin.loadFile("settings.html"); + if (store.get("top") == true) settingsWin.setAlwaysOnTop(true); + settingsWin.once('ready-to-show', () => { + settingsWin.show(); + }) + settingsWin.on('closed', () => { win.reload(); + settingsWin = null + }) + if (!store.get("settings-experience")) { + store.set("settings-experience", true); + notifier.notify( + { + title: i18n.__('settingstip'), + message: i18n.__('settingstipmsg'), + sound: true, // Only Notification Center or Windows Toasters + wait: true // Wait with callback, until user action is taken against notification + } + ); } - settingsWin = null - }) - if (!store.get("settings-experience")) { - store.set("settings-experience", true); - notifier.notify( - { - title: i18n.__('settingstip'), - message: i18n.__('settingstipmsg'), - sound: true, // Only Notification Center or Windows Toasters - wait: true // Wait with callback, until user action is taken against notification - } - ); } } } @@ -522,23 +526,25 @@ ipcMain.on('settings', settings); function tourguide() { if (app.isReady()) { - tourWin = new BrowserWindow({ parent: win, width: 729, height: 600, resizable: false, frame: false, show: false, center: true, titleBarStyle: "hidden", webPreferences: { nodeIntegration: true } }); - tourWin.loadFile("tourguide.html"); - if (store.get("top") == true) tourWin.setAlwaysOnTop(true); - tourWin.once('ready-to-show', () => { - tourWin.show(); - }) - tourWin.on('closed', () => { - tourWin = null - }) - notifier.notify( - { - title: i18n.__('welcomer1'), - message: i18n.__('alarmtipmsg'), - sound: true, // Only Notification Center or Windows Toasters - wait: true // Wait with callback, until user action is taken against notification - } - ); + if (win != null) { + tourWin = new BrowserWindow({ parent: win, width: 729, height: 600, resizable: false, frame: false, show: false, center: true, titleBarStyle: "hidden", webPreferences: { nodeIntegration: true } }); + tourWin.loadFile("tourguide.html"); + if (store.get("top") == true) tourWin.setAlwaysOnTop(true); + tourWin.once('ready-to-show', () => { + tourWin.show(); + }) + tourWin.on('closed', () => { + tourWin = null + }) + notifier.notify( + { + title: i18n.__('welcomer1'), + message: i18n.__('alarmtipmsg'), + sound: true, // Only Notification Center or Windows Toasters + wait: true // Wait with callback, until user action is taken against notification + } + ); + } } } ipcMain.on('tourguide', tourguide); @@ -571,7 +577,7 @@ ipcMain.on("timer-win", function (event, message) { contextMenu.items[2].enabled = true; } globalShortcut.register('CommandOrControl+Shift+Alt+' + store.get('hotkey2'), () => { - win.webContents.send('startorstop'); + if (win != null) win.webContents.send('startorstop'); }) if (resetAlarm) { clearTimeout(resetAlarm); diff --git a/package.json b/package.json index e016b34..bca1564 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wnr", - "version": "1.5.1", + "version": "1.5.2", "description": "It's a timer app with strong expansibility for computers. The name is an abbr of \"Work and Rest\".", "main": "main.js", "scripts": { diff --git a/settings.html b/settings.html index bc9fc2c..e64587e 100644 --- a/settings.html +++ b/settings.html @@ -120,6 +120,14 @@ +
+ + +
+ + +

@@ -258,6 +266,12 @@ if (document.getElementById("autocheck-set").checked == true) store.set("autocheck", true); else store.set("autocheck", false); } + if (store.get("alarmtip") != false) document.getElementById("alarmtip-set").checked = true; + else document.getElementById("alarmtip-set").checked = false; + function alarmtipset() { + if (document.getElementById("alarmtip-set").checked == true) store.set("alarmtip", true); + else store.set("alarmtip", false); + } $("#hotkey1-set").val(store.get("hotkey1").toUpperCase()); function hotkey1set() { if ($("#hotkey1-set").val() != null && $("#hotkey1-set").val()) {