Skip to content

Commit

Permalink
optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
RoderickQiu committed Jan 24, 2019
1 parent 0da7d47 commit 36672a2
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 21 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 onpaste="return false">
<!-- prevent people from pasting abnormal content -->
<body >
<!-- prevent people from pasting abnormal contentonpaste="return false" -->
<script>
function about() {
ipc.send("about");
Expand Down
31 changes: 23 additions & 8 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ const store = new Store();

// 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, aboutWin
let win, settingsWin = null, aboutWin = null
let tray = null

app.commandLine.appendSwitch('autoplay-policy', 'no-user-gesture-required');// 允许自动播放音频

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

globalShortcut.register('CommandOrControl+Shift+Alt+W', () => {
win.isVisible() ? win.hide() : win.show();
if (settingsWin) settingsWin.isVisible() ? settingsWin.hide() : settingsWin.show();
if (aboutWin) aboutWin.isVisible() ? aboutWin.hide() : aboutWin.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')
const contextMenu = Menu.buildFromTemplate([
{ label: 'Show/Hide', click: () => { win.isVisible() ? win.hide() : win.show() } },
{
label: 'Show/Hide', 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();
}
},
{ label: 'Exit', click: () => { app.quit() } }
])
tray.setToolTip('wnr')
tray.setContextMenu(contextMenu)
tray.on('click', () => {
win.isVisible() ? win.hide() : win.show()
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') {
Expand Down Expand Up @@ -209,22 +216,30 @@ ipcMain.on('about', function () {
aboutWin.once('ready-to-show', () => {
aboutWin.show()
})
aboutWin.on('closed', () => {
aboutWin = null
})
})

ipcMain.on('settings', function () {
settingsWin = new BrowserWindow({ parent: win, modal: true, width: 720, height: 700, resizable: false, frame: false, show: false, center: true, webPreferences: { nodeIntegration: true } });
settingsWin = new BrowserWindow({ parent: win, modal: true, width: 720, height: 500, resizable: false, frame: false, show: false, center: true, webPreferences: { nodeIntegration: true } });
settingsWin.loadFile("settings.html");
if (store.get("top") == true || store.get("top") == undefined) settingsWin.setAlwaysOnTop(true);
settingsWin.once('ready-to-show', () => {
settingsWin.show();
})
settingsWin.on('closed', () => {
if (win != null) {
win.reload()
win.reload();
}
settingsWin = null
})
})

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

/* 参考:
- https://blog.avocode.com/4-must-know-tips-for-building-cross-platform-electron-apps-f3ae9c2bffff [need proxy]
- https://electronjs.org/docs
Expand Down
17 changes: 16 additions & 1 deletion package-lock.json

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

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "wnr",
"version": "1.1.3",
"update-use-version": "11377",
"version": "1.1.4",
"update-use-version": "11477",
"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,9 +21,10 @@
"copyright": "© Roderick Qiu",
"productName": "wnr",
"dependencies": {
"cheerio": "^1.0.0-rc.2",
"electron-store": "^2.0.0",
"request": "^2.88.0",
"cheerio": "^1.0.0-rc.2"
"start-on-windows-boot": "^1.0.0"
},
"devDependencies": {
"electron": "^4.0.2",
Expand Down
26 changes: 26 additions & 0 deletions settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@
required. <span id="restarttip"></span></b>
</span>
</div>
<div class="align-content-center form-text">
<label>Start up with system: </label>
<input id="autostart-set" type="checkbox" onchange="autostartset()" checked />
<br /><span class="text-muted small">
If it is enabled, every time your system starts, wnr starts. <b>(Only for Windows)</b>
</span>
</div>
<br />
<p class="lead"><i class="fa fa-ellipsis-h fa-fw" aria-hidden="true"></i>Other Things</p>
<hr />
Expand Down Expand Up @@ -137,6 +144,25 @@
else store.set("top", false);
$("#restarttip").html("(<a class='rest' href='javascript:relauncher()'>Restart Now</a>)");
}
if (store.get("autostart") != undefined) {
if (store.get("autostart")) $("#autostart-set").attr("checked");
else $("#autostart-set").removeAttr("checked");
}
function autostartset() {
var startOnBoot = require('start-on-windows-boot');
if (document.getElementById("autostart-set").checked) {
store.set("autostart", true);
if (process.platform == "win32") {
startOnBoot.enableAutoStart('wnr', __dirname + "\\wnr.exe");
}
}
else {
store.set("autostart", false);
if (process.platform == "win32") {
startOnBoot.disableAutoStart('wnr');
}
}
}
function relauncher() {
ipc.send("relauncher");
}
Expand Down
18 changes: 17 additions & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,23 @@ input:focus::-webkit-input-placeholder, input:hover::-webkit-input-placeholder {
-webkit-user-select: text;
position: absolute;
top: 35px;
left: 25px;
left: 35.5px;
overflow-y:scroll;
height: 444px;
width: 90%;
}
#settingscontainer::-webkit-scrollbar-track{
background-color: #fefefe;
}
#settingscontainer::-webkit-scrollbar{
width: 12px;
background-color: #f5f5f5;
}
#settingscontainer::-webkit-scrollbar-thumb{
background-color: #5555558f;
}
#settingscontainer::-webkit-scrollbar-thumb:active{
background-color: #4a9af68f;
}
#controller{
position: absolute;
Expand Down
18 changes: 12 additions & 6 deletions timer.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@
<body>
<div class="d-flex mx-auto justify-content-center align-items-center text-dark" id="main">
<div id="controller">
<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;
<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;
<a href="javascript:window.close()" class="small work"><i class="fa fa-times fa-fw" title="Exit" aria-hidden="true"></i></a>
<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;
<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;
<a href="javascript:window.close()" class="small work"><i class="fa fa-times fa-fw" title="Exit"
aria-hidden="true"></i></a>
</div>
<div id="timer" class="justify-content-center">
<div id="title" class="text-center h3"></div>
<div id="work-rest" class="text-center work lead"><i class="fa fa-building" aria-hidden="true"></i></div>
<div id="now-timing" class="text-center h1 work"></div>
<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>
<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>
</div>
</div><!-- for things with 'work' mark, when it's resting, the color should be changed -->
<audio id="allend" src="res/sound/allend.wav"></audio>
Expand Down Expand Up @@ -62,7 +66,7 @@
if (title && title != "undefined") $("#title").html(title);
var starttime, int, t, seconds, minutes, hours, method = 1, times = 0, isclockworking = 1;//method: 1-work / 2-rest, times: time-reset times
starttime = new Date().getTime();
if (loop != 0) int = self.setInterval("clock()", 10);
if (loop != 0) int = self.setInterval("clock()", 100);
else ender();
function stopper() {
if (isclockworking) {
Expand All @@ -72,7 +76,7 @@
} else {
if (method == 1) starttime = new Date().getTime() - (worktime - hours * 3600000 - minutes * 60000 - seconds * 1000);
else starttime = new Date().getTime() - (resttime - hours * 3600000 - minutes * 60000 - seconds * 1000);
int = self.setInterval("clock()", 10);
int = self.setInterval("clock()", 100);
$("#stopper").html("<i class='fa fa-pause' aria-hidden='true'></i>");
isclockworking = 1;//to restart
}
Expand Down Expand Up @@ -114,6 +118,8 @@
if (method == 1) seconds = parseInt((worktime - t + starttime) / 1000);
else seconds = parseInt((resttime - t + starttime) / 1000);
if (seconds > 0) {
if (method == 1) ipc.send("progress-bar-set", (seconds / worktime) * 1000);
else ipc.send("progress-bar-set", (seconds / resttime) * 1000);
hours = parseInt(seconds / 3600);
minutes = parseInt((seconds - hours * 3600) / 60);
seconds = seconds - hours * 3600 - minutes * 60;
Expand Down

0 comments on commit 36672a2

Please sign in to comment.