Skip to content

Commit

Permalink
Fix reminder notification bugs, make user settings persist across ses…
Browse files Browse the repository at this point in the history
…sions
  • Loading branch information
cassidoo committed Feb 24, 2020
1 parent 2a1922c commit dc57564
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"dependencies": {
"@reach/accordion": "^0.8.0",
"date-fns": "^2.9.0",
"electron-is-dev": "^1.1.0"
"electron-is-dev": "^1.1.0",
"electron-store": "^5.1.0"
},
"devDependencies": {
"@rescripts/cli": "^0.0.13",
Expand All @@ -73,7 +74,7 @@
"node-sass": "^4.13.1",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-scripts": "3.3.0",
"react-scripts": "3.4.0",
"wait-on": "^4.0.0"
}
}
57 changes: 42 additions & 15 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ const {
powerMonitor,
shell
} = require("electron");
const Store = require("electron-store");
const isDev = require("electron-is-dev");

const path = require("path");
const { version } = require("../package.json");
const isDev = require("electron-is-dev");

const store = new Store();

global.notificationSettings = {
resetNotification: store.get("reset") || true,
reminderNotification: store.get("reminder") || "hour"
};

let mainWindow = {
show: () => {
Expand Down Expand Up @@ -65,13 +73,13 @@ function menuSetup() {
{
type: "separator"
},
{
/* For debugging */
label: "Dev tools",
click: () => {
mainWindow.webContents.openDevTools();
}
},
// {
// /* For debugging */
// label: "Dev tools",
// click: () => {
// mainWindow.webContents.openDevTools();
// }
// },
{
label: "Quit",
accelerator: "CommandOrControl+Q",
Expand All @@ -96,6 +104,17 @@ function menuSetup() {
{
label: "View",
submenu: [
// {
// label: "Light mode",
// type: "checkbox",
// checked: false,
// click: e => {
// mainWindow.isLightMode = e.checked;
// }
// },
{
type: "separator"
},
{ role: "reload" },
{ role: "togglefullscreen" },
{ role: "minimize" },
Expand All @@ -108,9 +127,10 @@ function menuSetup() {
{
label: "Enable reset notification",
type: "checkbox",
checked: true,
checked: store.get("reset"),
click: e => {
mainWindow.showResetNotification = e.checked;
mainWindow.resetNotification = e.checked;
store.set("reset", e.checked);
}
},
{
Expand All @@ -119,37 +139,44 @@ function menuSetup() {
{
label: "Never",
type: "radio",
checked: store.get("reminder") === "never",
click: e => {
if (e.checked) {
mainWindow.resetNotification = "never";
mainWindow.reminderNotification = "never";
store.set("reminder", "never");
}
}
},
{
label: "Every 15 minutes",
type: "radio",
checked: store.get("reminder") === "quarterhour",
click: e => {
if (e.checked) {
mainWindow.resetNotification = "quarterhour";
mainWindow.reminderNotification = "quarterhour";
store.set("reminder", "quarterhour");
}
}
},
{
label: "Every 30 minutes",
type: "radio",
checked: store.get("reminder") === "halfhour",
click: e => {
if (e.checked) {
mainWindow.resetNotification = "halfhour";
mainWindow.reminderNotification = "halfhour";
store.set("reminder", "halfhour");
}
}
},
{
label: "Every hour",
type: "radio",
checked: true,
checked: store.get("reminder") === "hour",
click: e => {
if (e.checked) {
mainWindow.resetNotification = "hour";
mainWindow.reminderNotification = "hour";
store.set("reminder", "hour");
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/hooks/useDateCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ export default function useDateCheck() {
let currentDate = parseISO(
`${format(nd, "y")}-${format(nd, "MM")}-${format(nd, "dd")}`
);
console.log(remote.getCurrentWindow());

if (isBefore(storedDate, currentDate)) {
if (remote.getCurrentWindow().showResetNotification) {
if (remote.getGlobal("notificationSettings").resetNotification) {
new Notification("todometer reset time!", {
body: "It's a new day! Your todos are being reset."
});
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useReminderNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useItems } from "../AppContext";
function getTimeCondition(nd) {
let condition = false;

switch (remote.getCurrentWindow().resetNotification) {
switch (remote.getGlobal("notificationSettings").reminderNotification) {
case "hour":
condition = nd.getMinutes() === 0 && nd.getSeconds() === 0;
break;
Expand Down

0 comments on commit dc57564

Please sign in to comment.