Skip to content

Commit 71d4e2b

Browse files
Disable Closing App While Recording
- If you click the top right close button by accident it won't close. Timer must be inactive to close the app
1 parent 18d0a94 commit 71d4e2b

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const appDataPath = app.getPath('userData');
88
const optionsFile = `${appDataPath}\\options.json`;
99
const db = new sqlite3.Database(`${appDataPath}/database.db`);
1010

11+
let isClockActive = false;
12+
1113
db.run(`
1214
CREATE TABLE IF NOT EXISTS topics (
1315
id INTEGER PRIMARY KEY,
@@ -81,6 +83,14 @@ const createWindow = async () => {
8183
}
8284
});
8385

86+
mainWindow.on('close', (event) => {
87+
if (isClockActive){
88+
event.preventDefault();
89+
} else {
90+
app.quit();
91+
}
92+
});
93+
8494
if (!fs.existsSync(optionsFile)){
8595
await saveOptions('Daily', 1, 0);
8696
}
@@ -114,6 +124,10 @@ app.on('activate', () => {
114124
}
115125
});
116126

127+
ipcMain.handle('toggle-clock-active', () => {
128+
isClockActive = !isClockActive;
129+
});
130+
117131
autoUpdater.on('checking-for-update', () => {
118132
mainWindow.webContents.send('auto-updater-callback', 'Checking for Update');
119133
});

src/preload.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ contextBridge.exposeInMainWorld('api', {
1313
graphCompareHandler: (data) => ipcRenderer.invoke('graph-compare-handler', data),
1414
optionsHandler: (data) => ipcRenderer.invoke('options-handler', data),
1515
progressBarHandler: (data) => ipcRenderer.invoke('progress-bar-handler', data),
16+
17+
toggleClockActive: () => ipcRenderer.invoke('toggle-clock-active'),
1618
});
1719

1820
contextBridge.exposeInMainWorld('autoUpdater', {

src/timer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function startTimer(){
4040
logStartTime = Date.now();
4141
timerInterval = setInterval(updateTimer, 10);
4242
toggleInputsDiv();
43+
api.toggleClockActive();
4344
}
4445

4546
async function stopTimer(){
@@ -58,6 +59,7 @@ async function stopTimer(){
5859
await populateAnnualGraph('All');
5960
await populateWeeklyCompareGraph('All');
6061
await progressBar();
62+
api.toggleClockActive();
6163
}
6264

6365
function updateTimer(){

0 commit comments

Comments
 (0)