mirror of
https://github.com/rubickCenter/rubick
synced 2025-07-18 13:27:25 +08:00
✨ 支持系统菜单功能
This commit is contained in:
parent
c9d6b04a7d
commit
6ee0b2a795
@ -2,6 +2,7 @@ import path from "path";
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import getLocalDataFile from "./getLocalDataFile";
|
import getLocalDataFile from "./getLocalDataFile";
|
||||||
import { app } from "electron";
|
import { app } from "electron";
|
||||||
|
import commonConst from "./commonConst";
|
||||||
|
|
||||||
const configPath = path.join(getLocalDataFile(), "./rubick-config.json");
|
const configPath = path.join(getLocalDataFile(), "./rubick-config.json");
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ const defaultConfigForAnyPlatform = {
|
|||||||
start: true,
|
start: true,
|
||||||
space: true,
|
space: true,
|
||||||
// 是否失焦隐藏。默认在dev环境不隐藏,在打包后隐藏。
|
// 是否失焦隐藏。默认在dev环境不隐藏,在打包后隐藏。
|
||||||
hideOnBlur: app.isPackaged,
|
hideOnBlur: commonConst.production(),
|
||||||
},
|
},
|
||||||
local: {
|
local: {
|
||||||
search: true,
|
search: true,
|
||||||
|
@ -71,7 +71,6 @@ export default class {
|
|||||||
result._id = this.replaceDocId(name, result._id);
|
result._id = this.replaceDocId(name, result._id);
|
||||||
return result;
|
return result;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,10 @@ export default () => {
|
|||||||
|
|
||||||
// 判断失焦是否隐藏
|
// 判断失焦是否隐藏
|
||||||
win.on("blur", () => {
|
win.on("blur", () => {
|
||||||
app.isPackaged && win.hide();
|
const config = { ...global.OP_CONFIG.get() };
|
||||||
|
if (config.perf.common.hideOnBlur) {
|
||||||
|
win.hide();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ export default () => {
|
|||||||
view.webContents.openDevTools();
|
view.webContents.openDevTools();
|
||||||
executeHooks("PluginEnter", plugin.ext);
|
executeHooks("PluginEnter", plugin.ext);
|
||||||
executeHooks("PluginReady", plugin.ext);
|
executeHooks("PluginReady", plugin.ext);
|
||||||
|
window.webContents.executeJavaScript(`window.pluginLoaded()`);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
@changeSelect="changeSelect"
|
@changeSelect="changeSelect"
|
||||||
:searchValue="searchValue"
|
:searchValue="searchValue"
|
||||||
:placeholder="placeholder"
|
:placeholder="placeholder"
|
||||||
|
:pluginLoading="pluginLoading"
|
||||||
@choosePlugin="choosePlugin"
|
@choosePlugin="choosePlugin"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -39,6 +40,7 @@ const {
|
|||||||
openPlugin,
|
openPlugin,
|
||||||
currentPlugin,
|
currentPlugin,
|
||||||
placeholder,
|
placeholder,
|
||||||
|
pluginLoading,
|
||||||
} = createPluginManager();
|
} = createPluginManager();
|
||||||
|
|
||||||
initPlugins();
|
initPlugins();
|
||||||
|
@ -18,11 +18,20 @@
|
|||||||
"
|
"
|
||||||
>
|
>
|
||||||
<template #suffix>
|
<template #suffix>
|
||||||
<div @click="() => emit('openMenu')" class="suffix-tool" >
|
<div class="suffix-tool" >
|
||||||
|
<MoreOutlined
|
||||||
|
@click="showSeparate()"
|
||||||
|
class="icon-more"
|
||||||
|
/>
|
||||||
<div v-if="currentPlugin && currentPlugin.logo" style="position: relative">
|
<div v-if="currentPlugin && currentPlugin.logo" style="position: relative">
|
||||||
|
<a-spin v-show="pluginLoading" class="loading">
|
||||||
|
<template #indicator>
|
||||||
|
<LoadingOutlined style="font-size: 42px" />
|
||||||
|
</template>
|
||||||
|
</a-spin>
|
||||||
<img class="icon-tool" :src="currentPlugin.logo" />
|
<img class="icon-tool" :src="currentPlugin.logo" />
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="rubick-logo">
|
<div @click="() => emit('openMenu')" v-else class="rubick-logo">
|
||||||
<img src="../assets/logo.png" />
|
<img src="../assets/logo.png" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -33,7 +42,12 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { defineProps, defineEmits, ref } from "vue";
|
import { defineProps, defineEmits, ref } from "vue";
|
||||||
import { ipcRenderer } from "electron";
|
import { ipcRenderer, remote } from "electron";
|
||||||
|
import { LoadingOutlined, MoreOutlined } from "@ant-design/icons-vue";
|
||||||
|
const opConfig = remote.getGlobal("OP_CONFIG");
|
||||||
|
const { Menu } = remote;
|
||||||
|
|
||||||
|
const config = ref(opConfig.get());
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
searchValue: {
|
searchValue: {
|
||||||
@ -45,6 +59,7 @@ const props = defineProps({
|
|||||||
default: "",
|
default: "",
|
||||||
},
|
},
|
||||||
currentPlugin: {},
|
currentPlugin: {},
|
||||||
|
pluginLoading: Boolean,
|
||||||
});
|
});
|
||||||
|
|
||||||
const changeValue = (e) => {
|
const changeValue = (e) => {
|
||||||
@ -83,6 +98,53 @@ const closeTag = () => {
|
|||||||
type: "removePlugin",
|
type: "removePlugin",
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const showSeparate = () => {
|
||||||
|
let pluginMenu = [
|
||||||
|
{
|
||||||
|
label: config.value.perf.common.hideOnBlur ? "钉住" : "自动隐藏",
|
||||||
|
click: changeHideOnBlur,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
if (props.currentPlugin && props.currentPlugin.logo) {
|
||||||
|
pluginMenu = pluginMenu.concat([
|
||||||
|
{
|
||||||
|
label: "开发者工具",
|
||||||
|
click: () => {
|
||||||
|
// todo
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "当前插件信息",
|
||||||
|
submenu: [
|
||||||
|
{
|
||||||
|
label: "简介",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "功能",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "分离窗口",
|
||||||
|
click: newWindow,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
let menu = Menu.buildFromTemplate(pluginMenu);
|
||||||
|
menu.popup();
|
||||||
|
};
|
||||||
|
|
||||||
|
const changeHideOnBlur = () => {
|
||||||
|
let cfg = { ...config.value };
|
||||||
|
cfg.perf.common.hideOnBlur = !cfg.perf.common.hideOnBlur;
|
||||||
|
opConfig.set("perf", cfg.perf);
|
||||||
|
config.value = cfg;
|
||||||
|
};
|
||||||
|
|
||||||
|
const newWindow = () => {
|
||||||
|
// todo
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less">
|
<style lang="less">
|
||||||
@ -141,5 +203,20 @@ const closeTag = () => {
|
|||||||
border: none;
|
border: none;
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
}
|
}
|
||||||
|
.suffix-tool {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
.icon-more {
|
||||||
|
font-size: 26px;
|
||||||
|
font-weight: bold;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.loading {
|
||||||
|
color: #ff4ea4;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -18,6 +18,7 @@ const createPluginManager = (): any => {
|
|||||||
plugins: [],
|
plugins: [],
|
||||||
localPlugins: [],
|
localPlugins: [],
|
||||||
currentPlugin: {},
|
currentPlugin: {},
|
||||||
|
pluginLoading: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const appList = ref([]);
|
const appList = ref([]);
|
||||||
@ -28,6 +29,10 @@ const createPluginManager = (): any => {
|
|||||||
|
|
||||||
const openPlugin = (plugin) => {
|
const openPlugin = (plugin) => {
|
||||||
if (plugin.pluginType === "ui") {
|
if (plugin.pluginType === "ui") {
|
||||||
|
if (state.currentPlugin && state.currentPlugin.name === plugin.name) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
state.pluginLoading = true;
|
||||||
state.currentPlugin = plugin;
|
state.currentPlugin = plugin;
|
||||||
ipcRenderer.sendSync("msg-trigger", {
|
ipcRenderer.sendSync("msg-trigger", {
|
||||||
type: "openPlugin",
|
type: "openPlugin",
|
||||||
@ -84,7 +89,6 @@ const createPluginManager = (): any => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
window.setCurrentPlugin = ({ currentPlugin }) => {
|
window.setCurrentPlugin = ({ currentPlugin }) => {
|
||||||
console.log(currentPlugin);
|
|
||||||
state.currentPlugin = currentPlugin;
|
state.currentPlugin = currentPlugin;
|
||||||
setSearchValue("");
|
setSearchValue("");
|
||||||
};
|
};
|
||||||
@ -95,6 +99,10 @@ const createPluginManager = (): any => {
|
|||||||
window.setSubInput({ placeholder: "" });
|
window.setSubInput({ placeholder: "" });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
window.pluginLoaded = () => {
|
||||||
|
state.pluginLoading = false;
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...toRefs(state),
|
...toRefs(state),
|
||||||
initPlugins,
|
initPlugins,
|
||||||
|
1
src/renderer/shims-vue.d.ts
vendored
1
src/renderer/shims-vue.d.ts
vendored
@ -20,4 +20,5 @@ interface Window {
|
|||||||
updatePlugin: (plugin: any) => void;
|
updatePlugin: (plugin: any) => void;
|
||||||
initRubick: () => void;
|
initRubick: () => void;
|
||||||
setCurrentPlugin: (plugin: any) => void;
|
setCurrentPlugin: (plugin: any) => void;
|
||||||
|
pluginLoaded: () => void;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user