diff --git a/feature/src/confOp.ts b/feature/src/confOp.ts new file mode 100644 index 0000000..6adfd59 --- /dev/null +++ b/feature/src/confOp.ts @@ -0,0 +1,22 @@ +const LOCAL_CONFIG_KEY = 'rubick-local-config'; + +const localConfig = { + getConfig(): Promise { + 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; diff --git a/feature/src/languages/i18n.ts b/feature/src/languages/i18n.ts index c55b806..18a45fc 100644 --- a/feature/src/languages/i18n.ts +++ b/feature/src/languages/i18n.ts @@ -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({ diff --git a/feature/src/main.ts b/feature/src/main.ts index 29b8bf5..3bcaf6b 100644 --- a/feature/src/main.ts +++ b/feature/src/main.ts @@ -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'); diff --git a/feature/src/views/installed/index.vue b/feature/src/views/installed/index.vue index 45663b2..8cec787 100644 --- a/feature/src/views/installed/index.vue +++ b/feature/src/views/installed/index.vue @@ -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'); diff --git a/feature/src/views/settings/index.vue b/feature/src/views/settings/index.vue index e132795..5e02ca4 100644 --- a/feature/src/views/settings/index.vue +++ b/feature/src/views/settings/index.vue @@ -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: { diff --git a/feature/src/views/settings/user-info.vue b/feature/src/views/settings/user-info.vue index 1d37077..6c2b0cb 100644 --- a/feature/src/views/settings/user-info.vue +++ b/feature/src/views/settings/user-info.vue @@ -122,31 +122,29 @@ - + + + + +