Skip to content

Commit ec99515

Browse files
committed
FullUpdt0607-Added Timer (Beta)
1 parent 754d85e commit ec99515

File tree

5 files changed

+94
-97
lines changed

5 files changed

+94
-97
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
## SimpleTime
2+
**Mainstream support for this project ended on 6 July 2021. I don't have any plans to continue to work on this. only bug fixes until end of life. However SimpleTime has been and always will be open to contributions!**
3+
24
A simple cross-platform timer and stopwatch app with modern design in mind. Using Neutralino JS. heavily in development, bugs are expected.
35

46
## Available for
57
- Windows
68

7-
**Note : You need to have WebView2 or Latest Microsoft Edge Installed for app to function correctly, check "Apps and features" in Windows settings. If you don't have it installed, download it from [here](https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section).**
9+
**Note : You need to have WebView2 or Latest Microsoft Edge Installed for app to function correctly.**
810

9-
**Note: if you are getting a white screen after opening app, run this command as admin**
11+
**Note: if you are getting a white screen after opening app, You should update Microsoft Edge or get WebView2 Engine [HERE](https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section) manually**
1012

11-
```CheckNetIsolation.exe LoopbackExempt -a -n="Microsoft.Win32WebViewHost_cw5n1h2txyewy"```
12-
> The reason is that accessing localhost from a UWP context is disabled by default. Run the following command with administrative privileges on the command prompt.
1313

14-
Unfortunately it is a problem with Neutralino JS.
1514

1615
- Linux
1716

@@ -30,16 +29,18 @@ neu build -r
3029

3130
## Contributions
3231

33-
SimpleTime is open to contributions, but I recommend creating an issue or replying in a comment to let me know what you are working on first that way we don't overwrite each other.
32+
SimpleTime is open to contributions, but I recommend creating an issue or replying in a comment to let me know what you are working on first, that way we don't overwrite each other.
3433

3534
## Future of the project
36-
this project may be a part of a bigger parent project. But for now, I don't have any plans.
35+
This project was for personal use and I made it public. it may be a part of a bigger parent project. But for now, I don't have any plans.
36+
3737

3838
## Thanks
3939
to [@SinisterStalker](https://github.com/sinisterstalker) and [@Al1382](https://github.com/Al1382) for Testing and ideas.
4040

41-
## License and Copyright
41+
## License, Copyright and Attribution
4242
- Neutralinojs core: MIT. Copyright © 2021 Neutralinojs and contributors.
4343
- SimpleTime : GNU GPLv3. Copyright © 2021 Navid Mafi Ranji and contributors.
4444
- DSEG Font Family : OFL-1.1. Copyright © 2021 DSEG Font Family and contributors.
45-
- Sound Effects By [Zapsplat](https://www.zapsplat.com) , [License](https://www.zapsplat.com/license-type/standard-license/).
45+
- Sound Effect By [Zapsplat](https://www.zapsplat.com) , [License](https://www.zapsplat.com/license-type/standard-license/).
46+
- App Icon By [Freepik](https://www.freepik.com/) from [Flaticon](https://www.flaticon.com/free-icon/clock_2784399) , [License](https://media.flaticon.com/license/license.pdf).

neutralino.config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
"nativeBlockList": [],
99
"modes": {
1010
"window": {
11-
"title": "SimpleTime-Build210630",
11+
"title": "SimpleTime",
1212
"width": 400,
1313
"height": 110,
1414
"minWidth": 400,
1515
"minHeight": 150,
1616
"fullScreen": false,
1717
"alwaysOnTop": true,
18-
"icon": "/resources/icons/appIcon.png",
18+
"icon": "/resources/icons/clock.png",
1919
"enableInspector": true,
2020
"borderless": false,
2121
"maximize": false

resources/icons/appIcon.png

-16 KB
Binary file not shown.

resources/icons/clock.png

53.5 KB
Loading

resources/js/main.js

Lines changed: 82 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
let startTime;
22
let elapsedTime = 0;
33
let timerInterval;
4+
let zerocheckInterval;
45
let PPbtn = document.getElementById("playpauseButton");
56
let RstBtn = document.getElementById("resetButton");
67
let StpBtn = document.getElementById("stopButton");
@@ -20,35 +21,38 @@ let timerval;
2021
let PREFDATA;
2122
let MODE;
2223
let runninstatus;
23-
24-
function updater() {
24+
let updateinterval;
25+
async function updater() {
2526
runninstatus = "off";
2627
MODE = "CHRONO";
2728
document.addEventListener("contextmenu", (event) => event.preventDefault());
28-
printbig("Starting...", 2000);
29-
checkfirstrun();
30-
setTimeout(() => {
31-
if (PREFDATA.showms == false) {
32-
display.innerText = "0:00:00";
33-
}
34-
if (PREFDATA.useeff == false) {
35-
oc.firstElementChild.style.display="none";
36-
}
37-
}, 500);
29+
printbig("Starting...", 1000);
30+
await checkfirstrun();
31+
await getprefs();
32+
if (PREFDATA.showms == false) {
33+
display.innerText = "0:00:00";
34+
}
35+
if (PREFDATA.useeff == false) {
36+
oc.firstElementChild.style.display = "none";
37+
}
3838
PPbtn.addEventListener("click", togglerunnin);
3939
RstBtn.addEventListener("click", reset);
40-
StpBtn.addEventListener("click",stop)
41-
SttBtn.addEventListener("click", showsettings)
42-
timerbtn.addEventListener("click",settimer)
40+
StpBtn.addEventListener("click", stop);
41+
SttBtn.addEventListener("click", showsettings);
42+
timerbtn.addEventListener("click", settimer);
4343
document.addEventListener("keydown", function (event) {
4444
if (event.code === "Space") {
4545
togglerunnin();
4646
}
4747
});
48-
getprefs();
48+
if (PREFDATA.showms == false) {
49+
updateinterval = 100;
50+
}
51+
if (PREFDATA.showms == true) {
52+
updateinterval = 10;
53+
}
4954
}
5055

51-
5256
async function readdata() {
5357
let response = await Neutralino.storage.getData({
5458
bucket: "prefs",
@@ -60,7 +64,6 @@ async function getprefs() {
6064
PREFDATA = await readdata();
6165
}
6266

63-
6467
async function firstdetected() {
6568
await Neutralino.filesystem.createDirectory({
6669
path: "./.storage",
@@ -69,7 +72,7 @@ async function firstdetected() {
6972
fileName: "./.storage/prefs.neustorage",
7073
data: '{"showms":true , "useeff":true}',
7174
});
72-
printbig("GenConfig..",500)
75+
printbig("GenConfig..", 500);
7376
setTimeout(() => {
7477
window.location.reload();
7578
}, 500);
@@ -103,79 +106,70 @@ function timeToString(time) {
103106
let formattedMM = mm.toString().padStart(2, "0");
104107
let formattedSS = ss.toString().padStart(2, "0");
105108
let formattedMS = ms.toString().padStart(2, "0");
109+
106110
if (PREFDATA.showms == true) {
107111
return `${formattedHH}:${formattedMM}:${formattedSS}:${formattedMS}`;
108112
}
109113
if (PREFDATA.showms == false) {
110114
return `${formattedHH}:${formattedMM}:${formattedSS}`;
111-
}
112-
else {
113-
return `err`;
114-
}
115+
}
115116
}
116117

117118
function print(txt) {
118119
display.innerHTML = txt;
119120
}
120121

121122
function start() {
122-
if (runninstatus != "timerpaused") {
123-
runninstatus = "crn";
124-
}
125-
126-
document.getElementById("oc").style.opacity = "1";
127-
PPbtn.innerText="Pause";
128-
var x;
129-
if (PREFDATA.showms == false){
130-
console.log("runin in 1s mode");
131-
x=1000;
132-
}
133-
if (PREFDATA.showms == true){
134-
x=10;
135-
}
136-
137-
if (runninstatus=="timerpaused") {
138-
runninstatus = "timerrunning";
139-
startTime = Date.now() - elapsedTime;
123+
startTime = Date.now() - elapsedTime;
124+
if (runninstatus == "timerpaused") {
140125
timerInterval = setInterval(function printTime() {
141126
elapsedTime = Date.now() - startTime;
142127
print(timeToString(timerval-elapsedTime));
143-
}, x);
128+
}, updateinterval);
129+
runninstatus = "timerrunning";
144130
}
145-
if (runninstatus=="crn") {
146-
startTime = Date.now() - elapsedTime;
131+
else {
147132
timerInterval = setInterval(function printTime() {
148133
elapsedTime = Date.now() - startTime;
149134
print(timeToString(elapsedTime));
150-
}, x);
151-
}
135+
}, updateinterval);
136+
runninstatus = "crn";
152137

138+
}
139+
document.getElementById("oc").style.opacity = "1";
140+
PPbtn.innerText = "Pause";
141+
zerocheckInterval = setInterval(function checkforzero() {
142+
if (timerval-1000 <= elapsedTime) {
143+
timeEnded();
144+
}
145+
}, 1000);
153146
}
154147

155148
function pause() {
156-
if (runninstatus=="crn") {
157-
runninstatus="crnpaused"
149+
if (runninstatus == "crn") {
150+
runninstatus = "crnpaused";
158151
}
159-
if (runninstatus=="timerrunning") {
160-
runninstatus="timerpaused"
152+
if (runninstatus == "timerrunning") {
153+
runninstatus = "timerpaused";
154+
}
155+
if (PREFDATA.useeff == false) {
156+
oc.firstElementChild.style.display = "none";
157+
}
158+
if (PREFDATA.useeff == true) {
159+
document.getElementById("oc").style.opacity = "0.5";
161160
}
162-
document.getElementById("oc").style.opacity = "0.5";
163161
clearInterval(timerInterval);
164-
165-
PPbtn.innerText="Resume";
162+
clearInterval(zerocheckInterval);
163+
PPbtn.innerText = "Resume";
166164
}
167165

168-
function c(d){
166+
function c(d) {
169167
console.log(d);
170168
//dEbUG XD
171169
}
172170

173171
function showsettings() {
174-
if (runninstatus == "crn") {
175-
pause();
176-
runninstatus == "insettings";
177-
}
178-
172+
pause();
179173
mainscreen.style.display = "none";
180174
backbtn.removeAttribute("style");
181175
setscreen.style.display = "grid";
@@ -184,24 +178,22 @@ function showsettings() {
184178
async function mainscreenshow() {
185179
await getprefs();
186180
setscreen.style.display = "none";
187-
timerscreen.style.display="none";
181+
timerscreen.style.display = "none";
188182
backbtn.style.display = "none";
189183
mainscreen.style.display = "grid";
190-
if (runninstatus=="timerpaused") {
191-
print(timeToString(timerval));
184+
if (runninstatus == "timerpaused") {
185+
print(timeToString(timerval-elapsedTime));
192186
}
193-
if (runninstatus=="crn") {
187+
if (runninstatus == "crn") {
194188
print(timeToString(elapsedTime));
195189
}
196-
197190

198191
if (PREFDATA.useeff == false) {
199-
oc.firstElementChild.style.display="none";
192+
oc.firstElementChild.style.display = "none";
200193
}
201194
if (PREFDATA.useeff == true) {
202195
oc.firstElementChild.removeAttribute("style");
203196
}
204-
205197
}
206198

207199
function printbig(text, time) {
@@ -219,49 +211,52 @@ function reset() {
219211
document.getElementById("timeended").currentTime = 0;
220212
display.removeAttribute("style");
221213
elapsedTime = 0;
222-
runninstatus= "off";
214+
runninstatus = "off";
223215
setTimeout(() => {
224216
print(timeToString(elapsedTime));
225217
RstBtn.removeAttribute("style");
226218
PPbtn.removeAttribute("style");
227-
PPbtn.innerText="Start";
219+
PPbtn.innerText = "Start";
228220
StpBtn.removeAttribute("style");
229221
}, 80);
230222
}
231223

232224
function settimer() {
233-
mainscreen.style.display="none";
234-
setscreen.style.display="none";
235-
timerscreen.style.display="grid";
225+
mainscreen.style.display = "none";
226+
setscreen.style.display = "none";
227+
timerscreen.style.display = "grid";
236228
}
237229

238230
function togglerunnin() {
239-
240-
if (runninstatus == "timerpaused" || runninstatus == "crnpaused" || runninstatus == "off") {
231+
if (
232+
runninstatus == "timerpaused" ||
233+
runninstatus == "crnpaused" ||
234+
runninstatus == "off"
235+
) {
241236
start();
242-
}
243-
else {
237+
} else {
244238
pause();
245239
}
246240
}
247241

248242
function getformdata() {
249-
timerval= timerinputelmnt.value*1000*60;
250-
runninstatus="timerpaused";
251-
c(timerval);
252-
print(timeToString(timerval));
253-
clearInterval(timerInterval);
254-
mainscreenshow();
243+
reset();
244+
setTimeout(() => {
245+
timerval = timerinputelmnt.value * 1000 * 60;
246+
runninstatus = "timerpaused";
247+
c(timerval);
248+
print(timeToString(timerval));
249+
mainscreenshow();
250+
}, 100);
255251
}
256252

257253
function timeEnded() {
258254
stop();
259-
document.getElementById("timeended").loop = true;
255+
document.getElementById("timeended").loop = true;
260256
display.style.color = "#fc2149";
261257
display.innerText = "END";
262258
display.style.textShadow = "none";
263259
document.getElementById("timeended").play();
264-
265260
}
266261

267262
function stop() {
@@ -271,7 +266,7 @@ function stop() {
271266
RstBtn.style.width = "50%";
272267
PPbtn.style.display = "none";
273268
StpBtn.style.display = "none";
274-
};
269+
}
275270

276271
efftgl.onclick = async function () {
277272
console.log("hello");
@@ -317,9 +312,8 @@ mstoggle.onclick = async function () {
317312
printbig("Applying", 600);
318313
setTimeout(() => {
319314
getprefs();
315+
updateinterval = 10;
320316
}, 500);
321-
322-
323317
}
324318
if (PREFDATA.showms == true) {
325319
await Neutralino.storage.putData({
@@ -332,6 +326,8 @@ mstoggle.onclick = async function () {
332326
printbig("Applying", 600);
333327
setTimeout(() => {
334328
getprefs();
329+
updateinterval = 1000;
330+
335331
}, 500);
336332
}
337333
};

0 commit comments

Comments
 (0)