Skip to content

Commit

Permalink
optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
RoderickQiu committed Jul 9, 2019
1 parent 7ff4469 commit a368dc6
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 73 deletions.
4 changes: 3 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. "
}
4 changes: 3 additions & 1 deletion locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,7 @@
"snoretip": "wnr有时会发送通知(可以在系统设置中关闭或打开)。在Windows平台下使用了SnoreToast服务来发送通知。",
"default1": "预设",
"default2": "任务",
"edit": "编辑预设"
"edit": "编辑预设",
"isalarmtipon": "是否要让wnr发出使用提醒:",
"isalarmtipontip": "如果此项被选中,则wnr会在您一直不使用的时候提示您使用wnr,提高效率。"
}
146 changes: 76 additions & 70 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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",
Expand All @@ -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();
Expand Down Expand Up @@ -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'
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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') {
Expand All @@ -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';
}
}
}
Expand All @@ -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;
})
Expand Down Expand Up @@ -469,76 +471,80 @@ 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
}
);
}
}
}
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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
14 changes: 14 additions & 0 deletions settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@
<script>document.write(i18n.__('checktip'));</script>
</span>
</div>
<div class="align-content-center form-text">
<label>
<script>document.write(i18n.__('isalarmtipon'));</script></label>
<input id="alarmtip-set" type="checkbox" onchange="alarmtipset()" />
<br /><span class="text-muted small">
<script>document.write(i18n.__('isalarmtipontip'));</script>
</span>
</div>
<br />
<p class="lead"><i class="fa fa-ellipsis-h fa-fw" aria-hidden="true"></i>
<script>document.write(i18n.__('otherthings'));</script>
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit a368dc6

Please sign in to comment.