Skip to content

Commit

Permalink
FullUpdt0607-Added Timer (Beta)
Browse files Browse the repository at this point in the history
  • Loading branch information
navidmafi committed Jul 6, 2021
1 parent 754d85e commit ec99515
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 97 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
## SimpleTime
**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!**

A simple cross-platform timer and stopwatch app with modern design in mind. Using Neutralino JS. heavily in development, bugs are expected.

## Available for
- Windows

**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).**
**Note : You need to have WebView2 or Latest Microsoft Edge Installed for app to function correctly.**

**Note: if you are getting a white screen after opening app, run this command as admin**
**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**

```CheckNetIsolation.exe LoopbackExempt -a -n="Microsoft.Win32WebViewHost_cw5n1h2txyewy"```
> 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.

Unfortunately it is a problem with Neutralino JS.

- Linux

Expand All @@ -30,16 +29,18 @@ neu build -r

## Contributions

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.
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.

## Future of the project
this project may be a part of a bigger parent project. But for now, I don't have any plans.
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.


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

## License and Copyright
## License, Copyright and Attribution
- Neutralinojs core: MIT. Copyright © 2021 Neutralinojs and contributors.
- SimpleTime : GNU GPLv3. Copyright © 2021 Navid Mafi Ranji and contributors.
- DSEG Font Family : OFL-1.1. Copyright © 2021 DSEG Font Family and contributors.
- Sound Effects By [Zapsplat](https://www.zapsplat.com) , [License](https://www.zapsplat.com/license-type/standard-license/).
- Sound Effect By [Zapsplat](https://www.zapsplat.com) , [License](https://www.zapsplat.com/license-type/standard-license/).
- 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).
4 changes: 2 additions & 2 deletions neutralino.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
"nativeBlockList": [],
"modes": {
"window": {
"title": "SimpleTime-Build210630",
"title": "SimpleTime",
"width": 400,
"height": 110,
"minWidth": 400,
"minHeight": 150,
"fullScreen": false,
"alwaysOnTop": true,
"icon": "/resources/icons/appIcon.png",
"icon": "/resources/icons/clock.png",
"enableInspector": true,
"borderless": false,
"maximize": false
Expand Down
Binary file removed resources/icons/appIcon.png
Binary file not shown.
Binary file added resources/icons/clock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
168 changes: 82 additions & 86 deletions resources/js/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let startTime;
let elapsedTime = 0;
let timerInterval;
let zerocheckInterval;
let PPbtn = document.getElementById("playpauseButton");
let RstBtn = document.getElementById("resetButton");
let StpBtn = document.getElementById("stopButton");
Expand All @@ -20,35 +21,38 @@ let timerval;
let PREFDATA;
let MODE;
let runninstatus;

function updater() {
let updateinterval;
async function updater() {
runninstatus = "off";
MODE = "CHRONO";
document.addEventListener("contextmenu", (event) => event.preventDefault());
printbig("Starting...", 2000);
checkfirstrun();
setTimeout(() => {
if (PREFDATA.showms == false) {
display.innerText = "0:00:00";
}
if (PREFDATA.useeff == false) {
oc.firstElementChild.style.display="none";
}
}, 500);
printbig("Starting...", 1000);
await checkfirstrun();
await getprefs();
if (PREFDATA.showms == false) {
display.innerText = "0:00:00";
}
if (PREFDATA.useeff == false) {
oc.firstElementChild.style.display = "none";
}
PPbtn.addEventListener("click", togglerunnin);
RstBtn.addEventListener("click", reset);
StpBtn.addEventListener("click",stop)
SttBtn.addEventListener("click", showsettings)
timerbtn.addEventListener("click",settimer)
StpBtn.addEventListener("click", stop);
SttBtn.addEventListener("click", showsettings);
timerbtn.addEventListener("click", settimer);
document.addEventListener("keydown", function (event) {
if (event.code === "Space") {
togglerunnin();
}
});
getprefs();
if (PREFDATA.showms == false) {
updateinterval = 100;
}
if (PREFDATA.showms == true) {
updateinterval = 10;
}
}


async function readdata() {
let response = await Neutralino.storage.getData({
bucket: "prefs",
Expand All @@ -60,7 +64,6 @@ async function getprefs() {
PREFDATA = await readdata();
}


async function firstdetected() {
await Neutralino.filesystem.createDirectory({
path: "./.storage",
Expand All @@ -69,7 +72,7 @@ async function firstdetected() {
fileName: "./.storage/prefs.neustorage",
data: '{"showms":true , "useeff":true}',
});
printbig("GenConfig..",500)
printbig("GenConfig..", 500);
setTimeout(() => {
window.location.reload();
}, 500);
Expand Down Expand Up @@ -103,79 +106,70 @@ function timeToString(time) {
let formattedMM = mm.toString().padStart(2, "0");
let formattedSS = ss.toString().padStart(2, "0");
let formattedMS = ms.toString().padStart(2, "0");

if (PREFDATA.showms == true) {
return `${formattedHH}:${formattedMM}:${formattedSS}:${formattedMS}`;
}
if (PREFDATA.showms == false) {
return `${formattedHH}:${formattedMM}:${formattedSS}`;
}
else {
return `err`;
}
}
}

function print(txt) {
display.innerHTML = txt;
}

function start() {
if (runninstatus != "timerpaused") {
runninstatus = "crn";
}

document.getElementById("oc").style.opacity = "1";
PPbtn.innerText="Pause";
var x;
if (PREFDATA.showms == false){
console.log("runin in 1s mode");
x=1000;
}
if (PREFDATA.showms == true){
x=10;
}

if (runninstatus=="timerpaused") {
runninstatus = "timerrunning";
startTime = Date.now() - elapsedTime;
startTime = Date.now() - elapsedTime;
if (runninstatus == "timerpaused") {
timerInterval = setInterval(function printTime() {
elapsedTime = Date.now() - startTime;
print(timeToString(timerval-elapsedTime));
}, x);
}, updateinterval);
runninstatus = "timerrunning";
}
if (runninstatus=="crn") {
startTime = Date.now() - elapsedTime;
else {
timerInterval = setInterval(function printTime() {
elapsedTime = Date.now() - startTime;
print(timeToString(elapsedTime));
}, x);
}
}, updateinterval);
runninstatus = "crn";

}
document.getElementById("oc").style.opacity = "1";
PPbtn.innerText = "Pause";
zerocheckInterval = setInterval(function checkforzero() {
if (timerval-1000 <= elapsedTime) {
timeEnded();
}
}, 1000);
}

function pause() {
if (runninstatus=="crn") {
runninstatus="crnpaused"
if (runninstatus == "crn") {
runninstatus = "crnpaused";
}
if (runninstatus=="timerrunning") {
runninstatus="timerpaused"
if (runninstatus == "timerrunning") {
runninstatus = "timerpaused";
}
if (PREFDATA.useeff == false) {
oc.firstElementChild.style.display = "none";
}
if (PREFDATA.useeff == true) {
document.getElementById("oc").style.opacity = "0.5";
}
document.getElementById("oc").style.opacity = "0.5";
clearInterval(timerInterval);

PPbtn.innerText="Resume";
clearInterval(zerocheckInterval);
PPbtn.innerText = "Resume";
}

function c(d){
function c(d) {
console.log(d);
//dEbUG XD
}

function showsettings() {
if (runninstatus == "crn") {
pause();
runninstatus == "insettings";
}

pause();
mainscreen.style.display = "none";
backbtn.removeAttribute("style");
setscreen.style.display = "grid";
Expand All @@ -184,24 +178,22 @@ function showsettings() {
async function mainscreenshow() {
await getprefs();
setscreen.style.display = "none";
timerscreen.style.display="none";
timerscreen.style.display = "none";
backbtn.style.display = "none";
mainscreen.style.display = "grid";
if (runninstatus=="timerpaused") {
print(timeToString(timerval));
if (runninstatus == "timerpaused") {
print(timeToString(timerval-elapsedTime));
}
if (runninstatus=="crn") {
if (runninstatus == "crn") {
print(timeToString(elapsedTime));
}


if (PREFDATA.useeff == false) {
oc.firstElementChild.style.display="none";
oc.firstElementChild.style.display = "none";
}
if (PREFDATA.useeff == true) {
oc.firstElementChild.removeAttribute("style");
}

}

function printbig(text, time) {
Expand All @@ -219,49 +211,52 @@ function reset() {
document.getElementById("timeended").currentTime = 0;
display.removeAttribute("style");
elapsedTime = 0;
runninstatus= "off";
runninstatus = "off";
setTimeout(() => {
print(timeToString(elapsedTime));
RstBtn.removeAttribute("style");
PPbtn.removeAttribute("style");
PPbtn.innerText="Start";
PPbtn.innerText = "Start";
StpBtn.removeAttribute("style");
}, 80);
}

function settimer() {
mainscreen.style.display="none";
setscreen.style.display="none";
timerscreen.style.display="grid";
mainscreen.style.display = "none";
setscreen.style.display = "none";
timerscreen.style.display = "grid";
}

function togglerunnin() {

if (runninstatus == "timerpaused" || runninstatus == "crnpaused" || runninstatus == "off") {
if (
runninstatus == "timerpaused" ||
runninstatus == "crnpaused" ||
runninstatus == "off"
) {
start();
}
else {
} else {
pause();
}
}

function getformdata() {
timerval= timerinputelmnt.value*1000*60;
runninstatus="timerpaused";
c(timerval);
print(timeToString(timerval));
clearInterval(timerInterval);
mainscreenshow();
reset();
setTimeout(() => {
timerval = timerinputelmnt.value * 1000 * 60;
runninstatus = "timerpaused";
c(timerval);
print(timeToString(timerval));
mainscreenshow();
}, 100);
}

function timeEnded() {
stop();
document.getElementById("timeended").loop = true;
document.getElementById("timeended").loop = true;
display.style.color = "#fc2149";
display.innerText = "END";
display.style.textShadow = "none";
document.getElementById("timeended").play();

}

function stop() {
Expand All @@ -271,7 +266,7 @@ function stop() {
RstBtn.style.width = "50%";
PPbtn.style.display = "none";
StpBtn.style.display = "none";
};
}

efftgl.onclick = async function () {
console.log("hello");
Expand Down Expand Up @@ -317,9 +312,8 @@ mstoggle.onclick = async function () {
printbig("Applying", 600);
setTimeout(() => {
getprefs();
updateinterval = 10;
}, 500);


}
if (PREFDATA.showms == true) {
await Neutralino.storage.putData({
Expand All @@ -332,6 +326,8 @@ mstoggle.onclick = async function () {
printbig("Applying", 600);
setTimeout(() => {
getprefs();
updateinterval = 1000;

}, 500);
}
};

0 comments on commit ec99515

Please sign in to comment.