mirror of
https://github.com/rubickCenter/rubick
synced 2025-12-16 23:54:19 +08:00
♻️ 修改系统设置存储方式
This commit is contained in:
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">
|
||||
|
||||
Reference in New Issue
Block a user