Skip to content

Commit 89fe830

Browse files
committed
fix mini mode non-stoppable
1 parent 5a07d7a commit 89fe830

3 files changed

Lines changed: 122 additions & 15 deletions

File tree

floating.html

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
<script src="supporter.js"></script>
1919
<div class="d-flex mx-auto justify-content-center align-items-center text-dark" id="main">
2020
<div id="floating-container" class="justify-content-center align-content-center text-center">
21-
<div id="floating-unhover">
21+
<div id="floating-unhover" style="pointer-events: none;">
2222
<div id="time-left" class="text-center h6 work">--</div>
2323
<div id="time-left-msg" class="text-center small work">
2424
<script>document.write(i18n.__('min-left'));</script>
2525
</div>
2626
</div>
2727
<div id="floating-hover" onmouseover="hover()" onmouseleave="unhover()" ontouchstart="semihover()">
28-
<div class="small" id="floating-stopper">
28+
<div class="small" id="floating-stopper" style="margin-top: 8px;">
2929
<a id="stopper" href="javascript:stopper()" class="text-muted" draggable="false">
3030
<i class="iconfont icon-pause"></i>
3131
</a>
@@ -77,10 +77,33 @@
7777
hover();
7878
}
7979

80-
let isWorking = true;
80+
let isWorking = null;
81+
let stopSyncPending = false;
82+
let desiredWorking = null;
83+
let lastMessageWorking = null;
84+
let lastActionAt = 0;
85+
86+
function renderStopperIcon(working) {
87+
if (working) {
88+
$("#stopper").html("<i class='iconfont icon-pause' aria-hidden='true'></i>");
89+
} else {
90+
$("#stopper").html("<i class='iconfont icon-play' aria-hidden='true'></i>");
91+
}
92+
}
8193

8294
function stopper() {
83-
ipc.send("floating-conversation", { topic: "stop" });
95+
let baseWorking = lastMessageWorking;
96+
if (baseWorking === null) baseWorking = isWorking;
97+
if (baseWorking === null) {
98+
return;
99+
}
100+
101+
desiredWorking = !baseWorking;
102+
isWorking = desiredWorking;
103+
lastActionAt = Date.now();
104+
stopSyncPending = true;
105+
renderStopperIcon(isWorking);
106+
ipc.send("floating-conversation", { topic: "stop-set", desiredWorking: desiredWorking });
84107
}
85108

86109
function skipper() {
@@ -133,9 +156,23 @@
133156

134157
let method = 1;
135158
ipc.on("floating-time-left", function (event, message) {
136-
isWorking = message.isWorking;
137-
if (isWorking) $("#stopper").html("<i class='iconfont icon-pause' aria-hidden='true'></i>");
138-
else $("#stopper").html("<i class='iconfont icon-play' aria-hidden='true'></i>");
159+
let messageWorking = !!message.isWorking;
160+
lastMessageWorking = messageWorking;
161+
let now = Date.now();
162+
if (stopSyncPending) {
163+
if (messageWorking === desiredWorking) {
164+
stopSyncPending = false;
165+
isWorking = messageWorking;
166+
renderStopperIcon(isWorking);
167+
} else if (now - lastActionAt > 800) {
168+
stopSyncPending = false;
169+
isWorking = messageWorking;
170+
renderStopperIcon(isWorking);
171+
}
172+
} else if (now - lastActionAt > 200) {
173+
isWorking = messageWorking;
174+
renderStopperIcon(isWorking);
175+
}
139176

140177
timeLeft.text(getStyledTimeLeft(message.minute));
141178
floatingBottomBar.css("width", message.percentage + "%");
@@ -213,9 +250,10 @@
213250
});
214251

215252
ipc.on("floating-stop-sync", function (event, message) {
216-
isWorking = message;
217-
if (isWorking) $("#stopper").html("<i class='iconfont icon-pause' aria-hidden='true'></i>");
218-
else $("#stopper").html("<i class='iconfont icon-play' aria-hidden='true'></i>");
253+
stopSyncPending = false;
254+
desiredWorking = !!message;
255+
isWorking = desiredWorking;
256+
renderStopperIcon(isWorking);
219257
});
220258

221259
if (process.platform === "darwin") {

main.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2364,7 +2364,10 @@ function startFloatingHeartbeat() {
23642364
if (floatingHeartbeatInterval != null) return;
23652365
floatingHeartbeatInterval = setInterval(function () {
23662366
if (floatingWin == null || floatingHeartbeat == null) return;
2367-
let elapsedSeconds = (Date.now() - floatingHeartbeat.timestamp) / 1000;
2367+
let elapsedSeconds = 0;
2368+
if (floatingHeartbeat.isWorking) {
2369+
elapsedSeconds = (Date.now() - floatingHeartbeat.timestamp) / 1000;
2370+
}
23682371
let remainingSeconds = floatingHeartbeat.remainingSeconds - elapsedSeconds;
23692372
if (remainingSeconds < 0) remainingSeconds = 0;
23702373
let percentage = 0;
@@ -2641,6 +2644,13 @@ ipcMain.on("floating-conversation", function (event, message) {
26412644
});
26422645
} else if (message.topic === "stop") {
26432646
if (win != null) win.webContents.send('remote-control-msg', 'stop');
2647+
} else if (message.topic === "stop-set") {
2648+
if (win != null) {
2649+
win.webContents.send('remote-control-msg', {
2650+
type: "stop-set",
2651+
desiredWorking: message.desiredWorking
2652+
});
2653+
}
26442654
} else if (message.topic === "skip") {
26452655
if (win != null) win.webContents.send('remote-control-msg', 'skipper');
26462656
} else if (message.topic === "recover") {

timer.html

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,14 @@ <h3>
380380

381381
// Send immediate heartbeat first to prevent freeze at zero
382382
if (methodFromStart !== 3) {
383-
let remainingMs = ((method === 1) ? workTime : restTime) - new Date().getTime() + startTime -
384-
(times === 0 ? firstTimeDiscount : 0);
383+
let remainingMs;
384+
if (!isClockWorking) {
385+
// When paused, use the stored time values to avoid time drift
386+
remainingMs = (hours * 3600 + minutes * 60 + seconds) * 1000;
387+
} else {
388+
remainingMs = ((method === 1) ? workTime : restTime) - new Date().getTime() + startTime -
389+
(times === 0 ? firstTimeDiscount : 0);
390+
}
385391
if (remainingMs < 0) remainingMs = 0;
386392
ipc.send("floating-heartbeat", {
387393
remainingSeconds: Math.floor(remainingMs / 1000),
@@ -404,8 +410,14 @@ <h3>
404410
if (methodFromStart !== 3)
405411
for (let floatingRepeater = 1; floatingRepeater < 5; floatingRepeater++)
406412
setTimeout(function () {
407-
let remainingMs = ((method === 1) ? workTime : restTime) - new Date().getTime() + startTime -
408-
(times === 0 ? firstTimeDiscount : 0);
413+
let remainingMs;
414+
if (!isClockWorking) {
415+
// When paused, use the stored time values to avoid time drift
416+
remainingMs = (hours * 3600 + minutes * 60 + seconds) * 1000;
417+
} else {
418+
remainingMs = ((method === 1) ? workTime : restTime) - new Date().getTime() + startTime -
419+
(times === 0 ? firstTimeDiscount : 0);
420+
}
409421
if (remainingMs < 0) remainingMs = 0;
410422
ipc.send("floating-heartbeat", {
411423
remainingSeconds: Math.floor(remainingMs / 1000),
@@ -848,6 +860,15 @@ <h3>
848860
ipc.on('remote-control-msg', function (event, message) {
849861
if (hasSoonFinishTipPosted) return;// ban stopping after tip posted
850862

863+
if (message && typeof message === "object" && message.type === "stop-set") {
864+
let desiredWorking = !!message.desiredWorking;
865+
if ((desiredWorking && !isClockWorking) || (!desiredWorking && isClockWorking)) {
866+
stopper();
867+
}
868+
ipc.send("floating-conversation", { topic: "stop-sync", val: isClockWorking });
869+
return;
870+
}
871+
851872
if (message === "skipper") skipper();
852873
else if (message === "back") {
853874
if (methodFromStart === 3 || ((!store.get("islocked")) && (!isFeatureDisabled(store.get('disable-backing'), method))))
@@ -903,6 +924,25 @@ <h3>
903924
msg: i18n.__('alarm-for-not-using-wnr-dialog-box-content')
904925
});
905926
}, 600000);
927+
if (hasFloating) {
928+
if (methodFromStart === 3) {
929+
ipc.send("floating-heartbeat", {
930+
remainingSeconds: hours * 3600 + minutes * 60 + seconds,
931+
totalMs: 0,
932+
method: 3,
933+
isWorking: isClockWorking,
934+
isOnlyRest: isOnlyRest
935+
});
936+
} else {
937+
ipc.send("floating-heartbeat", {
938+
remainingSeconds: hours * 3600 + minutes * 60 + seconds,
939+
totalMs: (method === 1) ? workTime : restTime,
940+
method: method,
941+
isWorking: isClockWorking,
942+
isOnlyRest: isOnlyRest
943+
});
944+
}
945+
}
906946
} else {
907947
if (pauseInt != null)
908948
window.clearTimeout(pauseInt);
@@ -918,6 +958,25 @@ <h3>
918958
isClockWorking = 1;//to restart
919959
ipc.send("tray-image-change", "start");
920960
if (pausingTimeout) window.clearInterval(pausingTimeout);
961+
if (hasFloating) {
962+
if (methodFromStart === 3) {
963+
ipc.send("floating-heartbeat", {
964+
remainingSeconds: hours * 3600 + minutes * 60 + seconds,
965+
totalMs: 0,
966+
method: 3,
967+
isWorking: isClockWorking,
968+
isOnlyRest: isOnlyRest
969+
});
970+
} else {
971+
ipc.send("floating-heartbeat", {
972+
remainingSeconds: hours * 3600 + minutes * 60 + seconds,
973+
totalMs: (method === 1) ? workTime : restTime,
974+
method: method,
975+
isWorking: isClockWorking,
976+
isOnlyRest: isOnlyRest
977+
});
978+
}
979+
}
921980
}
922981
}
923982

0 commit comments

Comments
 (0)