Skip to content

Commit 0078146

Browse files
committed
fix mini-mode non-stop and non-sync
- main reason: bad electron new upd - and also: need to optimize to use main.js thread as a mediator
1 parent d621e42 commit 0078146

4 files changed

Lines changed: 99 additions & 51 deletions

File tree

main.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ let win = null, settingsWin = null, aboutWin = null, tourWin = null, floatingWin
3535
store = null, styleCache = null, statistics = null, timingData = null, recapStore = null,
3636
personalizationNotificationList = [[], [], [], [], [], []],
3737
isMultiMonitorLoose = false;
38+
let floatingHeartbeat = null;
39+
let floatingHeartbeatInterval = null;
3840

3941
let months = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
4042
let languageCodeList = ['en', 'zh-CN', 'zh-TW'], i//locale code
@@ -2357,6 +2359,33 @@ function externalTitle(title, notes) {
23572359
}
23582360
}
23592361

2362+
function startFloatingHeartbeat() {
2363+
if (floatingHeartbeatInterval != null) return;
2364+
floatingHeartbeatInterval = setInterval(function () {
2365+
if (floatingWin == null || floatingHeartbeat == null) return;
2366+
let elapsedSeconds = (Date.now() - floatingHeartbeat.timestamp) / 1000;
2367+
let remainingSeconds = floatingHeartbeat.remainingSeconds - elapsedSeconds;
2368+
if (remainingSeconds < 0) remainingSeconds = 0;
2369+
let percentage = 0;
2370+
if (floatingHeartbeat.totalMs > 0) {
2371+
percentage = Math.round((remainingSeconds * 1000 / floatingHeartbeat.totalMs) * 100);
2372+
}
2373+
floatingWin.webContents.send('floating-time-left', {
2374+
minute: remainingSeconds / 60,
2375+
percentage: percentage,
2376+
method: floatingHeartbeat.method,
2377+
isWorking: floatingHeartbeat.isWorking,
2378+
isOnlyRest: floatingHeartbeat.isOnlyRest
2379+
});
2380+
}, 250);
2381+
}
2382+
2383+
function stopFloatingHeartbeat() {
2384+
if (floatingHeartbeatInterval == null) return;
2385+
clearInterval(floatingHeartbeatInterval);
2386+
floatingHeartbeatInterval = null;
2387+
}
2388+
23602389
function floating() {
23612390
if (styleCache.has("floating-axis")) {
23622391
// fix that floating window may be out of screen after changing screen resolution
@@ -2405,10 +2434,12 @@ function floating() {
24052434
floatingWin.show();
24062435
floatingWin.setAlwaysOnTop(true, "pop-up-menu");
24072436
floatingWin.focus();
2437+
startFloatingHeartbeat();
24082438
});
24092439
floatingWin.on('closed', () => {
24102440
floatingWin = null;
24112441
hasFloating = false;
2442+
stopFloatingHeartbeat();
24122443
// no longer need this
24132444
/*if (win != null && process.platform === "darwin"){
24142445
win.show();
@@ -2582,6 +2613,22 @@ ipcMain.on("timer-win", function (event, message) {
25822613
}
25832614
})
25842615

2616+
ipcMain.on("floating-heartbeat", function (event, message) {
2617+
if (message == null) return;
2618+
let remainingSeconds = Number(message.remainingSeconds);
2619+
let totalMs = Number(message.totalMs);
2620+
if (!Number.isFinite(remainingSeconds)) return;
2621+
if (!Number.isFinite(totalMs)) totalMs = 0;
2622+
floatingHeartbeat = {
2623+
remainingSeconds: remainingSeconds,
2624+
totalMs: totalMs,
2625+
method: message.method,
2626+
isWorking: message.isWorking,
2627+
isOnlyRest: message.isOnlyRest,
2628+
timestamp: Date.now()
2629+
};
2630+
});
2631+
25852632
ipcMain.on("floating-conversation", function (event, message) {
25862633
if (message.topic === "time-left") {
25872634
if (floatingWin != null) floatingWin.webContents.send('floating-time-left', {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
},
5050
"devDependencies": {
5151
"cross-env": "10.1.0",
52-
"electron": "37.6.0",
52+
"electron": "22.3.27",
5353
"electron-builder": "26.0.12"
5454
}
5555
}

timer.html

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,12 @@ <h3>
382382
if (methodFromStart !== 3)
383383
for (let floatingRepeater = 1; floatingRepeater < 5; floatingRepeater++)
384384
setTimeout(function () {
385-
ipc.send("floating-conversation", {
386-
topic: "time-left",
387-
val: (((method === 1) ? workTime : restTime) - new Date().getTime() + startTime -
388-
(times === 0 ? firstTimeDiscount : 0)) / 60000,
389-
percentage: Math.round(lastRecordedProgress * 100),
385+
let remainingMs = ((method === 1) ? workTime : restTime) - new Date().getTime() + startTime -
386+
(times === 0 ? firstTimeDiscount : 0);
387+
if (remainingMs < 0) remainingMs = 0;
388+
ipc.send("floating-heartbeat", {
389+
remainingSeconds: Math.floor(remainingMs / 1000),
390+
totalMs: (method === 1) ? workTime : restTime,
390391
method: method,
391392
isWorking: isClockWorking,
392393
isOnlyRest: isOnlyRest
@@ -395,12 +396,12 @@ <h3>
395396
else
396397
for (let floatingRepeater = 1; floatingRepeater < 5; floatingRepeater++)
397398
setTimeout(function () {
398-
ipc.send("floating-conversation", {
399-
topic: "time-left",
400-
val: seconds / 60,
401-
percentage: 0,
399+
ipc.send("floating-heartbeat", {
400+
remainingSeconds: seconds,
401+
totalMs: 0,
402402
method: 3,
403-
isWorking: isClockWorking
403+
isWorking: isClockWorking,
404+
isOnlyRest: isOnlyRest
404405
})
405406
}, 500 * floatingRepeater);
406407
}
@@ -719,6 +720,8 @@ <h3>
719720
lastRecordedRemain = -1,
720721
lastRecordedSecond = -1,
721722
lastRecordedProgress = 0.00,
723+
naturalProgress = 0.00,
724+
lastFloatingSecond = -1,
722725
wasCounting = true,
723726
shouldNap,
724727
napInterval = 0,
@@ -867,7 +870,7 @@ <h3>
867870
}
868871
if ((method === 1 && workTime > 60000) || (method === 2 && restTime > 60000)) moreThanOneMin = 1;
869872
else moreThanOneMin = 0;//if less than 1 min, prevent less than 1min warning
870-
lastRecordedMinutesLeft = -1, lastRecordedHoursLeft = -1, lastRecordedProgress = 0.00, lastRecordedSecond = -1;
873+
lastRecordedMinutesLeft = -1, lastRecordedHoursLeft = -1, lastRecordedProgress = 0.00, lastRecordedSecond = -1, lastFloatingSecond = -1;
871874
canStop = false;
872875
timingData.set("last-recorded-minutes-left", -1);
873876
timingData.set("last-recorded-hours-left", -1);
@@ -1042,9 +1045,9 @@ <h3>
10421045
} else {
10431046
if (hasFloating) {
10441047
floatingOpener();
1045-
if (!isFeatureDisabled(store.get('disable-skipping'), 2)) {
1046-
$("#skipper-container").css("display", "inline");
1047-
}
1048+
if (!isFeatureDisabled(store.get('disable-skipping'), 2)) {
1049+
$("#skipper-container").css("display", "inline");
1050+
}
10481051
}
10491052

10501053
if (workTimeFocused === true) {
@@ -1294,12 +1297,12 @@ <h3>
12941297
hours = Math.floor(seconds / 3600);
12951298
minutes = Math.floor((seconds - hours * 3600) / 60);
12961299

1297-
if (hasFloating) ipc.send("floating-conversation", {
1298-
topic: "time-left",
1299-
val: seconds / 60,
1300-
percentage: 0,
1300+
if (hasFloating) ipc.send("floating-heartbeat", {
1301+
remainingSeconds: seconds,
1302+
totalMs: 0,
13011303
method: 3,
1302-
isWorking: isClockWorking
1304+
isWorking: isClockWorking,
1305+
isOnlyRest: isOnlyRest
13031306
});
13041307

13051308
if (lastTimePositiveMinutes !== minutes) {
@@ -1352,37 +1355,28 @@ <h3>
13521355
minutes = Math.floor((seconds - hours * 3600) / 60);
13531356
remainMinutes = hours * 60 + minutes;
13541357

1358+
naturalProgress = Math.round(Number(progress) * 100);
13551359
if (progress !== lastRecordedProgress) {
13561360
lastRecordedProgress = progress;
1357-
naturalProgress = Math.round(lastRecordedProgress * 100);
1358-
$bottomBar.css("width", naturalProgress + "%");
13591361
ipc.send("progress-bar-set", {
13601362
progress: progress,
13611363
remain: minutes + hours * 60,
13621364
positive: false
13631365
});
1364-
if (hasFloating && !(hours === 0 && minutes === 0)) {
1365-
ipc.send("floating-conversation", {
1366-
topic: "time-left",
1367-
val: seconds / 60,
1368-
percentage: naturalProgress,
1369-
method: method,
1370-
isWorking: isClockWorking,
1371-
isOnlyRest: isOnlyRest
1372-
});
1373-
}
13741366
}
1375-
1376-
if (hours === 0 && minutes === 0 && (lastRecordedSecond !== seconds)) {
1377-
lastRecordedSecond = seconds;
1378-
if (hasFloating) ipc.send("floating-conversation", {
1379-
topic: "time-left",
1380-
val: seconds / 60,
1381-
percentage: naturalProgress,
1367+
if (hasFloating && seconds !== lastFloatingSecond) {
1368+
lastFloatingSecond = seconds;
1369+
$bottomBar.css("width", naturalProgress + "%");
1370+
ipc.send("floating-heartbeat", {
1371+
remainingSeconds: seconds,
1372+
totalMs: (method === 1) ? workTime : restTime,
13821373
method: method,
13831374
isWorking: isClockWorking,
13841375
isOnlyRest: isOnlyRest
13851376
});
1377+
if (seconds <= 0) {
1378+
skipper();
1379+
}
13861380
}
13871381

13881382
if (remainMinutes !== lastRecordedRemain) {
@@ -1442,6 +1436,15 @@ <h3>
14421436
}
14431437
}
14441438
} else {
1439+
if (hasFloating) {
1440+
ipc.send("floating-heartbeat", {
1441+
remainingSeconds: 0,
1442+
totalMs: (method === 1) ? workTime : restTime,
1443+
method: method,
1444+
isWorking: isClockWorking,
1445+
isOnlyRest: isOnlyRest
1446+
});
1447+
}
14451448
skipper();
14461449
}
14471450
}

yarn.lock

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,10 @@ __metadata:
438438
languageName: node
439439
linkType: hard
440440

441-
"@types/node@npm:^22.7.7":
442-
version: 22.18.6
443-
resolution: "@types/node@npm:22.18.6"
444-
dependencies:
445-
undici-types: ~6.21.0
446-
checksum: c200df1bc9abcfe79d4002f65cb96582dcd45ea10201e3bf070590a521ba50db0c3412e73aef425db7f395490f14f999e7cd5fbc1c3620a57d3d21ad67482c4d
441+
"@types/node@npm:^16.11.26":
442+
version: 16.18.126
443+
resolution: "@types/node@npm:16.18.126"
444+
checksum: 86112e7499f8a4d1bb60696cab0bf464adf3c141fca4bc5451e8f3aba5736529b76d4b4396edb21e5d7c19592852f7d6cb81ee70074fd13bde2db2d0db720467
447445
languageName: node
448446
linkType: hard
449447

@@ -1460,16 +1458,16 @@ __metadata:
14601458
languageName: node
14611459
linkType: hard
14621460

1463-
"electron@npm:37.6.0":
1464-
version: 37.6.0
1465-
resolution: "electron@npm:37.6.0"
1461+
"electron@npm:22.3.27":
1462+
version: 22.3.27
1463+
resolution: "electron@npm:22.3.27"
14661464
dependencies:
14671465
"@electron/get": ^2.0.0
1468-
"@types/node": ^22.7.7
1466+
"@types/node": ^16.11.26
14691467
extract-zip: ^2.0.1
14701468
bin:
14711469
electron: cli.js
1472-
checksum: c7effef7e64126427252da4772c2af5ab9f5d5322639abe2b841dc5354093d2040b5832aca91738bf9fc31caab30f55e8a2871763607a76e53131d999f71ec24
1470+
checksum: b9c5ad263c45065b42f612931de95e0e29f9e735d4f47f51298700788492e6a107d72f4982d421afc71f25364660579d5d15061f8198211ac9d507372ca8bbe1
14731471
languageName: node
14741472
linkType: hard
14751473

@@ -3914,7 +3912,7 @@ __metadata:
39143912
copy-to-clipboard: 3.3.3
39153913
cross-env: 10.1.0
39163914
crypto-js: 4.2.0
3917-
electron: 37.6.0
3915+
electron: 22.3.27
39183916
electron-builder: 26.0.12
39193917
electron-debug: 3.2.0
39203918
electron-store: 8.2.0

0 commit comments

Comments
 (0)