Skip to content

Commit

Permalink
bugs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
RoderickQiu committed Jan 26, 2019
1 parent 36672a2 commit a6680ef
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 77 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<body >
<!-- prevent people from pasting abnormal contentonpaste="return false" -->
<body onpaste="return false">
<!-- prevent people from pasting abnormal content -->
<script>
function about() {
ipc.send("about");
Expand Down
80 changes: 45 additions & 35 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { app, BrowserWindow, ipcMain, Tray, Menu, globalShortcut, dialog, shell } = require('electron')
const Store = require('electron-store');
const store = new Store();
const path = require("path");

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
Expand All @@ -21,23 +22,23 @@ function createWindow() {
title: "wnr",
icon: "./res/icons/wnrIcon.png",
backgroundColor: "#fefefe"
})// 为跨平台优化
});// 为跨平台优化

// 然后加载应用的 index.html。
win.loadFile('index.html')
win.loadFile('index.html');

//在加载页面时,渲染进程第一次完成绘制时,会发出 ready-to-show 事件。在此事件后显示窗口将没有视觉闪烁
win.once('ready-to-show', () => {
win.show()
//win.webContents.openDevTools()
})
});

// 当 window 被关闭,这个事件会被触发。
win.on('closed', () => {
// 取消引用 window 对象,如果你的应用支持多窗口的话,
// 通常会把多个 window 对象存放在一个数组里面,
// 与此同时,你应该删除相应的元素。
win = null
win = null;
if (process.platform !== 'darwin') {
app.quit()
}
Expand All @@ -54,17 +55,18 @@ app.on('will-quit', () => {
// 创建浏览器窗口时,调用这个函数。
// 部分 API 在 ready 事件触发后才能使用。
app.on('ready', () => {
createWindow()
createWindow();

if (store.get("top") == true || store.get("top") == undefined) win.setAlwaysOnTop(true)
if (store.get("top") == true || store.get("top") == undefined) win.setAlwaysOnTop(true);

globalShortcut.register('CommandOrControl+Shift+Alt+W', () => {
win.isVisible() ? win.hide() : win.show();
if (settingsWin != null) settingsWin.isVisible() ? settingsWin.hide() : settingsWin.show();
if (aboutWin != null) aboutWin.isVisible() ? aboutWin.hide() : aboutWin.show();
})

tray = new Tray('./res/icons/iconWin.ico')
if (process.platform == "win32") tray = new Tray(path.join(__dirname, '\\res\\icons\\iconWin.ico'));
else tray = new Tray(path.join(__dirname, '\\res\\icons\\wnrIcon.png'));
const contextMenu = Menu.buildFromTemplate([
{
label: 'Show/Hide', click: () => {
Expand All @@ -74,14 +76,14 @@ app.on('ready', () => {
}
},
{ label: 'Exit', click: () => { app.quit() } }
])
tray.setToolTip('wnr')
tray.setContextMenu(contextMenu)
]);
tray.setToolTip('wnr');
tray.setContextMenu(contextMenu);
tray.on('click', () => {
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 (process.platform === 'darwin') {
var template = [{
Expand Down Expand Up @@ -124,7 +126,7 @@ app.on('ready', () => {
}]
}];
var osxMenu = menu.buildFromTemplate(template);
menu.setApplicationMenu(osxMenu);
menu.setApplicationMenu(osxMenu)
}// 应付macOS的顶栏空缺
})

Expand All @@ -140,41 +142,49 @@ ipcMain.on('warninggiver-workend', function () {
if (win != null) {
win.once('focus', () => win.flashFrame(false));
win.flashFrame(true);
dialog.showMessageBox(win, {
title: "Your work time is now ended!",
type: "info",
message: "Your work time is now ended. Enjoy your rest time!"
}, function () {
if (!win.isVisible()) win.show()
})
if (store.get("fullscreen") == true) win.setFullScreen(true);
setTimeout(function () {
dialog.showMessageBox(win, {
title: "Your work time is now ended!",
type: "info",
message: "Your work time is now ended. Enjoy your rest time!",
silent: true
});
}, 100)
}
})

ipcMain.on('warninggiver-restend', function () {
if (win != null) {
win.once('focus', () => win.flashFrame(false));
win.flashFrame(true);
dialog.showMessageBox(win, {
title: "Your rest time is now ended!",
type: "info",
message: "Your rest time is now ended. Start working!"
}, function () {
if (!win.isVisible()) win.show()
})
if (win.isFullScreen()) win.setFullScreen(false);
setTimeout(function () {
dialog.showMessageBox(win, {
title: "Your rest time is now ended!",
type: "info",
message: "Your rest time is now ended. Start working!"
}, function () {
if (!win.isVisible()) win.show();
});
}, 180)
}
})

ipcMain.on('warninggiver-allend', function () {
if (win != null) {
win.once('focus', () => win.flashFrame(false));
win.flashFrame(true);
dialog.showMessageBox(win, {
title: "Your schedule is now finished!",
type: "info",
message: "Your schedule is now finished. You can now set another one."
}, function () {
if (!win.isVisible()) win.show()
})
if (win.isFullScreen()) win.setFullScreen(false);
setTimeout(function () {
dialog.showMessageBox(win, {
title: "Your schedule is now finished!",
type: "info",
message: "Your schedule is now finished. You can now set another one."
}, function () {
if (!win.isVisible()) win.show()
});
}, 100)
}
})

Expand Down Expand Up @@ -214,7 +224,7 @@ ipcMain.on('about', function () {
aboutWin.loadFile("about.html");
if (store.get("top") == true || store.get("top") == undefined) aboutWin.setAlwaysOnTop(true);
aboutWin.once('ready-to-show', () => {
aboutWin.show()
aboutWin.show();
})
aboutWin.on('closed', () => {
aboutWin = null
Expand All @@ -237,7 +247,7 @@ ipcMain.on('settings', function () {
})

ipcMain.on("progress-bar-set", function (event, message) {
win.setProgressBar(1 - message);
win.setProgressBar(1 - message)
})

/* 参考:
Expand Down
53 changes: 34 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "wnr",
"version": "1.1.4",
"update-use-version": "11477",
"version": "1.1.6",
"update-use-version": "11677",
"description": "The name is a abbr of \"Work & Rest\". It's a timer app with strong expansibility for computers.",
"main": "main.js",
"scripts": {
Expand All @@ -21,10 +21,10 @@
"copyright": "© Roderick Qiu",
"productName": "wnr",
"dependencies": {
"auto-launch": "^5.0.5",
"cheerio": "^1.0.0-rc.2",
"electron-store": "^2.0.0",
"request": "^2.88.0",
"start-on-windows-boot": "^1.0.0"
"request": "^2.88.0"
},
"devDependencies": {
"electron": "^4.0.2",
Expand Down
44 changes: 34 additions & 10 deletions settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,16 @@
</div>
<div class="align-content-center form-text">
<label>Start up with system: </label>
<input id="autostart-set" type="checkbox" onchange="autostartset()" checked />
<input id="autostart-set" type="checkbox" onchange="autostartset()" />
<br /><span class="text-muted small">
If it is enabled, every time your system starts, wnr starts. <b>(Only for Windows)</b>
If it is enabled, every time your system starts, wnr starts.
</span>
</div>
<div class="align-content-center form-text">
<label>Fullscreen rest time: </label>
<input id="fullscreen-set" type="checkbox" onchange="fullscreenset()" />
<br /><span class="text-muted small">
If it is enabled, when it's rest time, wnr will enter full-screen mode to prevent you from using computer.
</span>
</div>
<br />
Expand Down Expand Up @@ -145,24 +152,41 @@
$("#restarttip").html("(<a class='rest' href='javascript:relauncher()'>Restart Now</a>)");
}
if (store.get("autostart") != undefined) {
if (store.get("autostart")) $("#autostart-set").attr("checked");
if (store.get("autostart") == true) $("#autostart-set").attr("checked");
else $("#autostart-set").removeAttr("checked");
}
function autostartset() {
var startOnBoot = require('start-on-windows-boot');
var AutoLaunch = require('auto-launch');
var wnrLauncher = new AutoLaunch({ name: 'wnr' });
if (document.getElementById("autostart-set").checked) {
store.set("autostart", true);
if (process.platform == "win32") {
startOnBoot.enableAutoStart('wnr', __dirname + "\\wnr.exe");
}
wnrLauncher.isEnabled()
.then(function (isEnabled) {
if (isEnabled) {
return;
}
wnrLauncher.enable();
})
}
else {
store.set("autostart", false);
if (process.platform == "win32") {
startOnBoot.disableAutoStart('wnr');
}
minecraftAutoLauncher.isEnabled()
.then(function (isEnabled) {
if (isEnabled) {
wnrLauncher.disable();
}
return;
})
}
}
if (store.get("fullscreen") != undefined) {
if (store.get("fullscreen") == true) $("#fullscreen-set").attr("checked");
else $("#fullscreen-set").removeAttr("checked");
}
function fullscreenset() {
if (document.getElementById("fullscreen-set").checked) store.set("fullscreen", true);
else store.set("fullscreen", false);
}
function relauncher() {
ipc.send("relauncher");
}
Expand Down
Loading

0 comments on commit a6680ef

Please sign in to comment.