Skip to content

Commit dc57564

Browse files
committed
Fix reminder notification bugs, make user settings persist across sessions
1 parent 2a1922c commit dc57564

File tree

4 files changed

+47
-20
lines changed

4 files changed

+47
-20
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
"dependencies": {
6060
"@reach/accordion": "^0.8.0",
6161
"date-fns": "^2.9.0",
62-
"electron-is-dev": "^1.1.0"
62+
"electron-is-dev": "^1.1.0",
63+
"electron-store": "^5.1.0"
6364
},
6465
"devDependencies": {
6566
"@rescripts/cli": "^0.0.13",
@@ -73,7 +74,7 @@
7374
"node-sass": "^4.13.1",
7475
"react": "^16.12.0",
7576
"react-dom": "^16.12.0",
76-
"react-scripts": "3.3.0",
77+
"react-scripts": "3.4.0",
7778
"wait-on": "^4.0.0"
7879
}
7980
}

public/electron.js

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@ const {
66
powerMonitor,
77
shell
88
} = require("electron");
9+
const Store = require("electron-store");
10+
const isDev = require("electron-is-dev");
911

1012
const path = require("path");
1113
const { version } = require("../package.json");
12-
const isDev = require("electron-is-dev");
14+
15+
const store = new Store();
16+
17+
global.notificationSettings = {
18+
resetNotification: store.get("reset") || true,
19+
reminderNotification: store.get("reminder") || "hour"
20+
};
1321

1422
let mainWindow = {
1523
show: () => {
@@ -65,13 +73,13 @@ function menuSetup() {
6573
{
6674
type: "separator"
6775
},
68-
{
69-
/* For debugging */
70-
label: "Dev tools",
71-
click: () => {
72-
mainWindow.webContents.openDevTools();
73-
}
74-
},
76+
// {
77+
// /* For debugging */
78+
// label: "Dev tools",
79+
// click: () => {
80+
// mainWindow.webContents.openDevTools();
81+
// }
82+
// },
7583
{
7684
label: "Quit",
7785
accelerator: "CommandOrControl+Q",
@@ -96,6 +104,17 @@ function menuSetup() {
96104
{
97105
label: "View",
98106
submenu: [
107+
// {
108+
// label: "Light mode",
109+
// type: "checkbox",
110+
// checked: false,
111+
// click: e => {
112+
// mainWindow.isLightMode = e.checked;
113+
// }
114+
// },
115+
{
116+
type: "separator"
117+
},
99118
{ role: "reload" },
100119
{ role: "togglefullscreen" },
101120
{ role: "minimize" },
@@ -108,9 +127,10 @@ function menuSetup() {
108127
{
109128
label: "Enable reset notification",
110129
type: "checkbox",
111-
checked: true,
130+
checked: store.get("reset"),
112131
click: e => {
113-
mainWindow.showResetNotification = e.checked;
132+
mainWindow.resetNotification = e.checked;
133+
store.set("reset", e.checked);
114134
}
115135
},
116136
{
@@ -119,37 +139,44 @@ function menuSetup() {
119139
{
120140
label: "Never",
121141
type: "radio",
142+
checked: store.get("reminder") === "never",
122143
click: e => {
123144
if (e.checked) {
124-
mainWindow.resetNotification = "never";
145+
mainWindow.reminderNotification = "never";
146+
store.set("reminder", "never");
125147
}
126148
}
127149
},
128150
{
129151
label: "Every 15 minutes",
130152
type: "radio",
153+
checked: store.get("reminder") === "quarterhour",
131154
click: e => {
132155
if (e.checked) {
133-
mainWindow.resetNotification = "quarterhour";
156+
mainWindow.reminderNotification = "quarterhour";
157+
store.set("reminder", "quarterhour");
134158
}
135159
}
136160
},
137161
{
138162
label: "Every 30 minutes",
139163
type: "radio",
164+
checked: store.get("reminder") === "halfhour",
140165
click: e => {
141166
if (e.checked) {
142-
mainWindow.resetNotification = "halfhour";
167+
mainWindow.reminderNotification = "halfhour";
168+
store.set("reminder", "halfhour");
143169
}
144170
}
145171
},
146172
{
147173
label: "Every hour",
148174
type: "radio",
149-
checked: true,
175+
checked: store.get("reminder") === "hour",
150176
click: e => {
151177
if (e.checked) {
152-
mainWindow.resetNotification = "hour";
178+
mainWindow.reminderNotification = "hour";
179+
store.set("reminder", "hour");
153180
}
154181
}
155182
}

src/hooks/useDateCheck.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ export default function useDateCheck() {
1414
let currentDate = parseISO(
1515
`${format(nd, "y")}-${format(nd, "MM")}-${format(nd, "dd")}`
1616
);
17-
console.log(remote.getCurrentWindow());
1817

1918
if (isBefore(storedDate, currentDate)) {
20-
if (remote.getCurrentWindow().showResetNotification) {
19+
if (remote.getGlobal("notificationSettings").resetNotification) {
2120
new Notification("todometer reset time!", {
2221
body: "It's a new day! Your todos are being reset."
2322
});

src/hooks/useReminderNotification.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useItems } from "../AppContext";
55
function getTimeCondition(nd) {
66
let condition = false;
77

8-
switch (remote.getCurrentWindow().resetNotification) {
8+
switch (remote.getGlobal("notificationSettings").reminderNotification) {
99
case "hour":
1010
condition = nd.getMinutes() === 0 && nd.getSeconds() === 0;
1111
break;

0 commit comments

Comments
 (0)