Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

feat: completely remove BetterQQNT support #158

Merged
merged 1 commit into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

**请务必仔细阅读本章节内容以避免不必要的麻烦!**

QQNTim 支持 LiteLoader,但**不支持 BetterQQNT**。

> ### LiteLoader 相关安装教程:
>
> #### 如果你已经安装了 LiteLoader,想安装 QQNTim:
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/settings/src/panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function SettingsPanel({ qqntim, config, setConfig }: PanelsProps) {
],
[
"禁用兼容性处理",
"禁用后,LiteLoader 和 BetterQQNT 可能将不能与 QQNTim 一起使用。",
"禁用后,LiteLoader 可能将不能与 QQNTim 一起使用。",
config.disableCompatibilityProcessing,
(state) =>
setConfig((prev) => {
Expand Down
7 changes: 0 additions & 7 deletions src/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ import { QQNTim } from "@flysoftbeta/qqntim-typings";

const interruptIpcs: [QQNTim.IPC.InterruptFunction, QQNTim.IPC.InterruptIPCOptions | undefined][] = [];

function wrapIpc(args: QQNTim.IPC.Args<any>, direction: QQNTim.IPC.Direction) {
if (direction == "out" && (!args[0] || !args[0]?.eventName)) return [{ eventName: "QQNTIM_WRAPPER", type: "request" }, args];
else if (direction == "in" && args[0]?.eventName == "QQNTIM_WRAPPER") return args[1];
return args;
}

function interruptIpc(args: QQNTim.IPC.Args<any>, direction: QQNTim.IPC.Direction, channel: string, sender?: Electron.WebContents) {
for (const [func, options] of interruptIpcs) {
if (options?.cmdName && (!args[1] || (args[1][0]?.cmdName != options?.cmdName && args[1][0] != options?.cmdName))) continue;
Expand All @@ -26,7 +20,6 @@ function interruptIpc(args: QQNTim.IPC.Args<any>, direction: QQNTim.IPC.Directio

export function handleIpc(args: QQNTim.IPC.Args<any>, direction: QQNTim.IPC.Direction, channel: string, sender?: Electron.WebContents) {
if (args[0]?.eventName?.startsWith("ns-LoggerApi-")) return false;
wrapIpc(args, direction);
return interruptIpc(args, direction, channel, sender);
}

Expand Down
16 changes: 8 additions & 8 deletions src/main/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ipcMain.on("___!boot", (event) => {
if (!event.returnValue) event.returnValue = { enabled: false };
});

ipcMain.handle("___!dialog", (event, _, method: string, options: object) => dialog[method](BrowserWindow.fromWebContents(event.sender), options));
ipcMain.handle("___!dialog", (event, method: string, options: object) => dialog[method](BrowserWindow.fromWebContents(event.sender), options));

function patchBrowserWindow(BrowserWindow: typeof Electron.BrowserWindow) {
const windowMenu: Electron.MenuItem[] = [
Expand Down Expand Up @@ -106,12 +106,12 @@ function patchBrowserWindow(BrowserWindow: typeof Electron.BrowserWindow) {
handleIpc(args, "out", channel);
return send.call(win.webContents, channel, ...args);
};
win.webContents.on("ipc-message", (_, channel, ...args: QQNTim.IPC.Args<any>) => {
if (!handleIpc(args, "in", channel, win.webContents)) throw new Error("QQNTim 已强行中断了一条 IPC 消息");
if (channel == "___!apply_plugins") applyPlugins(plugins, args[1] as string);
win.webContents.on("ipc-message", (_, channel, ...args) => {
if (!handleIpc(args as any, "in", channel, win.webContents)) throw new Error("QQNTim 已强行中断了一条 IPC 消息");
if (channel == "___!apply_plugins") applyPlugins(plugins, args[0] as string);
});
win.webContents.on("ipc-message-sync", (event, channel, ...args: QQNTim.IPC.Args<any>) => {
handleIpc(args, "in", channel, win.webContents);
win.webContents.on("ipc-message-sync", (event, channel, ...args) => {
handleIpc(args as any, "in", channel, win.webContents);
if (channel == "___!boot") {
event.returnValue = {
enabled: true,
Expand All @@ -122,9 +122,9 @@ function patchBrowserWindow(BrowserWindow: typeof Electron.BrowserWindow) {
env: env,
};
} else if (channel == "___!browserwindow_api") {
event.returnValue = win[args[1][0]](...args[1][1]);
event.returnValue = win[args[0][0]](...args[0][1]);
} else if (channel == "___!app_api") {
event.returnValue = app[args[1][0]](...args[1][1]);
event.returnValue = app[args[0][0]](...args[0][1]);
}
});
if (!env.config.useNativeDevTools)
Expand Down
24 changes: 3 additions & 21 deletions src/renderer/api/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,16 @@ import { ipcRenderer } from "electron";

class AppAPI implements QQNTim.API.Renderer.AppAPI {
relaunch() {
ipcRenderer.sendSync(
"___!app_api",
{
eventName: "QQNTIM_APP_API",
},
["relaunch", []],
);
ipcRenderer.sendSync("___!app_api", ["relaunch", []]);
this.quit();
}

quit() {
ipcRenderer.sendSync(
"___!app_api",
{
eventName: "QQNTIM_APP_API",
},
["quit", []],
);
ipcRenderer.sendSync("___!app_api", ["quit", []]);
}

exit() {
ipcRenderer.sendSync(
"___!app_api",
{
eventName: "QQNTIM_APP_API",
},
["exit", []],
);
ipcRenderer.sendSync("___!app_api", ["exit", []]);
}
}

Expand Down
17 changes: 3 additions & 14 deletions src/renderer/api/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@ import { QQNTim } from "@flysoftbeta/qqntim-typings";
import { ipcRenderer } from "electron";

class DialogAPI implements QQNTim.API.Renderer.DialogAPI {
private api<R, T>(method: string, options: T): Promise<R> {
return ipcRenderer.invoke(
"___!dialog",
{
eventName: "QQNTIM_DIALOG_API",
},
method,
options,
) as Promise<R>;
}

async confirm(message = "") {
const res = await this.messageBox({ message, buttons: ["确定", "取消"], defaultId: 0, type: "question" });
return res.response == 0;
Expand All @@ -24,15 +13,15 @@ class DialogAPI implements QQNTim.API.Renderer.DialogAPI {
}

messageBox(options: Electron.MessageBoxOptions): Promise<Electron.MessageBoxReturnValue> {
return this.api("showMessageBox", options);
return ipcRenderer.invoke("___!dialog", "showMessageBox", options);
}

openDialog(options: Electron.OpenDialogOptions): Promise<Electron.OpenDialogReturnValue> {
return this.api("showOpenDialog", options);
return ipcRenderer.invoke("___!dialog", "showOpenDialog", options);
}

saveDialog(options: Electron.SaveDialogOptions): Promise<Electron.SaveDialogReturnValue> {
return this.api("showSaveDialog", options);
return ipcRenderer.invoke("___!dialog", "showSaveDialog", options);
}
}

Expand Down
9 changes: 1 addition & 8 deletions src/renderer/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,7 @@ export function applyPlugins(allPlugins: QQNTim.Plugin.AllUsersPlugins, uin = ""

windowLoadPromise.then(() => applyStylesheets());

if (uin != "")
ipcRenderer.send(
"___!apply_plugins",
{
eventName: "QQNTIM_APPLY_PLUGINS",
},
uin,
);
if (uin != "") ipcRenderer.send("___!apply_plugins", uin);

return true;
}
Expand Down
7 changes: 2 additions & 5 deletions src/renderer/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import { ipcRenderer } from "electron";
import * as React from "react";
import * as ReactDOMClient from "react-dom/client";

export const { enabled, preload, debuggerOrigin, webContentsId, plugins, env } = ipcRenderer.sendSync("___!boot", {
eventName: "QQNTIM_BOOT",
});
export const { enabled, preload, debuggerOrigin, webContentsId, plugins, env } = ipcRenderer.sendSync("___!boot");

patchElectron();
if (enabled) {
setEnv(env);
setAllPlugins(plugins);
Expand All @@ -37,6 +36,4 @@ if (enabled) {
}, 1);
}

patchElectron();

preload.forEach((item: string) => require(item));