Skip to content

Commit

Permalink
updated & semantic time
Browse files Browse the repository at this point in the history
- Semantic time I/O (node-shi).
- Traditional Chinese support added.
- Prevent darkmode from sparking.
- Optimized, esp for time running efficiency.
- Bugs fixed.
  • Loading branch information
RoderickQiu committed Feb 27, 2020
1 parent 9979788 commit 020318a
Show file tree
Hide file tree
Showing 13 changed files with 484 additions and 157 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ The online wnr is now out: [wnr-jr](https://wnr-jr.scris.top). *(just a demo ver

## Features

- semantic time input

- work time settings

- rest time settings
Expand All @@ -37,7 +39,7 @@ The online wnr is now out: [wnr-jr](https://wnr-jr.scris.top). *(just a demo ver

- optional taskname and task notes

- tray menu / dock menu
- tray menu

- alerts for time end

Expand Down Expand Up @@ -107,6 +109,8 @@ yarn run linux

I'm now using yarn.

**I'm currently disabling `node-modules/conf/index.js`' error from throwing by annotationifying line 441 (`throw error;`) because it's error-occurring.**

## Copyright & Credit

Copyright (c) 2019-2020 **[Roderick Qiu](https://r-q.name)** and other contributors. All rights reserved.
Expand All @@ -117,6 +121,8 @@ Now licensed under the **[MPL2.0 License](https://github.com/RoderickQiu/wnr/blo

#### Main Program

- node-shi, [**my own project**](https://shi.r-q.name) following MIT License.
- cmd-or-ctrl, [**another project of mine**](https://www.npmjs.com/package/cmd-or-ctrl) following MIT License.
- node-auto-launch, Teamwork, MIT License.
- compare-version, kevva, MIT License.
- electron-store, sindresorhus, MIT License.
Expand All @@ -132,7 +138,7 @@ Now licensed under the **[MPL2.0 License](https://github.com/RoderickQiu/wnr/blo
- font-awesome, fontawesome, [License](https://github.com/FortAwesome/Font-Awesome/blob/master/LICENSE.txt).
- node-md5, pvorb, BSD 3-Clause License.

#### Website *([wnr-guide](https://github.com/RoderickQiu/wnr-guide), provided with [CC BY] license)*
#### Website *([wnr-guide](https://github.com/RoderickQiu/wnr-guide), provided with [CC-BY-4.0] license)*

- **vuepress, vuejs, MIT License**.
- vuepress-plugin-sitemap, ekoeryanto, MIT License.
Expand Down
89 changes: 48 additions & 41 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@



<body onpaste="return false">
<!-- prevent people from pasting abnormal content -->
<body>

<!-- loader -->
<div id="loader-wrapper">
Expand All @@ -37,7 +36,7 @@
window.onload = function () {
$("body").addClass("loaded");
setTimeout(function () { $('#loader-wrapper').remove() }, 1000);
}
}
</script>

<script src="supporter.js"></script><!-- support wnr running -->
Expand All @@ -49,15 +48,16 @@
store.set('islocked', false);
ipc.send("tourguide");
}
const shi = require("node-shi");
</script>
<script>
function keydown(e) {
var currKey = 0, e = e || event;
if (e.keyCode == 13) {
window.location.href = "timer.html?title=" + $("#title").val()
+ "&work-time=" + $("#work-time").val()
+ "&rest-time=" + $("#rest-time").val()
+ "&loop=" + $("#loop").val()
+ "&work-time=" + shi.humanTimeParser($("#work-time").val(), { as: "m", to: "m", ignoreError: true })
+ "&rest-time=" + shi.humanTimeParser($("#rest-time").val(), { as: "m", to: "m", ignoreError: true })
+ "&loop=" + $("#loop").val().replace(new RegExp('[' + i18n.__('times') + ']', "g"), "")
+ "&note=" + $("#note").val()
+ "&method=1";
}
Expand Down Expand Up @@ -128,28 +128,24 @@
</div>
<br /><br />
<div class="align-content-center">
<input name="work-time" id="work-time" type="number" onkeyup="allSet()"
oninput="if (value.length > 4) value = value.slice(0, 4)" style="ime-mode:Disabled"
class="work lead" autofocus required />
<input id="focus-work-set" type="checkbox" onchange="focusWorkSet()" /><span
class="focuser extreme-small work">
<input name="work-time" id="work-time" type="text" onkeyup="allSet()" class="work lead" autofocus
required />
<input id="focus-work-set" type="checkbox" onchange="focusWorkSet()" />
<span class="focuser extreme-small work">
<script>document.write(i18n.__('focus-mode-part-1') + "<br />" + i18n.__('focus-mode-part-2'))</script>
</span>
</div>
<br />
<div class="align-content-center">
<input name="rest-time" id="rest-time" type="number" onkeyup="allSet()"
oninput="if (value.length > 4) value = value.slice(0, 4)" style="ime-mode:Disabled"
class="rest lead" required />
<input id="focus-rest-set" type="checkbox" onchange="focusRestSet()" /><span
class="focuser extreme-small rest">
<input name="rest-time" id="rest-time" type="text" onkeyup="allSet()" class="rest lead" required />
<input id="focus-rest-set" type="checkbox" onchange="focusRestSet()" />
<span class="focuser extreme-small rest">
<script>document.write(i18n.__('focus-mode-part-1') + "<br />" + i18n.__('focus-mode-part-2'))</script>
</span>
</div>
<br />
<input name="loop" id="loop" type="number" onkeyup="allSet()"
oninput="if (value.length > 3) value = value.slice(0, 3)" style="ime-mode:Disabled"
class="small text-muted" required />
<input name="loop" id="loop" type="text" onkeyup="allSet()"
oninput="if (value.length > 5) value = value.slice(0, 5)" class="small text-muted" required />
<br /><br />
<!-- control that only numbers are OK -->
<input name="note" id="note" type="text" class="small text-muted" maxlength="39" />
Expand Down Expand Up @@ -183,22 +179,33 @@
}

var timeCount, myDate, h, min, defaultArray;
function sumGet() {
timeCount = (Number($("#work-time").val()) + Number($("#rest-time").val())) * Number($("#loop").val());
$("#all-sum-num").html(timeCount);
myDate = new Date();
h = myDate.getHours() + Number(timeCount / 60);
min = myDate.getMinutes() + timeCount % 60;
if (min >= 60) min -= 60, h++;
while (h >= 24) h -= 24;
$("#to-num-h").html(parseInt(h));
if (min >= 10) $("#to-num-min").html(parseInt(min));
else $("#to-num-min").html("0" + parseInt(min));
function sumGet(workTimeGet, restTimeGet, loopGet) {
timeCount = (Number(workTimeGet) + Number(restTimeGet)) * Number(loopGet);
if (timeCount != NaN) {
$("#all-sum-num").html(timeCount);
myDate = new Date();
h = myDate.getHours() + Number(timeCount / 60);
min = myDate.getMinutes() + timeCount % 60;
if (min >= 60) min -= 60, h++;
while (h >= 24) h -= 24;
$("#to-num-h").html(parseInt(h));
if (min >= 10) $("#to-num-min").html(parseInt(min));
else $("#to-num-min").html("0" + parseInt(min));
}
}
function allSet() {
if (Number($("#work-time").val()) != 0 && Number($("#rest-time").val()) != 0 && Number($("#loop").val()) != 0 && String(Number($("#work-time").val())).indexOf('e') == -1 && String(Number($("#rest-time").val())).indexOf('e') == -1 && String(Number($("#loop").val())).indexOf('e') == -1) {
if ((Number($("#work-time").val()) + Number($("#rest-time").val())) * Number($("#loop").val())) sumGet();
} else {
try {
var workTimeGet = shi.humanTimeParser($("#work-time").val(), { as: "m", to: "m", ignoreError: true }),
restTimeGet = shi.humanTimeParser($("#rest-time").val(), { as: "m", to: "m", ignoreError: true }),
loopGet = $("#loop").val().replace(new RegExp('[' + i18n.__('times') + ']', "g"), "")
if (workTimeGet != 0 && restTimeGet != 0 && loopGet != 0 && workTimeGet <= 1440 && restTimeGet <= 1440 && loopGet <= 1440) {
if ((workTimeGet + restTimeGet) * loopGet) sumGet(workTimeGet, restTimeGet, loopGet);
} else {
$("#all-sum-num").html("---");
$("#to-num-h").html("--");
$("#to-num-min").html("--");
}
} catch {
$("#all-sum-num").html("---");
$("#to-num-h").html("--");
$("#to-num-min").html("--");
Expand All @@ -213,9 +220,9 @@
}

function defaultSet(workTime, restTime, loops, focusWhenWorking, focusWhenResting) {
$("#work-time").val(workTime);
$("#rest-time").val(restTime);
$("#loop").val(loops);
$("#work-time").val(shi.ArabicNumberTimeParser(workTime, { as: 'm', lang: store.get("i18n").replace(/-/g, '_'), ignoreError: true }));
$("#rest-time").val(shi.ArabicNumberTimeParser(restTime, { as: 'm', lang: store.get("i18n").replace(/-/g, '_'), ignoreError: true }));
$("#loop").val(loops + ' ' + i18n.__('times'));
document.getElementById("focus-work-set").checked = focusWhenWorking;
document.getElementById("focus-rest-set").checked = focusWhenResting;
focusWorkSet();
Expand All @@ -230,11 +237,11 @@
(!store.get("just-relaunched"))) {//auto-send the form is autostarttask is on
window.location.href =
"timer.html?title=" + $("#title").val()
+ "&work-time=" + $("#work-time").val()
+ "&rest-time=" + $("#rest-time").val()
+ "&loop=" + $("#loop").val()
+ "&work-time=" + shi.humanTimeParser($("#work-time").val(), { as: "m", to: "m", ignoreError: true })
+ "&rest-time=" + shi.humanTimeParser($("#rest-time").val(), { as: "m", to: "m", ignoreError: true })
+ "&loop=" + $("#loop").val().replace(new RegExp('[' + i18n.__('times') + ']', "g"), "")
+ "&note=" + $("#note").val()
+ "&method=" + 1;
+ "&method=1";
} else if (store.get("just-relaunched")) {
store.set("just-relaunched", false);
}
Expand All @@ -251,7 +258,7 @@
store.set("fullscreen", store.get("last-recorded-state").isRestTimeFocused);
if (store.get('last-recorded-hours-left') == 0 && store.get("last-recorded-minutes-left") < 2)
store.set("last-recorded-minutes-left", 2);
if (store.get("last-recorded-method") == 1) {
if (store.get("last-recorded-state").method == 1) {
window.location.href =
"timer.html?title=" + store.get("last-recorded-state").title
+ "&work-time=" + store.get("last-recorded-hours-left") * 60 + store.get("last-recorded-minutes-left")
Expand Down
15 changes: 15 additions & 0 deletions locales/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Languages

Until now, wnr has get these languages:

- English

- Chinese (Simplified Chinese)

- Chinese (Traditional Chinese)

And we're now hoping to have more languages. The name of translated file should follow [this guide](https://www.electronjs.org/docs/api/locales).

All the languages are stored in JSON format, using [i18n-node](https://github.com/mashpie/i18n-node).

After changed Simplified Chinese / Traditional Chinese, use [this tool](http://www.aies.cn/) to sync the changes.
8 changes: 4 additions & 4 deletions locales/zh.json → locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"time-settings": "默认时间设置",
"global-settings": "wnr全局设置",
"language-setting": "语言设置:",
"language-setting-tip": "选中选框则设置为英语,否则设置为中文。",
"language-setting-tip": "选中选框则设置为英语,否则设置为中文(将会自动根据本机设置,调整为简体中文或者正体中文)",
"sound-to-notify-setting": "提示音设置:",
"sound-to-notify-setting-tip": "在一段时间结束后,是否要播放提示音?",
"always-on-top-setting": "置顶设置:",
Expand Down Expand Up @@ -97,8 +97,8 @@
"alarm-for-not-using-wnr-dialog-box-content": "打开wnr,开始一个新计划吧!",
"all-sum-part-1": "共计",
"all-sum-part-2": "分钟,到",
"only-one-min-left": "时间仅剩1分钟",
"only-one-min-left-msg": "这一段时间只剩下1分钟了,好好规划一下暂时的收尾工作吧!",
"only-one-min-left": "时间仅剩不到1分钟",
"only-one-min-left-msg": "这一段时间只剩下不到1分钟了,好好规划一下暂时的收尾工作吧!",
"operations": "操作",
"tourguide": "导览",
"about": "关于",
Expand All @@ -107,7 +107,7 @@
"wrong-folder-notification-title": "当前应用并不在应用程序文件夹中",
"wrong-folder-notification-content": "把应用移到系统的应用程序文件夹中可以更方便地使用wnr。",
"more-than-one-wnr-running-dialog-box-title": "有不止一个wnr正在运行",
"more-than-one-wnr-running-dialog-box-content": "我们强烈建议只同时运行一个wnr程序。如果不退出,请取消勾选“退出当前”并点确认,然后等待程序加载。",
"more-than-one-wnr-running-dialog-box-content": "我们强烈建议只同时运行一个wnr程序,运行超过一个wnr可能导致糟糕的情况发生。如果不退出,请取消勾选“退出当前”并点确认,然后等待程序加载。",
"more-than-one-wnr-running-dialog-box-chk": "退出当前",
"notification-sending-tip-msg": "通知相关事项:",
"notification-sending-tip": "wnr有时会发送通知(可以在系统设置中调整)。",
Expand Down
Loading

0 comments on commit 020318a

Please sign in to comment.