Skip to content

Commit

Permalink
Switched to migrating function of electron-store
Browse files Browse the repository at this point in the history
  • Loading branch information
ransome1 committed Oct 31, 2023
1 parent 81c70d3 commit af6f18c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 59 deletions.
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
95 changes: 44 additions & 51 deletions src/main/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConfigData>({
cwd: userDataDirectory,
Expand All @@ -72,6 +25,50 @@ const configStorage = new Store<ConfigData>({
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);
},
Expand All @@ -80,10 +77,6 @@ const configStorage = new Store<ConfigData>({
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));
Expand Down
4 changes: 3 additions & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'),
},
Expand Down

0 comments on commit af6f18c

Please sign in to comment.