Skip to content

Commit

Permalink
optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
RoderickQiu committed Feb 19, 2019
1 parent a014570 commit 982b6ec
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 61 deletions.
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@ As a timer app, wnr is simple but useful.

## To-do List

- Chinese support

- natural notification

- history

- ......
Please go and see [Githhub Project](https://github.com/RoderickQiu/wnr/projects/1).

## Contact

Expand Down
6 changes: 6 additions & 0 deletions about.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
<p class="extreme-small"> some suggestion, just tell me!</p>
</div>
</div>
<script>
var ipc = require('electron').ipcRenderer;
const Store = require('electron-store');
const store = new Store();
</script>
<script src="renderer.js"></script>
</body>

</html>
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
</div>
</div>
<script src="updater.js"></script>
<script src="renderer.js"></script>
<script>
isTimerWindow(false);
$("#work-time").val(store.get("worktime"));
$("#rest-time").val(store.get("resttime"));
$("#loop").val(store.get("looptime"));
Expand Down
34 changes: 31 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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.
let win, settingsWin = null, aboutWin = null
let tray = null
let tray = null, contextMenu = null
app.commandLine.appendSwitch('autoplay-policy', 'no-user-gesture-required');// 允许自动播放音频

function createWindow() {
Expand Down Expand Up @@ -67,11 +67,19 @@ app.on('ready', () => {

if (process.platform == "win32") tray = new Tray(path.join(__dirname, '\\res\\icons\\iconWin.ico'));
else if (process.platform != "darwin") tray = new Tray(path.join(__dirname, '\\res\\icons\\wnrIcon.png'));
const contextMenu = Menu.buildFromTemplate([
contextMenu = Menu.buildFromTemplate([
{
label: 'wnr v' + require("./package.json").version
}, {
type: 'separator'
}, {
label: 'Start / Stop',
enabled: false,
click: function () {
win.webContents.send('startorstop')
}
}, {
type: 'separator'
}, {
label: 'Website',
click: function () {
Expand Down Expand Up @@ -165,6 +173,8 @@ ipcMain.on('warninggiver-workend', function () {
type: "info",
message: "Your work time is now ended. Enjoy your rest time!",
silent: true
}, function (response) {
win.webContents.send('warning-closed');
});
}, 100)
}
Expand All @@ -180,8 +190,9 @@ ipcMain.on('warninggiver-restend', function () {
title: "Your rest time is now ended!",
type: "info",
message: "Your rest time is now ended. Start working!"
}, function () {
}, function (response) {
if (!win.isVisible()) win.show();
win.webContents.send('warning-closed');
});
}, 180)
}
Expand Down Expand Up @@ -215,6 +226,7 @@ ipcMain.on('updateavailable', function () {
if (checkboxChecked) {
shell.openExternal("https://github.com/RoderickQiu/wnr/releases/latest");
}

})
})

Expand Down Expand Up @@ -274,6 +286,22 @@ ipcMain.on("logger", function (event, message) {
console.log(message)
})

ipcMain.on("timer-win", function (event, message) {
if (message) {
if (tray != null) {
contextMenu.items[2].enabled = true;
}
globalShortcut.register('CommandOrControl+Shift+Alt+S', () => {
win.webContents.send('startorstop');
})
} else {
if (tray != null) {
contextMenu.items[2].enabled = false;
}
globalShortcut.unregister('CommandOrControl+Shift+Alt+S');
}
})

/* 参考:
- https://blog.avocode.com/4-must-know-tips-for-building-cross-platform-electron-apps-f3ae9c2bffff [need proxy]
- https://electronjs.org/docs
Expand Down
56 changes: 28 additions & 28 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.2.0",
"update-use-version": "11877",
"version": "1.1.9",
"update-use-version": "11977",
"description": "It's a timer app with strong expansibility for computers. The name is a abbr of \"Work & Rest\".",
"main": "main.js",
"scripts": {
Expand All @@ -27,7 +27,7 @@
"request": "^2.88.0"
},
"devDependencies": {
"electron": "^4.0.4",
"electron": "^4.0.5",
"electron-builder": "^20.38.5"
},
"build": {
Expand All @@ -50,4 +50,4 @@
"icon": "res/icons/wnrIcon.png"
}
}
}
}
5 changes: 5 additions & 0 deletions renderer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function isTimerWindow(isTimer) {
if (isTimer) {
ipc.send('timer-win', true);
} else ipc.send('timer-win', false);
}
22 changes: 19 additions & 3 deletions settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimal-ui" />
<script>if (typeof module === 'object') { window.module = module; module = undefined; }</script><!-- solve the electron-jquery conflict -->
<script>if (typeof module === 'object') { window.module = module; module = undefined; }</script>
<!-- solve the electron-jquery conflict -->
<script src="res/lib/jquery-3.3.1.min.js"></script>
<script src="res/lib/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="res/lib/bootstrap.min.css" />
Expand Down Expand Up @@ -82,12 +83,20 @@
computer.
</span>
</div>
<div class="align-content-center form-text">
<label>Auto check for update: </label>
<input id="autocheck-set" type="checkbox" onchange="autocheckset()" />
<br /><span class="text-muted small">
If it is enabled, wnr will automatically check for update (every day).
</span>
</div>
<br />
<p class="lead"><i class="fa fa-ellipsis-h fa-fw" aria-hidden="true"></i>Other Things</p>
<hr />
<div class="text-muted small">
<li>
<a href="javascript:updatechecker(2)" class="rest"><span id="manually">Manually check for update</span></a>&nbsp;<b>(Now
<a href="javascript:updatechecker(2)" class="rest"><span id="manually">Manually check for
update</span></a>&nbsp;<b>(Now
<script>document.write("v" + require("./package.json").version)</script>)</b>
</li>
<li id="hotkey-tip">
Expand Down Expand Up @@ -179,15 +188,22 @@
}
}
if (store.get("fullscreen") == true) document.getElementById("fullscreen-set").checked = true;
else document.getElementById("fullscreen-set").checked = false;
else document.getElementById("fullscrseen-set").checked = false;
function fullscreenset() {
if (document.getElementById("fullscreen-set").checked == true) store.set("fullscreen", true);
else store.set("fullscreen", false);
}
if (store.get("autocheck") != false) document.getElementById("autocheck-set").checked = true;
else document.getElementById("autocheck-set").checked = false;
function autocheckset() {
if (document.getElementById("autocheck-set").checked == true) store.set("autocheck", true);
else store.set("autocheck", false);
}
function relauncher() {
ipc.send("relauncher");
}
</script>
<script src="renderer.js"></script>
</body>

</html>
Loading

0 comments on commit 982b6ec

Please sign in to comment.