Skip to content

Commit

Permalink
fix: javascript error on launch (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 authored Oct 2, 2023
1 parent 25403d7 commit c6c18fb
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 25 deletions.
19 changes: 8 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@

## [1.3.0](https://github.com/zidoro/pomatez/compare/v1.2.3...v1.3.0) (2023-09-26)


### Features ✨

* add support for open at login in the settings tab ([f57e133](https://github.com/zidoro/pomatez/commit/f57e1335d59938d95c6de4455b96aafcc8a878a2))
* increase maximum focus time to 2 hours ([#383](https://github.com/zidoro/pomatez/issues/383)) ([3fc1493](https://github.com/zidoro/pomatez/commit/3fc14937ee4b08e74390fbd36eb115278f55f179))

- add support for open at login in the settings tab ([f57e133](https://github.com/zidoro/pomatez/commit/f57e1335d59938d95c6de4455b96aafcc8a878a2))
- increase maximum focus time to 2 hours ([#383](https://github.com/zidoro/pomatez/issues/383)) ([3fc1493](https://github.com/zidoro/pomatez/commit/3fc14937ee4b08e74390fbd36eb115278f55f179))

### Bug Fixes 🐛

* compact mode layout broke with 120 minutes max timer config ([#393](https://github.com/zidoro/pomatez/issues/393)) ([c8c3c66](https://github.com/zidoro/pomatez/commit/c8c3c66460116aefe8a172b4237fa08b52583ffc))
* disable dragging for navigation links ([#387](https://github.com/zidoro/pomatez/issues/387)) ([a5b147f](https://github.com/zidoro/pomatez/commit/a5b147fbac812b2be6e92ce218841bfebe29d790))
* fix security issues ([bcbd65f](https://github.com/zidoro/pomatez/commit/bcbd65fa18d5f5531b20ab2ee0462b03ec766b5c)), closes [#407](https://github.com/zidoro/pomatez/issues/407)
* notification type selection issue in settings ([04ddca1](https://github.com/zidoro/pomatez/commit/04ddca16023bfea1b6496d41769ee7715700354d))
- compact mode layout broke with 120 minutes max timer config ([#393](https://github.com/zidoro/pomatez/issues/393)) ([c8c3c66](https://github.com/zidoro/pomatez/commit/c8c3c66460116aefe8a172b4237fa08b52583ffc))
- disable dragging for navigation links ([#387](https://github.com/zidoro/pomatez/issues/387)) ([a5b147f](https://github.com/zidoro/pomatez/commit/a5b147fbac812b2be6e92ce218841bfebe29d790))
- fix security issues ([bcbd65f](https://github.com/zidoro/pomatez/commit/bcbd65fa18d5f5531b20ab2ee0462b03ec766b5c)), closes [#407](https://github.com/zidoro/pomatez/issues/407)
- notification type selection issue in settings ([04ddca1](https://github.com/zidoro/pomatez/commit/04ddca16023bfea1b6496d41769ee7715700354d))

## [1.2.3](https://github.com/zidoro/pomatez/compare/v1.2.2...v1.2.3) (2023-05-03)


### Bug Fixes 🐛

* **app/renderer:** fix linter warnings that causes CI test build failing ([26edd59](https://github.com/zidoro/pomatez/commit/26edd59b26155954208fafc0dc3d933501c11bc9))
* Set Application Menu to Fix Mac Shortcuts ([0e6d47f](https://github.com/zidoro/pomatez/commit/0e6d47f0eb166256f914494518b4ea9e63160c06))
- **app/renderer:** fix linter warnings that causes CI test build failing ([26edd59](https://github.com/zidoro/pomatez/commit/26edd59b26155954208fafc0dc3d933501c11bc9))
- Set Application Menu to Fix Mac Shortcuts ([0e6d47f](https://github.com/zidoro/pomatez/commit/0e6d47f0eb166256f914494518b4ea9e63160c06))

## [1.2.2](https://github.com/zidoro/pomatez/compare/v1.2.1...v1.2.2) (2022-12-21)

Expand Down
2 changes: 1 addition & 1 deletion app/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"scripts": {
"prepare": "yarn build",
"clean": "rimraf dist/ build/",
"predev:main": "wait-on http://localhost:3000",
"predev:main": "wait-on http://127.0.0.1:3000",
"dev:main": "nodemon --exec \"yarn build && electron .\"",
"start": "yarn dev:main",
"build": "tsc && copyfiles -u 2 \"src/assets/*\" build/assets",
Expand Down
4 changes: 2 additions & 2 deletions app/main/src/helpers/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { v4 as uuid } from "uuid";

import store from "../store";

const userId = store.get("userId") || uuid();
const userId = store.safeGet("userId") || uuid();

store.set("userId", userId);
store.safeSet("userId", userId);

function activateUser() {
const user = ua("UA-172128342-2", userId);
Expand Down
18 changes: 10 additions & 8 deletions app/main/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const getFrameHeight = () => {
if (isWindow()) {
return 502;
} else {
if (store.get("useNativeTitlebar")) {
if (store.safeGet("useNativeTitlebar")) {
return 488;
}
return 502;
Expand All @@ -93,9 +93,9 @@ function createMainWindow() {
resizable: true,
maximizable: false,
show: false,
frame: store.get("useNativeTitlebar"),
frame: store.safeGet("useNativeTitlebar"),
icon: getIcon(),
backgroundColor: store.get("isDarkMode") ? "#141e25" : "#fff",
backgroundColor: store.safeGet("isDarkMode") ? "#141e25" : "#fff",
webPreferences: {
contextIsolation: true,
backgroundThrottling: false,
Expand Down Expand Up @@ -337,7 +337,9 @@ if (!onlySingleInstance) {
actions: ["View Released Notes"],
callback: (err, response) => {
if (!err) {
shell.openExternal(RELEASED_NOTES_LINK);
if (response === "view released notes") {
shell.openExternal(RELEASED_NOTES_LINK);
}
}
},
});
Expand Down Expand Up @@ -391,7 +393,7 @@ ipcMain.on(SET_COMPACT_MODE, (e, args) => {
});

ipcMain.on(SET_UI_THEME, (e, { isDarkMode }) => {
store.set("isDarkMode", isDarkMode);
store.safeSet("isDarkMode", isDarkMode);
});

ipcMain.on(SET_SHOW, () => {
Expand Down Expand Up @@ -425,8 +427,8 @@ ipcMain.on(SET_CLOSE, (e, { closeToTray }) => {
});

ipcMain.on(SET_NATIVE_TITLEBAR, (e, { useNativeTitlebar }) => {
if (store.get("useNativeTitlebar") !== useNativeTitlebar) {
store.set("useNativeTitlebar", useNativeTitlebar);
if (store.safeGet("useNativeTitlebar") !== useNativeTitlebar) {
store.safeSet("useNativeTitlebar", useNativeTitlebar);
setTimeout(() => {
app.relaunch();
app.exit();
Expand All @@ -440,7 +442,7 @@ ipcMain.on(TRAY_ICON_UPDATE, (e, dataUrl) => {
});

ipcMain.on(SET_OPEN_AT_LOGIN, (e, { openAtLogin }) => {
store.set("openAtLogin", openAtLogin);
store.safeSet("openAtLogin", openAtLogin);
app.setLoginItemSettings({
openAtLogin: openAtLogin,
openAsHidden: openAtLogin,
Expand Down
46 changes: 44 additions & 2 deletions app/main/src/store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Store from "electron-store";
import Store, { Options } from "electron-store";
import { nativeTheme } from "electron";
import { isWindow } from "./helpers";
import ElectronStore from "electron-store";

type StoreProps = {
userId?: string;
Expand All @@ -10,7 +11,48 @@ type StoreProps = {
openAtLogin?: boolean;
};

const store = new Store<StoreProps>({
/**
* Was going to make SafeStore extend Store but it didn't seem to work how it should. (Class constructor ElectronStore cannot be invoked without 'new')
*
* This also ensures that we can force calling the store safely. Though I have switched the names to safeGet and safeSet to make it more clear.
*/
class SafeStore<
T extends Record<string, any> = Record<string, unknown>,
> {
private store: ElectronStore<T>;
constructor(props: Options<T>) {
this.store = new Store<T>(props);
}

/**
* Safely set a value in the store and catch errors
* @param key
* @param value
*/
safeSet<Key extends keyof T>(key: Key, value?: T[Key]) {
try {
this.store.set(key, value);
} catch (error) {
console.error("[Store] Safe Set", error);
}
}

/**
* Safely get a value from the store and catch errors
* @param key
*/
safeGet<Key extends keyof T>(key: Key): T[Key] | undefined {
try {
return this.store.get(key);
} catch (error) {
console.error("[Store] Safe Get", error);
}
return undefined;
}
}

// Wrap the store due to a delete issue
const store = new SafeStore<StoreProps>({
defaults: {
isDarkMode: nativeTheme.shouldUseDarkColors,
useNativeTitlebar: !isWindow(),
Expand Down
4 changes: 3 additions & 1 deletion app/renderer/src/styles/routes/tasks/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ export const StyledCard = styled.div<CardProps>`
border-bottom-color: var(--color-border-input-secondary);
background-color: var(--color-bg-task-card);
transition: box-shadow 320ms ease-out, background-color 320ms ease-out,
:w transition:
box-shadow 320ms ease-out,
background-color 320ms ease-out,
border-color 320ms ease-out;
${(p) =>
Expand Down

0 comments on commit c6c18fb

Please sign in to comment.