Skip to content

Commit 8051f0a

Browse files
committed
以图搜图 添加新引擎
1 parent 95ad113 commit 8051f0a

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

Diff for: src/main/main.ts

+11
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,12 @@ async function createMainWindow(op: MainWinType) {
13621362
// 确保切换到index时能传递window_name
13631363
mainWindow.webContents.send("text", windowName, op);
13641364

1365+
if (op.type === "image" && op.arg0 === "ai") {
1366+
createBrowser(windowName, "http://ai-v.netlify.app").then((c) => {
1367+
c.executeJavaScript(`setImg("${op.content}")`);
1368+
});
1369+
}
1370+
13651371
if (mainWindow.html) {
13661372
mainWindow.webContents.send("html", mainWindow.html);
13671373
}
@@ -1528,6 +1534,11 @@ async function createBrowser(windowName: number, url: string) {
15281534
rendererPath(searchView.webContents, "browser_bg.html", { query: { type: "certificate-error" } });
15291535
if (dev) searchView.webContents.openDevTools();
15301536
});
1537+
return new Promise((resolve: (x: Electron.WebContents) => void) => {
1538+
searchView.webContents.on("did-finish-load", () => {
1539+
resolve(searchView.webContents);
1540+
});
1541+
});
15311542
}
15321543
/**
15331544
* 标签页事件

Diff for: src/renderer/capture.html

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<div id="tool_search" title="以图搜图">
4545
<img src="./assets/icons/search.svg" class="icon">
4646
<select name="识图引擎" id="识图引擎" class="side_select">
47+
<option value="ai">AI</option>
4748
<option value="baidu">百度</option>
4849
<option value="yandex">Yandex</option>
4950
<option value="google">Google</option>

Diff for: src/renderer/clip/clip_window.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ document.getElementById("tool_search").title = `以图搜图 - ${识图引擎.va
686686
function runSearch() {
687687
const type = 识图引擎.value;
688688
getClipPhoto("png").then((c: HTMLCanvasElement) => {
689-
ipcRenderer.send("clip_main_b", "search", [c.toDataURL().replace(/^data:image\/\w+;base64,/, ""), type]);
689+
ipcRenderer.send("clip_main_b", "search", [c.toDataURL(), type]);
690690
});
691691
tool.close();
692692
}

Diff for: src/renderer/editor/editor.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1578,6 +1578,7 @@ window.onbeforeunload = () => {
15781578
/************************************以图搜图 */
15791579

15801580
function searchImg(img: string, type: "baidu" | "yandex" | "google", callback: Function) {
1581+
img = img.replace(/^data:image\/\w+;base64,/, "");
15811582
switch (type) {
15821583
case "baidu":
15831584
baidu(img, (err, url) => {

0 commit comments

Comments
 (0)