Skip to content

Commit

Permalink
feat: remove electron-store and electron-settings
Browse files Browse the repository at this point in the history
  • Loading branch information
UrijHoruzij committed Jan 18, 2023
1 parent 278be73 commit 3e2b424
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 170 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
block_comment_start = /**
block_comment = *
block_comment_end = */

[*.md]
indent_size = 4
12 changes: 12 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"printWidth": 120,
"useTabs": true,
"semi":true,
"tabWidth": 2,
"singleQuote": true,
"jsxSingleQuote":false,
"trailingComma": "all",
"bracketSpacing": true,
"bracketSameLine": true,
"arrowParens": "always"
}
28 changes: 13 additions & 15 deletions main/background.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
const { app, ipcMain, dialog } = require('electron');
const serve = require('electron-serve');
const path = require('path');
const { autoUpdater } = require('electron-updater');
const isDev = require('electron-is-dev');
const settings = require('electron-settings');
const { upscayl, autoUpdate, createWindow } = require('./helpers/');
const { upscayl, autoUpdate, createWindow, store } = require('./helpers/');

if (isDev) {
require('electron-reload')(__dirname, {
Expand All @@ -21,21 +19,19 @@ let files = [];
let saveDirectory = [];
let flag = false;
app.on('ready', async () => {
const local = await settings.get('local.name');
if (!!!local) {
await settings.set('local', {
name: app.getLocaleCountryCode().toLowerCase(),
});
}
const settings = store({
configName: 'settings',
defaults: {
locale: app.getLocaleCountryCode().toLowerCase(),
},
});
ipcMain.handle('get-lang', async (e) => {
const lang = await settings.get('local.name');
const lang = await settings.get('locale');
return lang;
});
ipcMain.handle('set-lang', async (e, newLang) => {
await settings.set('local', {
name: newLang,
});
const lang = await settings.get('local.name');
await settings.set('locale', newLang);
const lang = await settings.get('locale');
return lang;
});
splashWindow = createWindow(
Expand Down Expand Up @@ -77,7 +73,9 @@ app.on('ready', async () => {
preload: path.join(__dirname, 'preload.js'),
},
});
// mainWindow.webContents.openDevTools();
if (isDev) {
mainWindow.webContents.openDevTools();
}
mainWindow.removeMenu();
mainWindow.once('ready-to-show', () => {
setTimeout(() => {
Expand Down
13 changes: 8 additions & 5 deletions main/helpers/createWindow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { screen, BrowserWindow } = require('electron');
const Store = require('electron-store');

const Store = require('./store.js');
const createWindow = (windowName, options, splash = false) => {
let win;
if (splash) {
Expand All @@ -9,15 +8,19 @@ const createWindow = (windowName, options, splash = false) => {
});
return win;
}
const store = Store({
configName: `window-state-${windowName}`,
defaults: {
windowBounds: { width: options.width, height: options.height },
},
});
let state = {};
const key = 'window-state';
const name = `window-state-${windowName}`;
const store = new Store({ name });
const defaultSize = {
width: options.width,
height: options.height,
};
const restore = () => store.get(key, defaultSize);
const restore = () => store.get(key);
const getCurrentPosition = () => {
const position = win.getPosition();
const size = win.getSize();
Expand Down
3 changes: 2 additions & 1 deletion main/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ const autoUpdate = require('./autoUpdate');
const binaries = require('./binaries');
const createWindow = require('./createWindow');
const upscayl = require('./upscayl');
const store = require('./store');

module.exports = { autoUpdate, binaries, createWindow, upscayl };
module.exports = { autoUpdate, binaries, createWindow, upscayl, store };
29 changes: 29 additions & 0 deletions main/helpers/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const electron = require('electron');
const path = require('path');
const fs = require('fs');

const Store = (opts) => {
const userDataPath = (electron.app || electron.remote.app).getPath('userData');
const pathJSON = path.join(userDataPath, opts.configName + '.json');
const parseDataFile = (filePath, defaults) => {
try {
return JSON.parse(fs.readFileSync(filePath));
} catch (error) {
return defaults;
}
};
const data = parseDataFile(pathJSON, opts.defaults);
const get = (key) => {
return data[key];
};
const set = (key, val) => {
data[key] = val;
fs.writeFileSync(pathJSON, JSON.stringify(data));
};
return {
get,
set,
};
};

module.exports = Store;
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
"electron-is-dev": "^2.0.0",
"electron-reload": "^2.0.0-alpha.1",
"electron-serve": "^1.1.0",
"electron-settings": "^4.0.2",
"electron-store": "^8.1.0",
"electron-updater": "^5.2.1",
"ui-forest": "^1.11.4"
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/Frame/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const Header = () => {
<>
<header className={classnames(styles.titlebar, { [styles.maximized]: maximise })}>
<div className={styles.drag_region}>
<div className={styles.window_title}>Суперразрешение</div>
<div className={styles.window_title}>{messages.frame.title}</div>
<div className={styles.window_controls}>
<div
title={messages.frame.minimize}
Expand Down
3 changes: 2 additions & 1 deletion src/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"minimize": "",
"maximize": "",
"unmaximize": "",
"close": "Close"
"close": "Close",
"title": "Super resolution"
},
"home": {
"name": "Super resolution",
Expand Down
3 changes: 2 additions & 1 deletion src/locale/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"minimize": "Свернуть",
"maximize": "Развернуть",
"unmaximize": "Свернуть в окно",
"close": "Закрыть"
"close": "Закрыть",
"title": "Суперразрешение"
},
"home": {
"name": "Суперразрешение",
Expand Down
Loading

0 comments on commit 3e2b424

Please sign in to comment.