增加失焦隐藏or不隐藏的小按钮

This commit is contained in:
tcsnzh 2021-10-04 19:14:16 +08:00
parent 60b1138dd8
commit 747c5512a7
4 changed files with 225 additions and 150 deletions

View File

@ -1,6 +1,7 @@
import {app} from 'electron'; import { app } from "electron";
import './config'; import "./config";
import Listener from './listener'; import Listener from "./listener";
import { remote } from "electron";
export default function init(mainWindow) { export default function init(mainWindow) {
const listener = new Listener(); const listener = new Listener();
@ -16,11 +17,11 @@ export default function init(mainWindow) {
} }
}); });
// 打包后,失焦隐藏 // 判断失焦是否隐藏
mainWindow.on('blur', () => { mainWindow.on("blur", () => {
app.isPackaged && mainWindow.hide(); const config = { ...opConfig.get() };
if (config.perf.common.hideOnBlur) {
mainWindow.hide();
}
}); });
} }

View File

@ -2,6 +2,7 @@ import path from "path";
import fs from "fs"; import fs from "fs";
import { getLocalDataFile } from "./utils"; import { getLocalDataFile } from "./utils";
import os from "os"; import os from "os";
import { app } from "electron";
const configPath = path.join(getLocalDataFile(), "./rubick-config.json"); const configPath = path.join(getLocalDataFile(), "./rubick-config.json");
@ -16,6 +17,8 @@ const defaultConfigForAnyPlatform = {
common: { common: {
start: true, start: true,
space: true, space: true,
// 是否失焦隐藏。默认在dev环境不隐藏在打包后隐藏。
hideOnBlur: app.isPackaged,
}, },
local: { local: {
search: true, search: true,

View File

@ -59,6 +59,14 @@
</div> </div>
</div> </div>
</a-input> </a-input>
<span class="button-hide-on-blur" @click="changeHideOnBlur">
<a-icon
type="pushpin"
:style="{
color: config.perf.common.hideOnBlur ? 'grey' : '#ea68a2',
}"
></a-icon>
</span>
<div v-show="showOptions" class="options"> <div v-show="showOptions" class="options">
<a-list item-layout="horizontal" :data-source="options"> <a-list item-layout="horizontal" :data-source="options">
<a-list-item <a-list-item
@ -135,11 +143,10 @@ export default {
return { return {
query: this.$route.query, query: this.$route.query,
searchFn: null, searchFn: null,
config: opConfig.get(), config: { ...opConfig.get() },
currentSelect: 0, currentSelect: 0,
}; };
}, },
created() { created() {
window.setPluginInfo = (pluginInfo) => { window.setPluginInfo = (pluginInfo) => {
this.commonUpdate({ this.commonUpdate({
@ -147,7 +154,6 @@ export default {
}); });
}; };
}, },
mounted() { mounted() {
ipcRenderer.on("init-rubick", this.closeTag); ipcRenderer.on("init-rubick", this.closeTag);
ipcRenderer.on("new-window", this.newWindow); ipcRenderer.on("new-window", this.newWindow);
@ -319,10 +325,14 @@ export default {
} }
}, },
changePath({ key }) { changePath({ key }) {
this.$router.push({ path: `/home/${key}` }); const path = `/home/${key}`;
this.commonUpdate({ //
current: [key], if (this.$router.history.current.fullPath != path) {
}); this.$router.push({ path });
this.commonUpdate({
current: [key],
});
}
}, },
closeTag(v) { closeTag(v) {
this.commonUpdate({ this.commonUpdate({
@ -396,6 +406,11 @@ export default {
ipcRenderer.send("window-move"); ipcRenderer.send("window-move");
} }
}, },
changeHideOnBlur(e) {
let cfg = { ...this.config };
cfg.perf.common.hideOnBlur = !cfg.perf.common.hideOnBlur;
this.config = cfg;
},
}, },
computed: { computed: {
...mapState("main", [ ...mapState("main", [
@ -410,7 +425,7 @@ export default {
"pluginLoading", "pluginLoading",
]), ]),
showOptions() { showOptions() {
// //
if (this.options.length && !this.showMain) { if (this.options.length && !this.showMain) {
return true; return true;
} }
@ -419,6 +434,17 @@ export default {
return this.pluginInfo.searchType ? "subWindow" : ""; return this.pluginInfo.searchType ? "subWindow" : "";
}, },
}, },
watch: {
config: {
deep: true,
handler() {
opConfig.set("perf", this.config.perf);
opConfig.set("superPanel", this.config.superPanel);
opConfig.set("global", this.config.global);
ipcRenderer.send("re-register");
},
},
},
}; };
</script> </script>
<style lang="less"> <style lang="less">
@ -538,4 +564,9 @@ export default {
left: 0; left: 0;
} }
} }
.button-hide-on-blur {
padding: 0px 3px 0px 0px;
// 1/3
height: 33%;
}
</style> </style>

View File

@ -1,7 +1,11 @@
<template> <template>
<div class="pg-settings"> <div class="pg-settings">
<div class="dev-detail"> <div class="dev-detail">
<a-menu v-model="currentSelect" style="width: 256px; height: 100%" mode="vertical"> <a-menu
v-model="currentSelect"
style="width: 256px; height: 100%"
mode="vertical"
>
<a-menu-item :key="0"> <a-menu-item :key="0">
偏好设置 偏好设置
</a-menu-item> </a-menu-item>
@ -15,40 +19,72 @@
<div class="settings-detail"> <div class="settings-detail">
<div v-if="currentSelect[0] === 0"> <div v-if="currentSelect[0] === 0">
<div class="setting-item"> <div class="setting-item">
<div class="title">快捷键(需要使用 option/ctrl/shift/command 键修饰)</div> <div class="title">
快捷键(需要使用 option/ctrl/shift/command 键修饰)
</div>
<div class="settings-item-li"> <div class="settings-item-li">
<div class="label">显示/隐藏快捷键</div> <div class="label">显示/隐藏快捷键</div>
<div class="value" tabIndex=-1 @keyup="(e) => changeShortCut(e, 'showAndHidden')">{{ config.perf.shortCut.showAndHidden }}</div> <div
class="value"
tabIndex="-1"
@keyup="(e) => changeShortCut(e, 'showAndHidden')"
>
{{ config.perf.shortCut.showAndHidden }}
</div>
</div> </div>
<div class="settings-item-li"> <div class="settings-item-li">
<div class="label">插件分离快捷键</div> <div class="label">插件分离快捷键</div>
<div class="value" tabIndex=-1 @keyup="(e) => changeShortCut(e, 'separate')">{{ config.perf.shortCut.separate }}</div> <div
class="value"
tabIndex="-1"
@keyup="(e) => changeShortCut(e, 'separate')"
>
{{ config.perf.shortCut.separate }}
</div>
</div> </div>
<div class="settings-item-li"> <div class="settings-item-li">
<div class="label">返回主界面</div> <div class="label">返回主界面</div>
<div class="value" tabIndex=-1 @keyup="(e) => changeShortCut(e, 'quit')">{{ config.perf.shortCut.quit }}</div> <div
class="value"
tabIndex="-1"
@keyup="(e) => changeShortCut(e, 'quit')"
>
{{ config.perf.shortCut.quit }}
</div>
</div> </div>
</div> </div>
<div class="setting-item"> <div class="setting-item">
<div class="title">通用</div> <div class="title">通用</div>
<div class="settings-item-li"> <div class="settings-item-li">
<div class="label">开机启动</div> <div class="label">开机启动</div>
<a-switch v-model:checked="config.perf.common.start" checked-children="" un-checked-children=""></a-switch> <a-switch
v-model:checked="config.perf.common.start"
checked-children="开"
un-checked-children="关"
></a-switch>
</div> </div>
<div class="settings-item-li"> <div class="settings-item-li">
<div class="label">空格执行</div> <div class="label">空格执行</div>
<a-switch v-model:checked="config.perf.common.space" checked-children="" un-checked-children=""></a-switch> <a-switch
v-model:checked="config.perf.common.space"
checked-children="开"
un-checked-children="关"
></a-switch>
</div> </div>
</div> </div>
<div class="setting-item"> <div class="setting-item">
<div class="title">本地搜索启动</div> <div class="title">本地搜索启动</div>
<div class="settings-item-li"> <div class="settings-item-li">
<div class="label">搜索启动应用&文件</div> <div class="label">搜索启动应用&文件</div>
<a-switch v-model:checked="config.perf.local.search" checked-children="" un-checked-children=""></a-switch> <a-switch
v-model:checked="config.perf.local.search"
checked-children="开"
un-checked-children="关"
></a-switch>
</div> </div>
</div> </div>
</div> </div>
<div v-if="currentSelect[0] === 1"> <div v-if="currentSelect[0] === 1">
<div class="setting-item"> <div class="setting-item">
<div class="title">弹出面板</div> <div class="title">弹出面板</div>
<a-select value="mouseRight" style="width: 200px" disabled> <a-select value="mouseRight" style="width: 200px" disabled>
@ -57,20 +93,25 @@
</div> </div>
<div class="setting-item"> <div class="setting-item">
<div class="title">长按以下设置的毫秒响应</div> <div class="title">长按以下设置的毫秒响应</div>
<a-slider :step="100" v-model:value="config.superPanel.mouseDownTime" :min="200" :max="1000" /> <a-slider
:step="100"
v-model:value="config.superPanel.mouseDownTime"
:min="200"
:max="1000"
/>
</div> </div>
</div> </div>
<div v-if="currentSelect[0] === 2"> <div v-if="currentSelect[0] === 2">
<a-collapse> <a-collapse>
<a-collapse-panel key="1" header="说明及示例"> <a-collapse-panel key="1" header="说明及示例">
<div>按下快捷键自动搜索对应关键字当关键字结果完全匹配且结果唯一时会直接指向该功能</div> <div>
按下快捷键自动搜索对应关键字当关键字结果完全匹配且结果唯一时会直接指向该功能
</div>
<h3 style="margin-top: 10px;">示例</h3> <h3 style="margin-top: 10px;">示例</h3>
<a-divider style="margin: 5px 0;" /> <a-divider style="margin: 5px 0;" />
<a-list item-layout="horizontal" :data-source="examples"> <a-list item-layout="horizontal" :data-source="examples">
<a-list-item slot="renderItem" slot-scope="item, index"> <a-list-item slot="renderItem" slot-scope="item, index">
<a-list-item-meta <a-list-item-meta :description="item.desc">
:description="item.desc"
>
<div slot="title">{{ item.title }}</div> <div slot="title">{{ item.title }}</div>
</a-list-item-meta> </a-list-item-meta>
</a-list-item> </a-list-item>
@ -82,80 +123,81 @@
<div>快捷键</div> <div>快捷键</div>
<a-tooltip placement="top" trigger="click"> <a-tooltip placement="top" trigger="click">
<template slot="title"> <template slot="title">
<span>先按功能键CtrlShiftAltOptionCommand再按其他普通键或按 F1-F12 单键</span> <span
>先按功能键CtrlShiftAltOptionCommand再按其他普通键或按
F1-F12 单键</span
>
</template> </template>
<div <div
v-for="(item, index) in config.global" v-for="(item, index) in config.global"
class="value" class="value"
tabIndex=-1 tabIndex="-1"
@keyup="(e) => changeGlobalKey(e, index)" @keyup="(e) => changeGlobalKey(e, index)"
> >
{{ item.key }} {{ item.key }}
</div> </div>
</a-tooltip> </a-tooltip>
</div> </div>
<div class="short-cut item"> <div class="short-cut item">
<div>功能关键字</div> <div>功能关键字</div>
<a-input <a-input
:value="item.value" :value="item.value"
v-for="(item, index) in config.global" v-for="(item, index) in config.global"
class="value" class="value"
:disabled="!item.key" :disabled="!item.key"
@change="(e) => changeGlobalValue(index, e.target.value)" @change="(e) => changeGlobalValue(index, e.target.value)"
/> />
</div> </div>
</div> </div>
<div @click="addConfig" class="add-global"> + 新增全局快捷功能</div> <div @click="addConfig" class="add-global">+ 新增全局快捷功能</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import keycodes from '../../../assets/keycode'; import keycodes from "../../../assets/keycode";
import {ipcRenderer, remote} from 'electron'; import { ipcRenderer, remote } from "electron";
const opConfig = remote.getGlobal('opConfig'); const opConfig = remote.getGlobal("opConfig");
export default { export default {
data() { data() {
return { return {
currentSelect: [0], currentSelect: [0],
config: JSON.parse(JSON.stringify(opConfig.get())), config: { ...opConfig.get() },
examples: [ examples: [
{ {
title: '快捷键 「 Alt + W」 关键字 「 微信」', title: "快捷键 「 Alt + W」 关键字 「 微信」",
desc: '按下Alt + W 直接打开本地微信应用' desc: "按下Alt + W 直接打开本地微信应用",
}, },
{ {
title: '快捷键 「 Alt + Q」 关键字 「 取色」', title: "快捷键 「 Alt + Q」 关键字 「 取色」",
desc: '按下Alt + Q 直接打开屏幕取色功能' desc: "按下Alt + Q 直接打开屏幕取色功能",
} },
] ],
} };
}, },
methods: { methods: {
changeShortCut(e, key) { changeShortCut(e, key) {
let change = false; let change = false;
if(e.altKey && e.keyCode !== 18){ if (e.altKey && e.keyCode !== 18) {
const compose = `Option+${keycodes[e.keyCode].toUpperCase()}`; const compose = `Option+${keycodes[e.keyCode].toUpperCase()}`;
this.config.perf.shortCut[key] = compose; this.config.perf.shortCut[key] = compose;
change = true; change = true;
} }
if(e.ctrlKey && e.keyCode !== 17){ if (e.ctrlKey && e.keyCode !== 17) {
const compose = `Ctrl+${keycodes[e.keyCode].toUpperCase()}`; const compose = `Ctrl+${keycodes[e.keyCode].toUpperCase()}`;
this.config.perf.shortCut[key] = compose; this.config.perf.shortCut[key] = compose;
change = true; change = true;
} }
if(e.shiftKey && e.keyCode !== 16){ if (e.shiftKey && e.keyCode !== 16) {
const compose = `Shift+${keycodes[e.keyCode].toUpperCase()}`; const compose = `Shift+${keycodes[e.keyCode].toUpperCase()}`;
this.config.perf.shortCut[key] = compose; this.config.perf.shortCut[key] = compose;
change = true; change = true;
} }
if(e.metaKey && e.keyCode !== 93){ if (e.metaKey && e.keyCode !== 93) {
const compose = `Command+${keycodes[e.keyCode].toUpperCase()}`; const compose = `Command+${keycodes[e.keyCode].toUpperCase()}`;
this.config.perf.shortCut[key] = compose; this.config.perf.shortCut[key] = compose;
change = true; change = true;
@ -163,131 +205,129 @@ export default {
}, },
addConfig() { addConfig() {
this.config.global.push({ this.config.global.push({
key: '', key: "",
value: '' value: "",
}); });
}, },
changeGlobalKey(e, index) { changeGlobalKey(e, index) {
let compose; let compose;
if(e.altKey && e.keyCode !== 18){ if (e.altKey && e.keyCode !== 18) {
compose = `Alt+${keycodes[e.keyCode].toUpperCase()}`; compose = `Alt+${keycodes[e.keyCode].toUpperCase()}`;
} }
if(e.ctrlKey && e.keyCode !== 17){ if (e.ctrlKey && e.keyCode !== 17) {
compose = `Ctrl+${keycodes[e.keyCode].toUpperCase()}`; compose = `Ctrl+${keycodes[e.keyCode].toUpperCase()}`;
} }
if(e.shiftKey && e.keyCode !== 16){ if (e.shiftKey && e.keyCode !== 16) {
compose = `Shift+${keycodes[e.keyCode].toUpperCase()}`; compose = `Shift+${keycodes[e.keyCode].toUpperCase()}`;
} }
if(e.metaKey && e.keyCode !== 93){ if (e.metaKey && e.keyCode !== 93) {
compose = `Command+${keycodes[e.keyCode].toUpperCase()}`; compose = `Command+${keycodes[e.keyCode].toUpperCase()}`;
} }
if (compose) { if (compose) {
this.$set(this.config.global[index], 'key', compose); this.$set(this.config.global[index], "key", compose);
} }
// f1 - f12 // f1 - f12
if (e.keyCode >= 112 && e.keyCode <= 123) { if (e.keyCode >= 112 && e.keyCode <= 123) {
compose = keycodes[e.keyCode].toUpperCase(); compose = keycodes[e.keyCode].toUpperCase();
} }
if (compose) { if (compose) {
this.$set(this.config.global[index], 'key', compose); this.$set(this.config.global[index], "key", compose);
} }
}, },
changeGlobalValue(index, value) { changeGlobalValue(index, value) {
this.$set(this.config.global[index], 'value', value); this.$set(this.config.global[index], "value", value);
} },
}, },
watch: { watch: {
config: { config: {
deep: true, deep: true,
handler() { handler() {
opConfig.set('perf', this.config.perf); opConfig.set("perf", this.config.perf);
opConfig.set('superPanel', this.config.superPanel); opConfig.set("superPanel", this.config.superPanel);
opConfig.set('global', this.config.global); opConfig.set("global", this.config.global);
ipcRenderer.send('re-register'); ipcRenderer.send("re-register");
} },
} },
} },
} };
</script> </script>
<style lang="less"> <style lang="less">
.pg-settings { .pg-settings {
height: calc(~'100vh - 110px'); height: calc(~"100vh - 110px");
overflow: auto;
.dev-detail {
height: 100%;
display: flex;
align-items: flex-start;
background: #fff;
}
.settings-detail {
padding: 20px;
box-sizing: border-box;
flex: 1;
overflow: auto; overflow: auto;
.dev-detail { height: 100%;
height: 100%; .setting-item {
display: flex; margin-bottom: 20px;
align-items: flex-start; .ant-form-item {
background: #fff; margin-bottom: 0;
} }
.settings-detail { .title {
padding: 20px; color: #6c9fe2;
box-sizing: border-box; font-size: 15px;
flex: 1; margin-bottom: 10px;
overflow: auto; }
height: 100%; .settings-item-li {
.setting-item { padding-left: 20px;
margin-bottom: 20px; display: flex;
.ant-form-item { width: 100%;
margin-bottom: 0; align-items: center;
justify-content: space-between;
margin-bottom: 10px;
.label {
color: #646464;
} }
.title { .value {
color: #6C9FE2; width: 300px;
font-size: 15px; text-align: center;
margin-bottom: 10px; border: 1px solid #ddd;
} color: #6c9fe2;
.settings-item-li { font-size: 14px;
padding-left: 20px; height: 24px;
display: flex; font-weight: lighter;
width: 100%;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
.label {
color: #646464;
}
.value {
width: 300px;
text-align: center;
border: 1px solid #ddd;
color: #6C9FE2;
font-size: 14px;
height: 24px;
font-weight: lighter;
}
} }
} }
} }
.feature-container {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 10px;
font-size: 14px;
.item {
flex: 1;
}
.short-cut {
margin-left: 20px;
}
.value {
text-align: center;
border: 1px solid #ddd;
color: #6C9FE2;
font-size: 14px;
height: 24px;
font-weight: lighter;
margin-top: 10px;
}
}
.add-global {
color: #6C9FE2;
margin-top: 20px;
width: 100%;
text-align: center;
cursor: pointer;
}
} }
.feature-container {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 10px;
font-size: 14px;
.item {
flex: 1;
}
.short-cut {
margin-left: 20px;
}
.value {
text-align: center;
border: 1px solid #ddd;
color: #6c9fe2;
font-size: 14px;
height: 24px;
font-weight: lighter;
margin-top: 10px;
}
}
.add-global {
color: #6c9fe2;
margin-top: 20px;
width: 100%;
text-align: center;
cursor: pointer;
}
}
</style> </style>