Skip to content

Commit 36672a2

Browse files
committed
optimized
1 parent 0da7d47 commit 36672a2

File tree

7 files changed

+100
-21
lines changed

7 files changed

+100
-21
lines changed

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
<link rel="stylesheet" type="text/css" href="style.css" />
1616
</head>
1717

18-
<body onpaste="return false">
19-
<!-- prevent people from pasting abnormal content -->
18+
<body >
19+
<!-- prevent people from pasting abnormal contentonpaste="return false" -->
2020
<script>
2121
function about() {
2222
ipc.send("about");

main.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ const store = new Store();
44

55
// Keep a global reference of the window object, if you don't, the window will
66
// be closed automatically when the JavaScript object is garbage collected.
7-
let win, settingsWin, aboutWin
7+
let win, settingsWin = null, aboutWin = null
88
let tray = null
9-
109
app.commandLine.appendSwitch('autoplay-policy', 'no-user-gesture-required');// 允许自动播放音频
1110

1211
function createWindow() {
@@ -61,19 +60,27 @@ app.on('ready', () => {
6160

6261
globalShortcut.register('CommandOrControl+Shift+Alt+W', () => {
6362
win.isVisible() ? win.hide() : win.show();
64-
if (settingsWin) settingsWin.isVisible() ? settingsWin.hide() : settingsWin.show();
65-
if (aboutWin) aboutWin.isVisible() ? aboutWin.hide() : aboutWin.show();
63+
if (settingsWin != null) settingsWin.isVisible() ? settingsWin.hide() : settingsWin.show();
64+
if (aboutWin != null) aboutWin.isVisible() ? aboutWin.hide() : aboutWin.show();
6665
})
6766

6867
tray = new Tray('./res/icons/iconWin.ico')
6968
const contextMenu = Menu.buildFromTemplate([
70-
{ label: 'Show/Hide', click: () => { win.isVisible() ? win.hide() : win.show() } },
69+
{
70+
label: 'Show/Hide', click: () => {
71+
win.isVisible() ? win.hide() : win.show();
72+
if (settingsWin != null) settingsWin.isVisible() ? settingsWin.hide() : settingsWin.show();
73+
if (aboutWin != null) aboutWin.isVisible() ? aboutWin.hide() : aboutWin.show();
74+
}
75+
},
7176
{ label: 'Exit', click: () => { app.quit() } }
7277
])
7378
tray.setToolTip('wnr')
7479
tray.setContextMenu(contextMenu)
7580
tray.on('click', () => {
76-
win.isVisible() ? win.hide() : win.show()
81+
win.isVisible() ? win.hide() : win.show();
82+
if (settingsWin != null) settingsWin.isVisible() ? settingsWin.hide() : settingsWin.show();
83+
if (aboutWin != null) aboutWin.isVisible() ? aboutWin.hide() : aboutWin.show()
7784
})//托盘菜单
7885

7986
if (process.platform === 'darwin') {
@@ -209,22 +216,30 @@ ipcMain.on('about', function () {
209216
aboutWin.once('ready-to-show', () => {
210217
aboutWin.show()
211218
})
219+
aboutWin.on('closed', () => {
220+
aboutWin = null
221+
})
212222
})
213223

214224
ipcMain.on('settings', function () {
215-
settingsWin = new BrowserWindow({ parent: win, modal: true, width: 720, height: 700, resizable: false, frame: false, show: false, center: true, webPreferences: { nodeIntegration: true } });
225+
settingsWin = new BrowserWindow({ parent: win, modal: true, width: 720, height: 500, resizable: false, frame: false, show: false, center: true, webPreferences: { nodeIntegration: true } });
216226
settingsWin.loadFile("settings.html");
217227
if (store.get("top") == true || store.get("top") == undefined) settingsWin.setAlwaysOnTop(true);
218228
settingsWin.once('ready-to-show', () => {
219229
settingsWin.show();
220230
})
221231
settingsWin.on('closed', () => {
222232
if (win != null) {
223-
win.reload()
233+
win.reload();
224234
}
235+
settingsWin = null
225236
})
226237
})
227238

239+
ipcMain.on("progress-bar-set", function (event, message) {
240+
win.setProgressBar(1 - message);
241+
})
242+
228243
/* 参考:
229244
- https://blog.avocode.com/4-must-know-tips-for-building-cross-platform-electron-apps-f3ae9c2bffff [need proxy]
230245
- https://electronjs.org/docs

package-lock.json

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "wnr",
3-
"version": "1.1.3",
4-
"update-use-version": "11377",
3+
"version": "1.1.4",
4+
"update-use-version": "11477",
55
"description": "The name is a abbr of \"Work & Rest\". It's a timer app with strong expansibility for computers.",
66
"main": "main.js",
77
"scripts": {
@@ -21,9 +21,10 @@
2121
"copyright": "© Roderick Qiu",
2222
"productName": "wnr",
2323
"dependencies": {
24+
"cheerio": "^1.0.0-rc.2",
2425
"electron-store": "^2.0.0",
2526
"request": "^2.88.0",
26-
"cheerio": "^1.0.0-rc.2"
27+
"start-on-windows-boot": "^1.0.0"
2728
},
2829
"devDependencies": {
2930
"electron": "^4.0.2",

settings.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@
6868
required. <span id="restarttip"></span></b>
6969
</span>
7070
</div>
71+
<div class="align-content-center form-text">
72+
<label>Start up with system: </label>
73+
<input id="autostart-set" type="checkbox" onchange="autostartset()" checked />
74+
<br /><span class="text-muted small">
75+
If it is enabled, every time your system starts, wnr starts. <b>(Only for Windows)</b>
76+
</span>
77+
</div>
7178
<br />
7279
<p class="lead"><i class="fa fa-ellipsis-h fa-fw" aria-hidden="true"></i>Other Things</p>
7380
<hr />
@@ -137,6 +144,25 @@
137144
else store.set("top", false);
138145
$("#restarttip").html("(<a class='rest' href='javascript:relauncher()'>Restart Now</a>)");
139146
}
147+
if (store.get("autostart") != undefined) {
148+
if (store.get("autostart")) $("#autostart-set").attr("checked");
149+
else $("#autostart-set").removeAttr("checked");
150+
}
151+
function autostartset() {
152+
var startOnBoot = require('start-on-windows-boot');
153+
if (document.getElementById("autostart-set").checked) {
154+
store.set("autostart", true);
155+
if (process.platform == "win32") {
156+
startOnBoot.enableAutoStart('wnr', __dirname + "\\wnr.exe");
157+
}
158+
}
159+
else {
160+
store.set("autostart", false);
161+
if (process.platform == "win32") {
162+
startOnBoot.disableAutoStart('wnr');
163+
}
164+
}
165+
}
140166
function relauncher() {
141167
ipc.send("relauncher");
142168
}

style.css

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,23 @@ input:focus::-webkit-input-placeholder, input:hover::-webkit-input-placeholder {
8686
-webkit-user-select: text;
8787
position: absolute;
8888
top: 35px;
89-
left: 25px;
89+
left: 35.5px;
90+
overflow-y:scroll;
91+
height: 444px;
92+
width: 90%;
93+
}
94+
#settingscontainer::-webkit-scrollbar-track{
95+
background-color: #fefefe;
96+
}
97+
#settingscontainer::-webkit-scrollbar{
98+
width: 12px;
99+
background-color: #f5f5f5;
100+
}
101+
#settingscontainer::-webkit-scrollbar-thumb{
102+
background-color: #5555558f;
103+
}
104+
#settingscontainer::-webkit-scrollbar-thumb:active{
105+
background-color: #4a9af68f;
90106
}
91107
#controller{
92108
position: absolute;

timer.html

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@
1818
<body>
1919
<div class="d-flex mx-auto justify-content-center align-items-center text-dark" id="main">
2020
<div id="controller">
21-
<a href="index.html" class="small work"><i class="fa fa-chevron-left fa-fw" title="Give up the timer & Back" aria-hidden="true"></i></a>&nbsp;
22-
<a href="javascript:minimizer()" class="small work"><i class="fa fa-minus fa-fw" title="Hide the windows to system tray" aria-hidden="true"></i></a>&nbsp;
23-
<a href="javascript:window.close()" class="small work"><i class="fa fa-times fa-fw" title="Exit" aria-hidden="true"></i></a>
21+
<a href="index.html" class="small work"><i class="fa fa-chevron-left fa-fw" title="Give up the timer & Back"
22+
aria-hidden="true"></i></a>&nbsp;
23+
<a href="javascript:minimizer()" class="small work"><i class="fa fa-minus fa-fw" title="Hide the windows to system tray"
24+
aria-hidden="true"></i></a>&nbsp;
25+
<a href="javascript:window.close()" class="small work"><i class="fa fa-times fa-fw" title="Exit"
26+
aria-hidden="true"></i></a>
2427
</div>
2528
<div id="timer" class="justify-content-center">
2629
<div id="title" class="text-center h3"></div>
2730
<div id="work-rest" class="text-center work lead"><i class="fa fa-building" aria-hidden="true"></i></div>
2831
<div id="now-timing" class="text-center h1 work"></div>
29-
<div class="text-center"><a id="stopper" href="javascript:stopper()" class="text-black-50"><i class="fa fa-pause" aria-hidden="true"></i></a></div>
32+
<div class="text-center"><a id="stopper" href="javascript:stopper()" class="text-black-50"><i class="fa fa-pause"
33+
aria-hidden="true"></i></a></div>
3034
</div>
3135
</div><!-- for things with 'work' mark, when it's resting, the color should be changed -->
3236
<audio id="allend" src="res/sound/allend.wav"></audio>
@@ -62,7 +66,7 @@
6266
if (title && title != "undefined") $("#title").html(title);
6367
var starttime, int, t, seconds, minutes, hours, method = 1, times = 0, isclockworking = 1;//method: 1-work / 2-rest, times: time-reset times
6468
starttime = new Date().getTime();
65-
if (loop != 0) int = self.setInterval("clock()", 10);
69+
if (loop != 0) int = self.setInterval("clock()", 100);
6670
else ender();
6771
function stopper() {
6872
if (isclockworking) {
@@ -72,7 +76,7 @@
7276
} else {
7377
if (method == 1) starttime = new Date().getTime() - (worktime - hours * 3600000 - minutes * 60000 - seconds * 1000);
7478
else starttime = new Date().getTime() - (resttime - hours * 3600000 - minutes * 60000 - seconds * 1000);
75-
int = self.setInterval("clock()", 10);
79+
int = self.setInterval("clock()", 100);
7680
$("#stopper").html("<i class='fa fa-pause' aria-hidden='true'></i>");
7781
isclockworking = 1;//to restart
7882
}
@@ -114,6 +118,8 @@
114118
if (method == 1) seconds = parseInt((worktime - t + starttime) / 1000);
115119
else seconds = parseInt((resttime - t + starttime) / 1000);
116120
if (seconds > 0) {
121+
if (method == 1) ipc.send("progress-bar-set", (seconds / worktime) * 1000);
122+
else ipc.send("progress-bar-set", (seconds / resttime) * 1000);
117123
hours = parseInt(seconds / 3600);
118124
minutes = parseInt((seconds - hours * 3600) / 60);
119125
seconds = seconds - hours * 3600 - minutes * 60;

0 commit comments

Comments
 (0)