From af6f18c5d7f4c8c156c36bbe9447d8036e5977bf Mon Sep 17 00:00:00 2001 From: ransome1 Date: Tue, 31 Oct 2023 22:44:44 +0100 Subject: [PATCH] Switched to migrating function of electron-store --- package.json | 12 +++--- src/main/config.tsx | 95 +++++++++++++++++++++------------------------ src/main/main.ts | 4 +- 3 files changed, 52 insertions(+), 59 deletions(-) diff --git a/package.json b/package.json index 85c6a4e0..bc664131 100644 --- a/package.json +++ b/package.json @@ -6,21 +6,19 @@ "build:dll": "cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.renderer.dev.dll.ts", "build:main": "cross-env NODE_ENV=production TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.main.prod.ts", "build:renderer": "cross-env NODE_ENV=production TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.renderer.prod.ts", - "postinstall": "ts-node .erb/scripts/check-native-dep.js && electron-builder install-app-deps && npm run build:dll", + "postinstall": "ts-node .erb/scripts/check-native-dep.js && electron-builder install-app-deps && yarn run build:dll", "lint": "cross-env NODE_ENV=development eslint . --ext .js,.jsx,.ts,.tsx", "package": "ts-node ./.erb/scripts/clean.js dist && yarn run build && electron-builder build --publish never && yarn run build:dll", - "dir": "ts-node ./.erb/scripts/clean.js dist && yarn run build && electron-builder --dir --publish never && yarn run build:dll", - "mac": "ts-node ./.erb/scripts/clean.js dist && yarn run build && electron-builder build -m --arm64 --publish never && yarn run build:dll", - "mas": "ts-node ./.erb/scripts/clean.js dist && yarn run build && electron-builder build -m mas --universal --publish never && yarn run build:dll", - "masDev": "ts-node ./.erb/scripts/clean.js dist && yarn run build && electron-builder build -m 'mas-dev' --arm64 --publish never && yarn run build:dll", - "appimage": "ts-node ./.erb/scripts/clean.js dist && yarn run build && electron-builder build -l appimage --universal --publish never && yarn run build:dll", - "peggy": "peggy --format es --output ./src/main/modules/FilterLang/FilterLang.js ./src/main/modules/FilterLang/FilterLang.pegjs", "rebuild": "electron-rebuild --parallel --types prod,dev,optional --module-dir release/app", "start": "ts-node ./.erb/scripts/check-port-in-use.js && yarn run start:renderer", "start:main": "cross-env NODE_ENV=development electronmon -r ts-node/register/transpile-only .", "start:preload": "cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.preload.dev.ts", "start:renderer": "cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack serve --config ./.erb/configs/webpack.config.renderer.dev.ts", "test": "jest", + "mac": "cross-env NODE_ENV=production yarn run build && electron-builder build -m --arm64 --publish never", + "mas": "cross-env NODE_ENV=production yarn run build && electron-builder build -m mas --universal --publish never", + "dir": "cross-env NODE_ENV=production yarn run build && electron-builder --dir --publish never", + "peggy": "peggy --format es --output ./src/main/modules/FilterLang/FilterLang.js ./src/main/modules/FilterLang/FilterLang.pegjs", "depcheck": "depcheck" }, "browserslist": [], diff --git a/src/main/config.tsx b/src/main/config.tsx index 2ccba7a1..81e7e30b 100644 --- a/src/main/config.tsx +++ b/src/main/config.tsx @@ -17,53 +17,6 @@ if (!fs.existsSync(userDataDirectory)) fs.mkdirSync(userDataDirectory) console.log('config.ts: sleek userdata is located at: ' + userDataDirectory); const customStylesPath = path.join(userDataDirectory, 'customStyles.css'); - -const defaultConfigData = { - sorting: [ - { id: '1', value: 'priority', invert: false }, - { id: '2', value: 'projects', invert: false }, - { id: '3', value: 'contexts', invert: false }, - { id: '4', value: 'due', invert: false }, - { id: '5', value: 't', invert: false }, - { id: '6', value: 'completed', invert: false }, - { id: '7', value: 'created', invert: false }, - { id: '8', value: 'rec', invert: false }, - { id: '9', value: 'pm', invert: false }, - ], - accordionOpenState: [ - true, - true, - true, - false, - false, - false, - false, - false, - false - ], - files: [], - appendCreationDate: false, - showCompleted: true, - showHidden: false, - windowMaximized: false, - fileSorting: false, - convertRelativeToAbsoluteDates: true, - thresholdDateInTheFuture: true, - dueDateInTheFuture: true, - colorTheme: 'system', - shouldUseDarkColors: false, - notificationsAllowed: true, - notificationThreshold: 2, - showFileTabs: true, - isNavigationOpen: true, - customStylesPath: customStylesPath, - tray: false, - zoom: 100, - multilineTextField: false, - useMultilineForBulkTodoCreation: false, - matomo: true, -}; - const configPath = path.join(userDataDirectory, 'config.json'); const configStorage = new Store({ cwd: userDataDirectory, @@ -72,6 +25,50 @@ const configStorage = new Store({ console.log(`[config.json] migrating from ${context.fromVersion} → ${context.toVersion}`); }, migrations: { + '2.0.0': store => { + store.set('sorting', [ + { id: '1', value: 'priority', invert: false }, + { id: '2', value: 'projects', invert: false }, + { id: '3', value: 'contexts', invert: false }, + { id: '4', value: 'due', invert: false }, + { id: '5', value: 't', invert: false }, + { id: '6', value: 'completed', invert: false }, + { id: '7', value: 'created', invert: false }, + { id: '8', value: 'rec', invert: false }, + { id: '9', value: 'pm', invert: false }, + ]); + store.set('accordionOpenState', [ + true, + true, + true, + false, + false, + false, + false, + false, + false + ]); + store.set('files', []); + store.set('appendCreationDate', false); + store.set('showCompleted', true); + store.set('showHidden', false); + store.set('windowMaximized', false); + store.set('fileSorting', false); + store.set('convertRelativeToAbsoluteDates', true); + store.set('thresholdDateInTheFuture', true); + store.set('colorTheme', 'system'); + store.set('shouldUseDarkColors', false); + store.set('notificationsAllowed', true); + store.set('notificationThreshold', 2); + store.set('showFileTabs', true); + store.set('isNavigationOpen', true); + store.set('customStylesPath', customStylesPath); + store.set('tray', false); + store.set('zoom', 100); + store.set('multilineTextField', false); + store.set('useMultilineForBulkTodoCreation', false); + store.set('matomo', true); + }, '2.0.1': store => { store.set('anonymousUserId', anonymousUserId); }, @@ -80,10 +77,6 @@ const configStorage = new Store({ const filtersPath = path.join(userDataDirectory, 'filters.json'); const filterStorage = new Store<{}>({ cwd: userDataDirectory, name: 'filters' }); -if (!fs.existsSync(configPath)) { - fs.writeFileSync(configPath, JSON.stringify(defaultConfigData, null, 2)); -} - if (!fs.existsSync(filtersPath)) { const defaultFilterData = {}; fs.writeFileSync(filtersPath, JSON.stringify(defaultFilterData)); diff --git a/src/main/main.ts b/src/main/main.ts index fcd76a46..401d8a93 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -9,6 +9,8 @@ import createTray from './modules/Tray'; import './modules/Ipc'; import handleTheme from './modules/Theme'; +const environment = process.env.NODE_ENV; + const files: File[] = (configStorage.get('files') as File[]) || []; let mainWindow: BrowserWindow | null = null; @@ -78,7 +80,7 @@ const createWindow = async() => { webPreferences: { contextIsolation: true, nodeIntegration: false, - preload: app.isPackaged + preload: environment === 'production' ? path.join(__dirname, 'preload.js') : path.join(__dirname, '../../.erb/dll/preload.ts'), },