Skip to content

Commit c671cfd

Browse files
committed
优化:剪切板自动粘贴逻辑优化
1 parent 9f42b98 commit c671cfd

4 files changed

Lines changed: 23 additions & 3 deletions

File tree

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ window.__page.onPluginInit((data: {
4747
alwaysOnTop: boolean
4848
}
4949
}) => {
50-
console.log('main.onPluginInit', data)
50+
// console.log('main.onPluginInit', data)
5151
manager.setActivePlugin(data.plugin)
5252
manager.setSubInput({
5353
placeholder: '',

src/lib/util.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ export const StringUtil = {
2727
}
2828

2929
export const TimeUtil = {
30+
timestamp() {
31+
return Math.floor(Date.now() / 1000)
32+
},
3033
timestampMS() {
31-
return new Date().getTime()
34+
return Date.now()
3235
},
3336
format(time: number, format: string = 'YYYY-MM-DD HH:mm:ss') {
3437
return dayjs(time).format(format)

src/pages/Main/Lib/entryListener.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {useManagerStore} from "../../../store/modules/manager";
22
import {ClipboardDataType, SelectedContent} from "../../../types/Manager";
3+
import {TimeUtil} from "../../../lib/util";
34

45
const manager = useManagerStore()
56

@@ -18,6 +19,14 @@ export const EntryListener = {
1819

1920
// console.log('EntryListener.prepareSearch', option)
2021

22+
// 清除搜索框
23+
if (manager.searchValue) {
24+
// 如果10分钟未变化,清空搜索框
25+
if (manager.searchValueUpdateTimestamp > 0 && manager.searchValueUpdateTimestamp < TimeUtil.timestamp() - 10 * 60) {
26+
manager.searchValue = ''
27+
}
28+
}
29+
2130
let searchValue = manager.searchValue
2231

2332
// 选中,只有快捷面板才获取
@@ -29,7 +38,12 @@ export const EntryListener = {
2938
const clipboardContent: ClipboardDataType | null = await window.$mapi.manager.getClipboardContent()
3039
const clipboardChangeTime = await window.$mapi.manager.getClipboardChangeTime()
3140
// 最近6秒内的剪切板变更才会被视为有效
32-
const useClipboard = clipboardChangeTime > Date.now() / 1000 - 6
41+
let useClipboard = false
42+
if (manager.searchValueUpdateTimestamp > 0 && !manager.searchValue) {
43+
if (clipboardChangeTime > TimeUtil.timestamp() - 6) {
44+
useClipboard = true
45+
}
46+
}
3347

3448
// 文件
3549
manager.setCurrentFiles([])

src/store/modules/manager.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import debounce from "lodash/debounce";
1010
import {WindowConfig} from "../../../electron/config/window";
1111
import {computed, toRaw} from "vue";
12+
import {TimeUtil} from "../../lib/util";
1213

1314
const searchFastPanelActionDebounce = debounce((query, cb) => {
1415
window.$mapi.manager.searchFastPanelAction(query)
@@ -33,6 +34,7 @@ export const managerStore = defineStore("manager", {
3334
config: {} as ConfigRecord,
3435
searchLoading: false,
3536
searchLastKeywords: '',
37+
searchValueUpdateTimestamp: 0,
3638
searchValue: '',
3739
searchPlaceholder: 'FocusAny,让您的工作专注高效',
3840
searchSubPlaceholder: '',
@@ -141,6 +143,7 @@ export const managerStore = defineStore("manager", {
141143
}
142144
this.searchLoading = true
143145
this.searchValue = keywords
146+
this.searchValueUpdateTimestamp = TimeUtil.timestamp()
144147
this.viewActions = []
145148
searchDebounce({
146149
keywords,

0 commit comments

Comments
 (0)