Skip to content

Commit 735a450

Browse files
authored
Merge pull request rubickCenter#81 from rubickCenter/feat-dev
LGTM
2 parents 8521262 + 417ab07 commit 735a450

File tree

9 files changed

+50
-44
lines changed

9 files changed

+50
-44
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rubick",
3-
"version": "2.0.1-beta.15",
3+
"version": "2.0.1-beta.16",
44
"private": true,
55
"scripts": {
66
"serve": "vue-cli-service serve",
@@ -19,11 +19,11 @@
1919
"ant-design-vue": "^2.2.8",
2020
"core-js": "^3.6.5",
2121
"cross-spawn": "^7.0.3",
22+
"electron-clipboard-ex": "^1.3.3",
2223
"extract-file-icon": "^0.3.2",
2324
"fix-path": "^3.0.0",
2425
"get-mac-apps": "^1.0.2",
2526
"got": "^11.8.3",
26-
"libnpmsearch": "^3.1.2",
2727
"lodash.throttle": "^4.1.1",
2828
"pouchdb": "^7.2.2",
2929
"vue": "^3.0.0",

src/common/utils/getCopyFiles.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ export default function getCopyFiles(): Array<any> | null {
1717
return null;
1818
}
1919
} else if (commonConst.windows()) {
20-
const filePath = clipboard.readBuffer('FileNameW').toString('ucs2').replace(RegExp(String.fromCharCode(0), 'g'), '');
21-
fileInfo = [filePath];
20+
/* eslint-disable */
21+
const clipboardEx = require("electron-clipboard-ex");
22+
fileInfo = clipboardEx.readFilePaths();
2223
// todo
2324
} else {
2425
if (!commonConst.linux()) return null;

src/core/plugin-handler/index.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
AdapterInfo,
44
} from "@/core/plugin-handler/types";
55
import fs from "fs-extra";
6-
import search, { Result } from "libnpmsearch";
76
import path from "path";
87
import got from "got";
98
import fixPath from "fix-path";
@@ -90,30 +89,6 @@ class AdapterHandler {
9089
await this.execCommand(installCmd, adapters);
9190
}
9291

93-
/**
94-
* 从 npm 搜索插件
95-
* 传入 streamFunc 可以流式处理
96-
* @param {string} adapter 插件名称
97-
* @param {(data: Result) => void} [streamFunc] 流式处理钩子
98-
* @memberof AdapterHandler
99-
*/
100-
async search(adapter: string, streamFunc?: (data: Result) => void) {
101-
return await new Promise<Result[]>((resolve, reject) => {
102-
const result: Result[] = [];
103-
const stream = search.stream(adapter);
104-
stream.on("data", (data: Result) => {
105-
result.push(data);
106-
if (streamFunc !== undefined) streamFunc(data);
107-
});
108-
stream.on("end", () => {
109-
resolve(result);
110-
});
111-
stream.on("error", (e: any) => {
112-
reject(e);
113-
});
114-
});
115-
}
116-
11792
/**
11893
* 更新指定插件
11994
* @param {...string[]} adapters 插件名称

src/main/browsers/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export default () => {
3434
// Load the index.html when not in development
3535
win.loadURL("app://./index.html");
3636
}
37-
3837
protocol.interceptFileProtocol("image", (req, callback) => {
3938
const url = req.url.substr(8);
4039
callback(decodeURI(url));

src/renderer/components/result.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div v-show="!!options.length && (searchValue || !!clipboardFile.length) && !currentPlugin.name" class="options" ref="scrollDom">
3-
<a-list item-layout="horizontal" :dataSource="options">
3+
<a-list item-layout="horizontal" :dataSource="sort(options)">
44
<template #renderItem="{ item, index }">
55
<a-list-item
66
@click="() => item.click()"
@@ -66,6 +66,20 @@ const renderDesc = (desc) => {
6666
}
6767
return desc;
6868
};
69+
70+
const sort = (options) => {
71+
for (let i = 0; i < options.length; i++) {
72+
for (let j = i + 1; j < options.length; j++) {
73+
if (options[j].zIndex > options[i].zIndex) {
74+
let temp = options[i];
75+
options[i] = options[j];
76+
options[j] = temp;
77+
}
78+
}
79+
}
80+
return options;
81+
};
82+
6983
</script>
7084

7185
<style lang="less">

src/renderer/components/search.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<div class="select-tag" v-show="currentPlugin.cmd">{{ currentPlugin.cmd }}</div>
44
<div :class="clipboardFile[0].name ? 'clipboard-tag' : 'clipboard-img'" v-if="!!clipboardFile.length">
55
<img :src="getIcon()" />
6-
{{ clipboardFile[0].name }}
6+
<div class="ellipse">{{ clipboardFile[0].name }}</div>
7+
<a-tag color="#aaa" v-if="clipboardFile.length > 1">{{ clipboardFile.length }}</a-tag>
78
</div>
89
<a-input
910
id="search"
@@ -177,7 +178,7 @@ const changeHideOnBlur = () => {
177178
const getIcon = () => {
178179
if (props.clipboardFile[0].dataUrl) return props.clipboardFile[0].dataUrl;
179180
return props.clipboardFile[0].isFile ? require("../assets/file.png") : require("../assets/folder.png")
180-
}
181+
};
181182
182183
const newWindow = () => {
183184
ipcRenderer.send("msg-trigger", {
@@ -197,6 +198,12 @@ const newWindow = () => {
197198
left: 0;
198199
width: 100%;
199200
align-items: center;
201+
.ellipse {
202+
overflow: hidden;
203+
text-overflow: ellipsis;
204+
white-space: nowrap;
205+
max-width: 200px;
206+
}
200207
.select-tag {
201208
white-space: pre;
202209
user-select: none;

src/renderer/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createApp } from "vue";
2-
import { Button, List, Spin, Input, Avatar } from "ant-design-vue";
2+
import { Button, List, Spin, Input, Avatar, Tag } from "ant-design-vue";
33
import App from "./App.vue";
44

55
createApp(App)
@@ -8,4 +8,5 @@ createApp(App)
88
.use(Spin)
99
.use(Input)
1010
.use(Avatar)
11+
.use(Tag)
1112
.mount("#app");

src/renderer/plugins-manager/clipboardWatch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ export default ({
120120
clearClipboardFile();
121121
window.setSubInputValue({ value: contentText });
122122
}
123+
clipboard.clear();
123124
}
124-
clipboard.clear();
125125
};
126126

127127
const clearClipboardFile = () => {

src/renderer/plugins-manager/options.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,18 @@ const optionsManager = ({
5454
icon: plugin.logo,
5555
desc: fe.explain,
5656
type: plugin.pluginType,
57+
zIndex: cmd.label ? 0 : 1, // 排序权重
5758
click: () => {
5859
pluginClickEvent({
5960
plugin,
6061
fe,
6162
cmd,
6263
ext: cmd.type
6364
? {
64-
code: fe.code,
65-
type: cmd.type || "text",
66-
payload: searchValue.value,
67-
}
65+
code: fe.code,
66+
type: cmd.type || "text",
67+
payload: searchValue.value,
68+
}
6869
: null,
6970
openPlugin,
7071
});
@@ -101,14 +102,17 @@ const optionsManager = ({
101102
}
102103
})
103104
.map((plugin) => {
104-
plugin.click = () => {
105-
openPlugin(plugin);
105+
return {
106+
...plugin,
107+
zIndex: 1,
108+
click: () => {
109+
openPlugin(plugin);
110+
},
106111
};
107-
return plugin;
108112
}),
109113
];
110114
return options;
111-
}
115+
};
112116

113117
watch(searchValue, () => search(searchValue.value));
114118
// search Input operation
@@ -126,7 +130,12 @@ const optionsManager = ({
126130
optionsRef.value = options;
127131
};
128132

129-
const { searchFocus, clipboardFile, clearClipboardFile, readClipboardContent } = useFocus({
133+
const {
134+
searchFocus,
135+
clipboardFile,
136+
clearClipboardFile,
137+
readClipboardContent,
138+
} = useFocus({
130139
currentPlugin,
131140
optionsRef,
132141
openPlugin,

0 commit comments

Comments
 (0)