From 448d19d4022203e0e7f04025eb953ff12a0b105b Mon Sep 17 00:00:00 2001
From: Oyasuminasai <61616918+nfnfgo@users.noreply.github.com>
Date: Sun, 7 Jul 2024 13:38:35 +0800
Subject: [PATCH 1/8] feat: Update .gitignore
---
.gitignore | 1 +
1 file changed, 1 insertion(+)
diff --git a/.gitignore b/.gitignore
index 3c4a5fa..2c0f374 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,4 +5,5 @@ settings.json
# ignore dist/
dist
+log
release.zip
\ No newline at end of file
From bbfa34033d992a7f7722ac1106aa878daaa1de25 Mon Sep 17 00:00:00 2001
From: Oyasuminasai <61616918+nfnfgo@users.noreply.github.com>
Date: Sun, 7 Jul 2024 13:39:30 +0800
Subject: [PATCH 2/8] feat: Add log file persist support.
---
manifest.json | 2 +-
src/main.js | 82 ++++++++++++++++++------------------
src/preload.js | 21 ++++-----
src/utils/liteloader_type.ts | 53 +++++++++++++++++++----
src/utils/logger.ts | 9 +++-
src/utils/logger_main.ts | 46 ++++++++++++++++++++
tsconfig.json | 1 +
webpack.common.js | 8 ++--
8 files changed, 157 insertions(+), 65 deletions(-)
create mode 100644 src/utils/logger_main.ts
diff --git a/manifest.json b/manifest.json
index e775daf..6f22d4a 100644
--- a/manifest.json
+++ b/manifest.json
@@ -27,7 +27,7 @@
],
"injects": {
"renderer": "./dist/renderer.js",
- "main": "./src/main.js",
+ "main": "./dist/main.js",
"preload": "./src/preload.js"
}
}
\ No newline at end of file
diff --git a/src/main.js b/src/main.js
index cf40889..f228d30 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,58 +1,60 @@
// 运行在 Electron 主进程 下的插件入口
const { shell, ipcMain } = require("electron");
-const fs = require('fs/promises');
+import { generateMainProcessLogerWriter } from '@/utils/logger_main';
-const plugin_path = LiteLoader.plugins["markdown_it"].path.plugin;
+// const setttingsJsonFilePath = `${plugin_path}/settings.json`;
-// import { shell, ipcMain } from "electron";
+// async function getSettings(key) {
+// var json = JSON.parse(await fs.readFile(setttingsJsonFilePath));
+// return json[key];
+// }
-const setttingsJsonFilePath = `${plugin_path}/settings.json`;
+// async function updateSettings({ name, value }) {
+// var json = {};
+// try { json = JSON.parse(await fs.readFile(setttingsJsonFilePath)); } catch (e) {
+// ;
+// }
+// json[name] = value;
+// await fs.writeFile(setttingsJsonFilePath, JSON.stringify(json));
+// }
-async function getSettings(key) {
- var json = JSON.parse(await fs.readFile(setttingsJsonFilePath));
- return json[key];
-}
+// async function removeSettings(key) {
+// var json = JSON.parse(await fs.readFile(setttingsJsonFilePath));
+// json[key] = undefined;
+// await fs.writeFile(setttingsJsonFilePath, JSON.stringify(json));
+// }
-async function updateSettings({ name, value }) {
- var json = {};
- try { json = JSON.parse(await fs.readFile(setttingsJsonFilePath)); } catch (e) {
- ;
- }
- json[name] = value;
- await fs.writeFile(setttingsJsonFilePath, JSON.stringify(json));
-}
-
-async function removeSettings(key) {
- var json = JSON.parse(await fs.readFile(setttingsJsonFilePath));
- json[key] = undefined;
- await fs.writeFile(setttingsJsonFilePath, JSON.stringify(json));
-}
+const loggerWriter = generateMainProcessLogerWriter();
onLoad();
// 加载插件时触发
function onLoad() {
- ipcMain.handle("LiteLoader.markdown_it.open_link", (event, content) => {
- if (content.indexOf("http") != 0) {
- content = "http://" + content;
- }
- return shell.openExternal(content);
+ // ipcMain.handle("LiteLoader.markdown_it.open_link", (event, content) => {
+ // if (content.indexOf("http") != 0) {
+ // content = "http://" + content;
+ // }
+ // return shell.openExternal(content);
+ // });
+
+ // ipcMain.handle('LiteLoader.markdown_it.get_settings', (e, key) => {
+ // return getSettings(key);
+ // });
+
+ // ipcMain.handle('LiteLoader.markdown_it.update_settings', (e, { name, value }) => {
+ // return updateSettings({ name, value });
+ // });
+
+ // ipcMain.handle('LiteLoader.markdown_it.remove_settings', (e, key) => {
+ // return removeSettings(key);
+ // })
+
+ ipcMain.handle('LiteLoader.markdown_it.log', (e, consoleMode, ...args) => {
+ loggerWriter(consoleMode, ...args);
});
-
- ipcMain.handle('LiteLoader.markdown_it.get_settings', (e, key) => {
- return getSettings(key);
- });
-
- ipcMain.handle('LiteLoader.markdown_it.update_settings', (e, { name, value }) => {
- return updateSettings({ name, value });
- });
-
- ipcMain.handle('LiteLoader.markdown_it.remove_settings', (e, key) => {
- return removeSettings(key);
- })
}
// 这两个函数都是可选的
-module.exports = {
+export {
onLoad,
};
diff --git a/src/preload.js b/src/preload.js
index 2286ca7..17a5ab2 100644
--- a/src/preload.js
+++ b/src/preload.js
@@ -3,14 +3,15 @@ const { contextBridge, ipcRenderer } = require("electron");
// 在window对象下导出只读对象
contextBridge.exposeInMainWorld("markdown_it", {
- render: (content) =>
- ipcRenderer.invoke("LiteLoader.markdown_it.render", content),
- open_link: (content) =>
- ipcRenderer.invoke("LiteLoader.markdown_it.open_link", content),
- get_settings: (key) =>
- ipcRenderer.invoke("LiteLoader.markdown_it.get_settings", key),
- update_settings: ({ name, value }) =>
- ipcRenderer.invoke("LiteLoader.markdown_it.update_settings", { name, value }),
- remove_settings: (key) =>
- ipcRenderer.invoke("LiteLoader.markdown_it.remove_settings", key),
+ // render: (content) =>
+ // ipcRenderer.invoke("LiteLoader.markdown_it.render", content),
+ // open_link: (content) =>
+ // ipcRenderer.invoke("LiteLoader.markdown_it.open_link", content),
+ // get_settings: (key) =>
+ // ipcRenderer.invoke("LiteLoader.markdown_it.get_settings", key),
+ // update_settings: ({ name, value }) =>
+ // ipcRenderer.invoke("LiteLoader.markdown_it.update_settings", { name, value }),
+ // remove_settings: (key) =>
+ // ipcRenderer.invoke("LiteLoader.markdown_it.remove_settings", key),
+ log: (consoleType, ...args) => ipcRenderer.invoke('LiteLoader.markdown_it.log', consoleType, ...args),
});
diff --git a/src/utils/liteloader_type.ts b/src/utils/liteloader_type.ts
index 03c3527..6cc9379 100644
--- a/src/utils/liteloader_type.ts
+++ b/src/utils/liteloader_type.ts
@@ -3,13 +3,50 @@
*
* Notice the `new_config` and `default_config` should all be a Object. Passing string will cause unexpected behaviour.
*/
-export interface LiteLoaderInterFace {
+
+export interface LiteLoaderInterFace {
+ path: {
+ root: string; // 本体目录路径
+ profile: string; // 存储目录路径(如果指定了 LITELOADERQQNT_PROFILE 环境变量)
+ data: string; // 数据目录路径
+ plugins: string; // 插件目录路径
+ };
+ versions: {
+ qqnt: string; // QQNT 版本号
+ liteloader: string; // LiteLoaderQQNT 版本号
+ node: string; // Node.js 版本号
+ chrome: string; // Chrome 版本号
+ electron: string; // Electron 版本号
+ };
+ os: {
+ platform: string; // 系统平台名称
+ };
+ package: {
+ liteloader: object; // LiteLoaderQQNT package.json 文件内容
+ qqnt: object; // QQNT package.json 文件内容
+ };
+ plugins: {
+ markdown_it: {
+ incompatible: boolean; // 插件是否兼容
+ disabled: boolean; // 插件是否禁用
+ manifest: object; // 插件 manifest.json 文件内容
+ path: {
+ plugin: string; // 插件本体根目录路径
+ data: string; // 插件数据根目录路径
+ injects: {
+ main: string; // 插件主进程脚本文件路径
+ renderer: string; // 插件渲染进程脚本文件路径
+ preload: string; // 插件预加载脚本文件路径
+ };
+ };
+ };
+ };
api: {
- openPath(path: string): any;
- openExternal(uri: string): any;
+ openPath(path: string): void; // 打开指定目录
+ openExternal(uri: string): void; // 打开外部连接
config: {
- set(slug: string, new_config: T): Promise;
- get(slug: string, default_config: T): Promise;
- }
- },
-};
\ No newline at end of file
+ set(slug: string, newConfig: ConfigInfoType): Promise; // 设置配置文件
+ get(slug: string, defaultConfig: ConfigInfoType): Promise; // 获取配置文件
+ };
+ };
+}
diff --git a/src/utils/logger.ts b/src/utils/logger.ts
index c49c477..bdd2ed8 100644
--- a/src/utils/logger.ts
+++ b/src/utils/logger.ts
@@ -4,6 +4,10 @@
import { useSettingsStore } from '@/states/settings';
+declare const markdown_it: {
+ log: (consoleType: string, ...args: any[]) => any
+};
+
type DistributiveFilter = Origin extends Filter ? Origin : never;
/**
@@ -32,6 +36,8 @@ function showOuputToConsole() {
* ```
*/
export function mditLogger(consoleFunction: SupportedLoggerFuncKey, ...params: any[]) {
+ markdown_it.log(consoleFunction, ...params);
+
if (!showOuputToConsole()) {
return undefined;
}
@@ -39,5 +45,4 @@ export function mditLogger(consoleFunction: SupportedLoggerFuncKey, ...params: a
'%c [MarkdownIt] ',
'background-color: rgba(0, 149, 204, 0.8); border-radius: 6px;padding-block: 2px; padding-inline: 0px; color: white;',
...params);
-}
-
+}
\ No newline at end of file
diff --git a/src/utils/logger_main.ts b/src/utils/logger_main.ts
new file mode 100644
index 0000000..2a9d928
--- /dev/null
+++ b/src/utils/logger_main.ts
@@ -0,0 +1,46 @@
+import * as path from 'path';
+import { existsSync, mkdirSync, createWriteStream } from 'fs';
+import { writeFile } from 'fs/promises';
+import { LiteLoaderInterFace } from '@/utils/liteloader_type';
+
+declare const LiteLoader: LiteLoaderInterFace
);
+}
+
+function ButtonTile({ title, caption, href, path, callback, actionName }) {
+ callback ??= function () {
+ if (href !== undefined && href !== null) {
+ LiteLoader.api.openExternal(href);
+ return;
+ }
+ if (path !== undefined && path !== null) {
+ LiteLoader.api.openPath(path);
+ return;
+ }
+ mditLogger('debug', 'Button with no action clicked');
+
+ }
+
+ return (
+
+
+
+ {actionName}
+
+
+ );
}
\ No newline at end of file
From e304fe92ab7058a8f3d3d43e31556e426a4095ff Mon Sep 17 00:00:00 2001
From: Oyasuminasai <61616918+nfnfgo@users.noreply.github.com>
Date: Sun, 7 Jul 2024 20:06:05 +0800
Subject: [PATCH 6/8] fix: Fix ElementCapture `rendered` flag doesn't work.
---
src/utils/logger.ts | 31 +++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/src/utils/logger.ts b/src/utils/logger.ts
index 02689d2..a7952e6 100644
--- a/src/utils/logger.ts
+++ b/src/utils/logger.ts
@@ -89,23 +89,30 @@ export function elementDebugLogger() {
// Add flag class for all marked --mdit-debug-capture-element
Array.from(codeEle)
- .filter((ele) => !ele.classList.contains(loggedClassName)) // ensure one message box will only be logged one time
.filter((ele) => ele.innerHTML == logFlagClassName)
- .forEach((ele) => { ele.classList.add(logFlagClassName) });
+ .forEach((ele) => {
+ ele.classList.add(logFlagClassName);
+ });
// find all self sent message box that has been marked to capture, then log it.
var flaggedMsgBoxs = document.querySelectorAll(`div.message-content__wrapper div.container--self:has(.${logFlagClassName})`);
- Array.from(flaggedMsgBoxs).forEach((ele) => {
- // file-only logger
- mditLoggerGenerator({
- ...defaultMditLoggerOptions,
- consoleOutput: false,
- })('log', ele.outerHTML);
- ele.classList.add(loggedClassName);
+ var loggedCount = 0;
+ Array
+ .from(flaggedMsgBoxs)
+ .filter((ele) => !ele.classList.contains(loggedClassName)) // ensure one message box will only be logged one time
+ .forEach((ele) => {
+ // file-only logger
+ mditLoggerGenerator({
+ ...defaultMditLoggerOptions,
+ consoleOutput: false,
+ })('log', ele.outerHTML);
+
+ mditLogger('debug', `Element captured: ${ele.tagName}`);
- mditLogger('debug', `Element captured: ${ele.tagName}`);
- });
+ ele.classList.add(loggedClassName);
+ loggedCount++;
+ });
- mditLogger('info', 'Element Capture Finished:', `${flaggedMsgBoxs.length} element(s) has been logged`);
+ mditLogger('info', 'Element Capture Finished:', `${loggedCount} element(s) has been logged`);
}
\ No newline at end of file
From cb0a810a9f57439dcc82dd56422c31c5a9f02d87 Mon Sep 17 00:00:00 2001
From: Oyasuminasai <61616918+nfnfgo@users.noreply.github.com>
Date: Sun, 7 Jul 2024 23:55:44 +0800
Subject: [PATCH 7/8] feat: Add Github info in Settings UI.
---
src/components/setting_page.jsx | 16 ++++++------
src/main.js | 44 +++------------------------------
src/preload.js | 1 +
src/utils/logger_main.ts | 29 ++++++++++++++++++----
4 files changed, 37 insertions(+), 53 deletions(-)
diff --git a/src/components/setting_page.jsx b/src/components/setting_page.jsx
index 2194e64..99f37c4 100644
--- a/src/components/setting_page.jsx
+++ b/src/components/setting_page.jsx
@@ -13,11 +13,14 @@ export function SettingPage() {
-
- 设置更新
- 在此页面更新设置后,需要重启QQ后方可生效
-
+
+
+
+
+
+
+
@@ -101,8 +104,8 @@ export function SettingPage() {
@@ -175,7 +178,6 @@ function TextAndCaptionBlock({ title, caption }) {
'display': 'flex',
'flexWrap': 'wrap',
'flexDirection': 'column',
- // 'width': '92%',
'flex': '1 1 auto',
}}>
{title}
diff --git a/src/main.js b/src/main.js
index fc043bc..3a2faec 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,28 +1,6 @@
// 运行在 Electron 主进程 下的插件入口
const { ipcMain } = require("electron");
-import { generateMainProcessLogerWriter } from '@/utils/logger_main';
-
-// const setttingsJsonFilePath = `${plugin_path}/settings.json`;
-
-// async function getSettings(key) {
-// var json = JSON.parse(await fs.readFile(setttingsJsonFilePath));
-// return json[key];
-// }
-
-// async function updateSettings({ name, value }) {
-// var json = {};
-// try { json = JSON.parse(await fs.readFile(setttingsJsonFilePath)); } catch (e) {
-// ;
-// }
-// json[name] = value;
-// await fs.writeFile(setttingsJsonFilePath, JSON.stringify(json));
-// }
-
-// async function removeSettings(key) {
-// var json = JSON.parse(await fs.readFile(setttingsJsonFilePath));
-// json[key] = undefined;
-// await fs.writeFile(setttingsJsonFilePath, JSON.stringify(json));
-// }
+import { generateMainProcessLogerWriter, LogPathHelper } from '@/utils/logger_main';
const loggerWriter = generateMainProcessLogerWriter();
@@ -34,28 +12,12 @@ function onBrowserWindowCreated() {
// 加载插件时触发
function onLoad() {
- // ipcMain.handle("LiteLoader.markdown_it.open_link", (event, content) => {
- // if (content.indexOf("http") != 0) {
- // content = "http://" + content;
- // }
- // return shell.openExternal(content);
- // });
-
- // ipcMain.handle('LiteLoader.markdown_it.get_settings', (e, key) => {
- // return getSettings(key);
- // });
-
- // ipcMain.handle('LiteLoader.markdown_it.update_settings', (e, { name, value }) => {
- // return updateSettings({ name, value });
- // });
-
- // ipcMain.handle('LiteLoader.markdown_it.remove_settings', (e, key) => {
- // return removeSettings(key);
- // })
ipcMain.handle('LiteLoader.markdown_it.log', (e, consoleMode, ...args) => {
loggerWriter(consoleMode, ...args);
});
+
+ ipcMain.handle('LiteLoader.markdown_it.get_log_path', (e) => LogPathHelper.getLogFolderPath());
}
// 这两个函数都是可选的
diff --git a/src/preload.js b/src/preload.js
index 17a5ab2..37a1fe8 100644
--- a/src/preload.js
+++ b/src/preload.js
@@ -14,4 +14,5 @@ contextBridge.exposeInMainWorld("markdown_it", {
// remove_settings: (key) =>
// ipcRenderer.invoke("LiteLoader.markdown_it.remove_settings", key),
log: (consoleType, ...args) => ipcRenderer.invoke('LiteLoader.markdown_it.log', consoleType, ...args),
+ get_log_path: () => ipcRenderer.invoke('LiteLoader.markdown_it.get_log_path'),
});
diff --git a/src/utils/logger_main.ts b/src/utils/logger_main.ts
index 5a8504c..c63000e 100644
--- a/src/utils/logger_main.ts
+++ b/src/utils/logger_main.ts
@@ -5,13 +5,32 @@ import { LiteLoaderInterFace } from '@/utils/liteloader_type';
declare const LiteLoader: LiteLoaderInterFace;
-var _logWriter: any = undefined;
+export const LogPathHelper = {
+ getLogFolderPath() {
+ return path.join(LiteLoader.plugins.markdown_it.path.plugin, 'log');
+ },
+
+ /**
+ * Get absolute file path of a log file.
+ *
+ * @param logFileName Name of the log file. If `undefined`,
+ * will generate automatically based on current time.
+ */
+ getLogFilePath(logFileName?: string | undefined) {
+ // generate log file name if not received
+ logFileName ??= (new Date().toISOString()).replaceAll(':', '-');
+
+ return path.join(LiteLoader.plugins.markdown_it.path.plugin, 'log', `${logFileName}.log`);
+ }
+};
+/**
+ * Generate a writer function that used to write log into log file.
+ */
export function generateMainProcessLogerWriter() {
- var startTimeStr: string = new Date().toISOString();
- startTimeStr = startTimeStr.replaceAll(':', '-');
- var logFolderPath = path.join(LiteLoader.plugins.markdown_it.path.plugin, 'log');
- var logFilePath = path.join(LiteLoader.plugins.markdown_it.path.plugin, 'log', `${startTimeStr}.log`);
+ var logFolderPath = LogPathHelper.getLogFolderPath();
+ var logFilePath = LogPathHelper.getLogFilePath();
+
console.log(`[markdown-it] logFolderPath: ${logFolderPath}`);
console.log(`[markdown-it] logFilePath: ${logFilePath}`);
From f890d834e1948d5eb3de1a44a2f03d628a0933f1 Mon Sep 17 00:00:00 2001
From: Oyasuminasai <61616918+nfnfgo@users.noreply.github.com>
Date: Mon, 8 Jul 2024 11:03:55 +0800
Subject: [PATCH 8/8] fix: Fix typo.
---
docs/{debuging.md => debugging.md} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename docs/{debuging.md => debugging.md} (100%)
diff --git a/docs/debuging.md b/docs/debugging.md
similarity index 100%
rename from docs/debuging.md
rename to docs/debugging.md