-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from WJZ-P/master
基于较新版QQ所作的更新
- Loading branch information
Showing
5 changed files
with
151 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,99 @@ | ||
const { ipcMain, dialog, shell, clipboard } = require("electron"); | ||
const {ipcMain, dialog, shell, clipboard} = require("electron"); | ||
const fs = require("fs"); | ||
const exec = require("child_process").exec; | ||
// const QrScanner = require("qr-scanner"); | ||
var defaultBrowser = LiteLoader.api.config.get("qr_decode", { | ||
browser: "", | ||
browser: "", | ||
}); | ||
|
||
|
||
onLoad(); | ||
|
||
function openUrl(url) { | ||
if ( | ||
(defaultBrowser?.browser ?? "") != "" && | ||
fs.existsSync(defaultBrowser.browser) | ||
) { | ||
var cmd = '"' + defaultBrowser.browser + '"' + ' "' + url + '"'; | ||
if ( | ||
(defaultBrowser?.browser ?? "") != "" && | ||
fs.existsSync(defaultBrowser.browser) | ||
) { | ||
var cmd = '"' + defaultBrowser.browser + '"' + ' "' + url + '"'; | ||
|
||
exec(cmd); | ||
} else { | ||
shell.openExternal(url); | ||
} | ||
exec(cmd); | ||
} else { | ||
shell.openExternal(url); | ||
} | ||
} | ||
|
||
function onLoad() { | ||
ipcMain.handle("LiteLoader.qr_decode.showFailed", (_, data) => { | ||
dialog.showMessageBox({ | ||
type: "error", | ||
title: "提示", | ||
message: | ||
"这可能不是一个有效的二维码,解码失败。\n错误信息为:" + data?.stack, | ||
buttons: ["确定"], | ||
ipcMain.handle("LiteLoader.qr_decode.showFailed", (_, data) => { | ||
dialog.showMessageBox({ | ||
type: "error", | ||
title: "提示", | ||
message: | ||
"这可能不是一个有效的二维码,解码失败。\n错误信息为:" + data?.stack, | ||
buttons: ["确定"], | ||
}); | ||
}); | ||
}); | ||
|
||
ipcMain.handle("LiteLoader.qr_decode.showResult", (_, data) => { | ||
var content = data; | ||
|
||
if (content == null) { | ||
dialog.showMessageBox({ | ||
type: "warning", | ||
title: "提示", | ||
message: "这可能不是一个有效的二维码,解码失败。", | ||
buttons: ["确定"], | ||
}); | ||
return; | ||
} | ||
// ipcMain.handle("LiteLoader.qr_decode.decodeLocally", async (_, imgPath) => { | ||
// console.log('图片的路径为:' + imgPath) | ||
// let result = await QrScanner.scanImage(imgPath); | ||
// console.log(result) | ||
// return result | ||
// } | ||
// ) | ||
|
||
var isUrl = | ||
/^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\*\+,;=.]+$/.test( | ||
content | ||
); | ||
ipcMain.handle("LiteLoader.qr_decode.showResult", (_, data) => { | ||
var content = data; | ||
|
||
var btns = ["复制", "什么都不做"]; | ||
var cancelId = 1; | ||
if (isUrl) { | ||
btns.unshift("打开链接"); | ||
cancelId = 2; | ||
} | ||
dialog | ||
.showMessageBox({ | ||
type: "info", | ||
title: "提示", | ||
message: `解析结果为:\n${content}\n你想对解析内容做什么?`, | ||
buttons: btns, | ||
cancelId: cancelId, | ||
}) | ||
.then((idx) => { | ||
//第一个按钮 | ||
if (idx.response == 0) { | ||
if (isUrl) { | ||
//打开URL | ||
openUrl(content); | ||
} else { | ||
//复制内容 | ||
clipboard.writeText(content); | ||
} | ||
if (content == null) { | ||
dialog.showMessageBox({ | ||
type: "warning", | ||
title: "提示", | ||
message: "这可能不是一个有效的二维码,解码失败。", | ||
buttons: ["确定"], | ||
}); | ||
return; | ||
} | ||
//第二个按钮 | ||
else if (idx.response == 1) { | ||
if (isUrl) { | ||
//复制内容 | ||
clipboard.writeText(content); | ||
} else { | ||
//取消 | ||
} | ||
} else { | ||
//取消 | ||
var isUrl = | ||
/^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\*\+,;=.]+$/.test( | ||
content | ||
); | ||
|
||
var btns = ["复制", "什么都不做"]; | ||
var cancelId = 1; | ||
if (isUrl) { | ||
btns.unshift("打开链接"); | ||
cancelId = 2; | ||
} | ||
}); | ||
}); | ||
dialog | ||
.showMessageBox({ | ||
type: "info", | ||
title: "提示", | ||
message: `解析结果为:\n${content}\n你想对解析内容做什么?`, | ||
buttons: btns, | ||
cancelId: cancelId, | ||
}) | ||
.then((idx) => { | ||
//第一个按钮 | ||
if (idx.response == 0) { | ||
if (isUrl) { | ||
//打开URL | ||
openUrl(content); | ||
} else { | ||
//复制内容 | ||
clipboard.writeText(content); | ||
} | ||
} | ||
//第二个按钮 | ||
else if (idx.response == 1) { | ||
if (isUrl) { | ||
//复制内容 | ||
clipboard.writeText(content); | ||
} else { | ||
//取消 | ||
} | ||
} else { | ||
//取消 | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.