mirror of
https://github.com/rubickCenter/rubick
synced 2025-06-08 11:34:10 +08:00
♻️ 修改系统设置存储方式
This commit is contained in:
parent
d2d94c13b7
commit
f4f91e1639
22
feature/src/confOp.ts
Normal file
22
feature/src/confOp.ts
Normal file
@ -0,0 +1,22 @@
|
||||
const LOCAL_CONFIG_KEY = 'rubick-local-config';
|
||||
|
||||
const localConfig = {
|
||||
getConfig(): Promise<any> {
|
||||
const data: any = window.rubick.db.get(LOCAL_CONFIG_KEY) || {};
|
||||
return data.data;
|
||||
},
|
||||
|
||||
setConfig(data: any) {
|
||||
const localConfig: any = window.rubick.db.get(LOCAL_CONFIG_KEY) || {};
|
||||
window.rubick.db.put({
|
||||
_id: LOCAL_CONFIG_KEY,
|
||||
_rev: localConfig._rev,
|
||||
data: {
|
||||
...localConfig.data,
|
||||
...data,
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export default localConfig;
|
@ -1,7 +1,7 @@
|
||||
import { createI18n } from 'vue-i18n';
|
||||
import messages from './langs';
|
||||
const remote = window.require('@electron/remote');
|
||||
const { perf } = remote.getGlobal('OP_CONFIG').get();
|
||||
import localConfig from '@/confOp';
|
||||
const { perf }: any = localConfig.getConfig();
|
||||
|
||||
// 2. Create i18n instance with options
|
||||
const i18n = createI18n({
|
||||
|
@ -6,13 +6,12 @@ import store from './store';
|
||||
import './assets/ant-reset.less';
|
||||
import 'ant-design-vue/dist/antd.variable.min.css';
|
||||
import registerI18n from './languages/i18n';
|
||||
import localConfig from './confOp';
|
||||
|
||||
const remote = window.require('@electron/remote');
|
||||
|
||||
const { perf } = remote.getGlobal('OP_CONFIG').get();
|
||||
const config: any = localConfig.getConfig();
|
||||
|
||||
ConfigProvider.config({
|
||||
theme: perf.custom || {},
|
||||
theme: config.perf.custom || {},
|
||||
});
|
||||
|
||||
createApp(App).use(registerI18n).use(store).use(Antd).use(router).mount('#app');
|
||||
|
@ -125,7 +125,7 @@ const remote = window.require('@electron/remote');
|
||||
const fs = window.require('fs');
|
||||
const md = new MarkdownIt();
|
||||
|
||||
const appPath = remote.app.getPath('cache');
|
||||
const appPath = remote.app.getPath('userData');
|
||||
const baseDir = path.join(appPath, './rubick-plugins');
|
||||
|
||||
const store = useStore();
|
||||
@ -171,7 +171,6 @@ const removePluginToSuperPanel = (cmd) => {
|
||||
return item.cmd !== cmd;
|
||||
}
|
||||
);
|
||||
console.log(toRaw(superPanelPlugins.value));
|
||||
window.rubick.db.put(toRaw(superPanelPlugins.value));
|
||||
};
|
||||
|
||||
@ -209,7 +208,7 @@ const readme = computed(() => {
|
||||
baseDir,
|
||||
'node_modules',
|
||||
pluginDetail.value.name,
|
||||
'readme.md'
|
||||
'README.md'
|
||||
);
|
||||
if (fs.existsSync(readmePath)) {
|
||||
const str = fs.readFileSync(readmePath, 'utf-8');
|
||||
|
@ -231,20 +231,20 @@ import {
|
||||
DatabaseOutlined,
|
||||
MinusCircleOutlined,
|
||||
PlusCircleOutlined,
|
||||
FileAddOutlined,
|
||||
UserOutlined,
|
||||
} from '@ant-design/icons-vue';
|
||||
import debounce from 'lodash.debounce';
|
||||
import { ref, reactive, watch, toRefs, computed, onMounted, toRaw } from 'vue';
|
||||
import { ref, reactive, watch, toRefs, computed } from 'vue';
|
||||
import keycodes from './keycode';
|
||||
import Localhost from './localhost.vue';
|
||||
import SuperPanel from './super-panel.vue';
|
||||
import UserInfo from './user-info';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import localConfig from '@/confOp';
|
||||
|
||||
const { locale, t } = useI18n();
|
||||
|
||||
const { ipcRenderer } = window.require('electron');
|
||||
const remote = window.require('@electron/remote');
|
||||
|
||||
const examples = [
|
||||
{
|
||||
@ -275,7 +275,7 @@ const tipText = computed(() => {
|
||||
|
||||
const currentSelect = ref(['userInfo']);
|
||||
|
||||
const { perf, global: defaultGlobal } = remote.getGlobal('OP_CONFIG').get();
|
||||
const { perf, global: defaultGlobal } = localConfig.getConfig();
|
||||
|
||||
state.shortCut = perf.shortCut;
|
||||
state.custom = perf.custom;
|
||||
@ -284,7 +284,7 @@ state.local = perf.local;
|
||||
state.global = defaultGlobal;
|
||||
|
||||
const setConfig = debounce(() => {
|
||||
remote.getGlobal('OP_CONFIG').set(
|
||||
localConfig.setConfig(
|
||||
JSON.parse(
|
||||
JSON.stringify({
|
||||
perf: {
|
||||
|
@ -122,31 +122,29 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer-btn">
|
||||
<a-button @click="reset" type="danger">
|
||||
{{ $t('feature.settings.account.reset') }}
|
||||
</a-button>
|
||||
</div>
|
||||
<!-- <div class="footer-btn">-->
|
||||
<!-- <a-button @click="reset" type="danger">-->
|
||||
<!-- {{ $t('feature.settings.account.reset') }}-->
|
||||
<!-- </a-button>-->
|
||||
<!-- </div>-->
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { reactive, ref, toRefs, watch } from 'vue';
|
||||
import { Modal } from 'ant-design-vue';
|
||||
import { UserOutlined } from '@ant-design/icons-vue';
|
||||
import debounce from 'lodash.debounce';
|
||||
import localConfig from '@/confOp';
|
||||
|
||||
import service from '../../assets/service';
|
||||
|
||||
const { ipcRenderer } = window.require('electron');
|
||||
const remote = window.require('@electron/remote');
|
||||
|
||||
const state = reactive({
|
||||
custom: {},
|
||||
});
|
||||
|
||||
const { perf } = remote.getGlobal('OP_CONFIG').get();
|
||||
const { perf } = localConfig.getConfig();
|
||||
|
||||
state.custom = perf.custom || {};
|
||||
|
||||
@ -157,7 +155,7 @@ const userInfo = ref(window.rubick.dbStorage.getItem('rubick-user-info'));
|
||||
// });
|
||||
|
||||
const setConfig = debounce(() => {
|
||||
remote.getGlobal('OP_CONFIG').set(
|
||||
localConfig.setConfig(
|
||||
JSON.parse(
|
||||
JSON.stringify({
|
||||
perf: {
|
||||
@ -182,17 +180,17 @@ const changeLogo = () => {
|
||||
state.custom.logo = `file://${logoPath}`;
|
||||
};
|
||||
|
||||
const reset = () => {
|
||||
Modal.warning({
|
||||
title: '确定恢复默认设置吗?',
|
||||
content: '回复后之前的设置将会被清空',
|
||||
onOk() {
|
||||
const defaultcustom = remote.getGlobal('OP_CONFIG').getDefaultConfig()
|
||||
.perf.custom;
|
||||
state.custom = JSON.parse(JSON.stringify(defaultcustom));
|
||||
},
|
||||
});
|
||||
};
|
||||
// const reset = () => {
|
||||
// Modal.warning({
|
||||
// title: '确定恢复默认设置吗?',
|
||||
// content: '回复后之前的设置将会被清空',
|
||||
// onOk() {
|
||||
// const defaultcustom = remote.getGlobal('OP_CONFIG').getDefaultConfig()
|
||||
// .perf.custom;
|
||||
// state.custom = JSON.parse(JSON.stringify(defaultcustom));
|
||||
// },
|
||||
// });
|
||||
// };
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
|
@ -1,5 +1,5 @@
|
||||
export default {
|
||||
version: 12,
|
||||
version: 0,
|
||||
perf: {
|
||||
custom: {
|
||||
primaryColor: '#ff4ea4',
|
||||
|
@ -1,17 +1,17 @@
|
||||
export default {
|
||||
linux(): boolean {
|
||||
return process.platform === "linux";
|
||||
return process.platform === 'linux';
|
||||
},
|
||||
macOS(): boolean {
|
||||
return process.platform === "darwin";
|
||||
return process.platform === 'darwin';
|
||||
},
|
||||
windows(): boolean {
|
||||
return process.platform === "win32";
|
||||
return process.platform === 'win32';
|
||||
},
|
||||
production(): boolean {
|
||||
return process.env.NODE_ENV !== "development";
|
||||
return process.env.NODE_ENV !== 'development';
|
||||
},
|
||||
dev(): boolean {
|
||||
return process.env.NODE_ENV === "development";
|
||||
return process.env.NODE_ENV === 'development';
|
||||
},
|
||||
};
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { ipcRenderer } from 'electron';
|
||||
import commonConst from './commonConst';
|
||||
|
||||
const useDrag = () => {
|
||||
let animationId: number;
|
||||
|
@ -1,12 +1,12 @@
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
export default (): string => {
|
||||
let localDataFile: any = process.env.HOME;
|
||||
if (!localDataFile) {
|
||||
localDataFile = process.env.LOCALAPPDATA;
|
||||
}
|
||||
const rubickPath = path.join(localDataFile, "rubick");
|
||||
const rubickPath = path.join(localDataFile, 'rubick');
|
||||
if (!fs.existsSync(rubickPath)) {
|
||||
fs.mkdirSync(rubickPath);
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { BrowserWindow, ipcMain, nativeTheme } from 'electron';
|
||||
import localConfig from '../common/initLocalConfig';
|
||||
import path from 'path';
|
||||
export default () => {
|
||||
let win: any;
|
||||
@ -28,7 +29,6 @@ export default () => {
|
||||
y: viewInfo.y,
|
||||
webPreferences: {
|
||||
webSecurity: false,
|
||||
enableRemoteModule: true,
|
||||
backgroundThrottling: false,
|
||||
contextIsolation: false,
|
||||
webviewTag: true,
|
||||
@ -49,8 +49,9 @@ export default () => {
|
||||
win = undefined;
|
||||
});
|
||||
|
||||
win.once('ready-to-show', () => {
|
||||
const darkMode = global.OP_CONFIG.get().perf.common.darkMode;
|
||||
win.once('ready-to-show', async () => {
|
||||
const config = await localConfig.getConfig();
|
||||
const darkMode = config.perf.common.darkMode;
|
||||
darkMode &&
|
||||
win.webContents.executeJavaScript(
|
||||
`document.body.classList.add("dark");window.rubick.theme="dark"`
|
||||
|
@ -43,7 +43,6 @@ export default () => {
|
||||
height: 600,
|
||||
webPreferences: {
|
||||
webSecurity: false,
|
||||
enableRemoteModule: true,
|
||||
backgroundThrottling: false,
|
||||
contextIsolation: false,
|
||||
webviewTag: true,
|
||||
|
@ -2,6 +2,7 @@ import { app, BrowserWindow, protocol, nativeTheme } from 'electron';
|
||||
import path from 'path';
|
||||
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib';
|
||||
import versonHandler from '../common/versionHandler';
|
||||
import localConfig from '@/main/common/initLocalConfig';
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
require('@electron/remote/main').initialize();
|
||||
|
||||
@ -65,8 +66,8 @@ export default () => {
|
||||
});
|
||||
|
||||
// 判断失焦是否隐藏
|
||||
win.on('blur', () => {
|
||||
const config = { ...global.OP_CONFIG.get() };
|
||||
win.on('blur', async () => {
|
||||
const config = await localConfig.getConfig();
|
||||
if (config.perf.common.hideOnBlur) {
|
||||
win.hide();
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import { BrowserView, BrowserWindow, session } from 'electron';
|
||||
import path from 'path';
|
||||
import commonConst from '../../common/utils/commonConst';
|
||||
import { PLUGIN_INSTALL_DIR as baseDir } from '@/common/constans/main';
|
||||
import localConfig from '@/main/common/initLocalConfig';
|
||||
|
||||
const getRelativePath = (indexPath) => {
|
||||
return commonConst.windows()
|
||||
@ -78,7 +79,7 @@ export default () => {
|
||||
});
|
||||
window.setBrowserView(view);
|
||||
view.webContents.loadURL(pluginIndexPath);
|
||||
view.webContents.once('dom-ready', () => {
|
||||
view.webContents.once('dom-ready', async () => {
|
||||
if (!view) return;
|
||||
const height = pluginSetting && pluginSetting.height;
|
||||
window.setSize(800, height || 660);
|
||||
@ -86,7 +87,8 @@ export default () => {
|
||||
view.setAutoResize({ width: true });
|
||||
executeHooks('PluginEnter', plugin.ext);
|
||||
executeHooks('PluginReady', plugin.ext);
|
||||
darkMode = global.OP_CONFIG.get().perf.common.darkMode;
|
||||
const config = await localConfig.getConfig();
|
||||
const darkMode = config.perf.common.darkMode;
|
||||
darkMode &&
|
||||
view.webContents.executeJavaScript(
|
||||
`document.body.classList.add("dark");window.rubick.theme="dark"`
|
||||
|
@ -10,8 +10,9 @@ import {
|
||||
shell,
|
||||
} from 'electron';
|
||||
import { runner, detach } from '../browsers';
|
||||
import DBInstance from './db';
|
||||
import fs from 'fs';
|
||||
import { LocalDb, screenCapture } from '@/core';
|
||||
import { screenCapture } from '@/core';
|
||||
import plist from 'plist';
|
||||
import ks from 'node-key-sender';
|
||||
|
||||
@ -21,14 +22,9 @@ import getCopyFiles from '@/common/utils/getCopyFiles';
|
||||
import mainInstance from '../index';
|
||||
const runnerInstance = runner();
|
||||
const detachInstance = detach();
|
||||
const dbInstance = new LocalDb(app.getPath('userData'));
|
||||
|
||||
dbInstance.init();
|
||||
|
||||
class API {
|
||||
class API extends DBInstance {
|
||||
public currentPlugin: null | any = null;
|
||||
private DBKEY = 'RUBICK_DB_DEFAULT';
|
||||
|
||||
init(mainWindow: BrowserWindow) {
|
||||
// 响应 preload.js 事件
|
||||
ipcMain.on('msg-trigger', async (event, arg) => {
|
||||
@ -196,26 +192,6 @@ class API {
|
||||
return false;
|
||||
}
|
||||
|
||||
public dbPut({ data }) {
|
||||
return dbInstance.put(this.DBKEY, data.data);
|
||||
}
|
||||
|
||||
public dbGet({ data }) {
|
||||
return dbInstance.get(this.DBKEY, data.id);
|
||||
}
|
||||
|
||||
public dbRemove({ data }) {
|
||||
return dbInstance.remove(this.DBKEY, data.doc);
|
||||
}
|
||||
|
||||
public dbBulkDocs({ data }) {
|
||||
return dbInstance.bulkDocs(this.DBKEY, data.docs);
|
||||
}
|
||||
|
||||
public dbAllDocs({ data }) {
|
||||
return dbInstance.allDocs(this.DBKEY, data.key);
|
||||
}
|
||||
|
||||
public getFeatures() {
|
||||
return this.currentPlugin.features;
|
||||
}
|
||||
|
28
src/main/common/db.ts
Normal file
28
src/main/common/db.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { LocalDb } from '@/core';
|
||||
import { app } from 'electron';
|
||||
|
||||
const dbInstance = new LocalDb(app.getPath('userData'));
|
||||
dbInstance.init();
|
||||
|
||||
export default class DBInstance {
|
||||
private DBKEY = 'RUBICK_DB_DEFAULT';
|
||||
public dbPut({ data }) {
|
||||
return dbInstance.put(this.DBKEY, data.data);
|
||||
}
|
||||
|
||||
public dbGet({ data }) {
|
||||
return dbInstance.get(this.DBKEY, data.id);
|
||||
}
|
||||
|
||||
public dbRemove({ data }) {
|
||||
return dbInstance.remove(this.DBKEY, data.doc);
|
||||
}
|
||||
|
||||
public dbBulkDocs({ data }) {
|
||||
return dbInstance.bulkDocs(this.DBKEY, data.docs);
|
||||
}
|
||||
|
||||
public dbAllDocs({ data }) {
|
||||
return dbInstance.allDocs(this.DBKEY, data.key);
|
||||
}
|
||||
}
|
51
src/main/common/initLocalConfig.ts
Normal file
51
src/main/common/initLocalConfig.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import defaultConfig from '@/common/constans/defaultConfig';
|
||||
import DBInstance from './db';
|
||||
const LOCAL_CONFIG_KEY = 'rubick-local-config';
|
||||
|
||||
const db = new DBInstance();
|
||||
|
||||
const localConfig = {
|
||||
async init(): Promise<any> {
|
||||
const localConfig = await db.dbGet({ data: { id: LOCAL_CONFIG_KEY } });
|
||||
if (
|
||||
!localConfig ||
|
||||
!localConfig.data ||
|
||||
localConfig.data.version !== defaultConfig.version
|
||||
) {
|
||||
const data: any = {
|
||||
_id: LOCAL_CONFIG_KEY,
|
||||
data: defaultConfig,
|
||||
};
|
||||
if (localConfig && localConfig.data) {
|
||||
data._rev = localConfig.data._rev;
|
||||
}
|
||||
await db.dbPut({
|
||||
data: { data },
|
||||
});
|
||||
}
|
||||
},
|
||||
async getConfig(): Promise<any> {
|
||||
const data: any =
|
||||
(await db.dbGet({ data: { id: LOCAL_CONFIG_KEY } })) || {};
|
||||
return data.data;
|
||||
},
|
||||
|
||||
async setConfig(data) {
|
||||
const localConfig: any =
|
||||
(await db.dbGet({ data: { id: LOCAL_CONFIG_KEY } })) || {};
|
||||
await db.dbPut({
|
||||
data: {
|
||||
data: {
|
||||
_id: LOCAL_CONFIG_KEY,
|
||||
_rev: localConfig._rev,
|
||||
data: {
|
||||
...localConfig.data,
|
||||
...data,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export default localConfig;
|
@ -9,19 +9,20 @@ import {
|
||||
Notification,
|
||||
} from 'electron';
|
||||
import screenCapture from '@/core/screen-capture';
|
||||
import localConfig from '@/main/common/initLocalConfig';
|
||||
|
||||
const registerHotKey = (mainWindow: BrowserWindow): void => {
|
||||
// 设置开机启动
|
||||
const setAutoLogin = () => {
|
||||
const config = global.OP_CONFIG.get();
|
||||
const setAutoLogin = async () => {
|
||||
const config = await localConfig.getConfig();
|
||||
app.setLoginItemSettings({
|
||||
openAtLogin: config.perf.common.start,
|
||||
openAsHidden: true,
|
||||
});
|
||||
};
|
||||
// 设置暗黑模式
|
||||
const setDarkMode = () => {
|
||||
const config = global.OP_CONFIG.get();
|
||||
const setDarkMode = async () => {
|
||||
const config = await localConfig.getConfig();
|
||||
const isDark = config.perf.common.darkMode;
|
||||
if (isDark) {
|
||||
nativeTheme.themeSource = 'dark';
|
||||
@ -46,10 +47,10 @@ const registerHotKey = (mainWindow: BrowserWindow): void => {
|
||||
}
|
||||
};
|
||||
|
||||
const init = () => {
|
||||
setAutoLogin();
|
||||
setDarkMode();
|
||||
const config = global.OP_CONFIG.get();
|
||||
const init = async () => {
|
||||
await setAutoLogin();
|
||||
await setDarkMode();
|
||||
const config = await localConfig.getConfig();
|
||||
globalShortcut.unregisterAll();
|
||||
// 注册偏好快捷键
|
||||
globalShortcut.register(config.perf.shortCut.showAndHidden, () => {
|
||||
|
@ -2,7 +2,6 @@ import { dialog, Menu, Tray, app, shell, BrowserWindow } from 'electron';
|
||||
import path from 'path';
|
||||
import pkg from '../../../package.json';
|
||||
import os from 'os';
|
||||
import API from '../common/api';
|
||||
import commonConst from '@/common/utils/commonConst';
|
||||
import { guide } from '../browsers';
|
||||
|
||||
@ -21,11 +20,6 @@ function createTray(window: BrowserWindow): Promise<Tray> {
|
||||
}
|
||||
const appIcon = new Tray(path.join(__static, icon));
|
||||
|
||||
const getShowAndHiddenHotKey = (): string => {
|
||||
const config = global.OP_CONFIG.get();
|
||||
return config.perf.shortCut.showAndHidden;
|
||||
};
|
||||
|
||||
const openSettings = () => {
|
||||
window.webContents.executeJavaScript(
|
||||
`window.rubick && window.rubick.openMenu && window.rubick.openMenu({ code: "settings" })`
|
||||
@ -59,8 +53,7 @@ function createTray(window: BrowserWindow): Promise<Tray> {
|
||||
},
|
||||
{ type: 'separator' },
|
||||
{
|
||||
label: '显示窗口',
|
||||
accelerator: getShowAndHiddenHotKey(),
|
||||
label: '显示',
|
||||
click() {
|
||||
window.show();
|
||||
},
|
||||
|
@ -12,9 +12,9 @@ import commonConst from '../common/utils/commonConst';
|
||||
import API from './common/api';
|
||||
import createTray from './common/tray';
|
||||
import registerHotKey from './common/registerHotKey';
|
||||
import localConfig from './common/initLocalConfig';
|
||||
|
||||
import '../common/utils/localPlugin';
|
||||
import '../common/utils/localConfig';
|
||||
|
||||
import registerySystemPlugin from './common/registerySystemPlugin';
|
||||
|
||||
@ -55,12 +55,13 @@ class App {
|
||||
this.windowCreator.init();
|
||||
}
|
||||
onReady() {
|
||||
const readyFunction = () => {
|
||||
const config = global.OP_CONFIG.get();
|
||||
const readyFunction = async () => {
|
||||
await localConfig.init();
|
||||
const config = await localConfig.getConfig();
|
||||
if (!config.perf.common.guide) {
|
||||
guide().init();
|
||||
config.perf.common.guide = true;
|
||||
global.OP_CONFIG.set(config);
|
||||
localConfig.setConfig(config);
|
||||
}
|
||||
this.createWindow();
|
||||
const mainWindow = this.windowCreator.getWindow();
|
||||
|
@ -57,10 +57,10 @@ import { ipcRenderer } from 'electron';
|
||||
import { LoadingOutlined, MoreOutlined } from '@ant-design/icons-vue';
|
||||
|
||||
const remote = window.require('@electron/remote');
|
||||
const opConfig = remote.getGlobal('OP_CONFIG');
|
||||
import localConfig from '../confOp';
|
||||
const { Menu } = remote;
|
||||
|
||||
const config = ref(opConfig.get());
|
||||
const config: any = ref(localConfig.getConfig());
|
||||
|
||||
const props: any = defineProps({
|
||||
searchValue: {
|
||||
@ -120,7 +120,7 @@ const keydownEvent = (e, key: string) => {
|
||||
emit('choosePlugin');
|
||||
break;
|
||||
case 'space':
|
||||
if (runPluginDisable || !opConfig.get().perf.common.space) return;
|
||||
if (runPluginDisable || !config.value.perf.common.space) return;
|
||||
emit('choosePlugin');
|
||||
break;
|
||||
default:
|
||||
@ -217,14 +217,14 @@ const showSeparate = () => {
|
||||
const changeLang = (lang) => {
|
||||
let cfg = { ...config.value };
|
||||
cfg.perf.common.lang = lang;
|
||||
opConfig.set(cfg);
|
||||
localConfig.setConfig(JSON.parse(JSON.stringify(cfg)));
|
||||
config.value = cfg;
|
||||
};
|
||||
|
||||
const changeHideOnBlur = () => {
|
||||
let cfg = { ...config.value };
|
||||
cfg.perf.common.hideOnBlur = !cfg.perf.common.hideOnBlur;
|
||||
opConfig.set(cfg);
|
||||
localConfig.setConfig(JSON.parse(JSON.stringify(cfg)));
|
||||
config.value = cfg;
|
||||
};
|
||||
|
||||
|
22
src/renderer/confOp.ts
Normal file
22
src/renderer/confOp.ts
Normal file
@ -0,0 +1,22 @@
|
||||
const LOCAL_CONFIG_KEY = 'rubick-local-config';
|
||||
|
||||
const localConfig = {
|
||||
getConfig(): Promise<any> {
|
||||
const data: any = window.rubick.db.get(LOCAL_CONFIG_KEY) || {};
|
||||
return data.data;
|
||||
},
|
||||
|
||||
setConfig(data) {
|
||||
const localConfig: any = window.rubick.db.get(LOCAL_CONFIG_KEY) || {};
|
||||
window.rubick.db.put({
|
||||
_id: LOCAL_CONFIG_KEY,
|
||||
_rev: localConfig._rev,
|
||||
data: {
|
||||
...localConfig.data,
|
||||
...data,
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export default localConfig;
|
@ -9,15 +9,14 @@ import {
|
||||
ConfigProvider,
|
||||
} from 'ant-design-vue';
|
||||
import App from './App.vue';
|
||||
import localConfig from './confOp';
|
||||
|
||||
import 'ant-design-vue/dist/antd.variable.min.css';
|
||||
|
||||
const { getGlobal } = window.require('@electron/remote');
|
||||
|
||||
const { perf } = getGlobal('OP_CONFIG').get();
|
||||
const config: any = localConfig.getConfig();
|
||||
|
||||
ConfigProvider.config({
|
||||
theme: perf.custom || {},
|
||||
theme: config.perf.custom || {},
|
||||
});
|
||||
|
||||
createApp(App)
|
||||
|
@ -3,12 +3,13 @@ import { clipboard, nativeImage, ipcRenderer } from 'electron';
|
||||
import { getGlobal } from '@electron/remote';
|
||||
import path from 'path';
|
||||
import pluginClickEvent from './pluginClickEvent';
|
||||
import localConfig from '../confOp';
|
||||
import { ref } from 'vue';
|
||||
|
||||
export default ({ currentPlugin, optionsRef, openPlugin, setOptionsRef }) => {
|
||||
const clipboardFile: any = ref([]);
|
||||
const searchFocus = () => {
|
||||
const config = getGlobal('OP_CONFIG').get();
|
||||
const config: any = localConfig.getConfig();
|
||||
// 未开启自动粘贴
|
||||
if (!config.perf.common.autoPast) return;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user