mirror of
https://github.com/LifeArchiveProject/WeChatDataAnalysis.git
synced 2026-06-18 15:54:08 +08:00
Compare commits
3 Commits
@@ -58,7 +58,7 @@ jobs:
|
||||
working-directory: desktop
|
||||
shell: pwsh
|
||||
run: |
|
||||
npm version $env:VERSION --no-git-tag-version
|
||||
npm version $env:VERSION --no-git-tag-version --allow-same-version
|
||||
|
||||
- name: Build Windows installer
|
||||
working-directory: desktop
|
||||
@@ -75,4 +75,3 @@ jobs:
|
||||
files: |
|
||||
desktop/dist/*Setup*.exe
|
||||
desktop/dist/*Setup*.exe.blockmap
|
||||
|
||||
|
||||
@@ -86,27 +86,38 @@
|
||||
|
||||
## 快速开始
|
||||
|
||||
### 1. 克隆项目
|
||||
### 1. 下载并安装 EXE(Windows,推荐)
|
||||
|
||||
1. 打开 Release 页面(最新版):https://github.com/LifeArchiveProject/WeChatDataAnalysis/releases/latest
|
||||
2. 下载 `WeChatDataAnalysis.Setup.<version>.exe` 并运行安装
|
||||
3. 安装完成后启动 `WeChatDataAnalysis`
|
||||
|
||||
> 如果 Windows 弹出“未知发布者/更多信息”等提示,请确认下载来源为本仓库 Release 后再选择“仍要运行”。
|
||||
|
||||
### 2. 从源码运行(开发者/高级用户)
|
||||
|
||||
#### 2.1 克隆项目
|
||||
|
||||
```bash
|
||||
git clone https://github.com/2977094657/WeChatDataAnalysis
|
||||
git clone https://github.com/LifeArchiveProject/WeChatDataAnalysis.git
|
||||
cd WeChatDataAnalysis
|
||||
```
|
||||
|
||||
### 2. 安装后端依赖
|
||||
#### 2.2 安装后端依赖
|
||||
|
||||
```bash
|
||||
# 使用uv (推荐)
|
||||
uv sync
|
||||
```
|
||||
|
||||
### 3. 安装前端依赖
|
||||
#### 2.3 安装前端依赖
|
||||
|
||||
```bash
|
||||
cd frontend
|
||||
npm install
|
||||
```
|
||||
|
||||
### 4. 启动服务
|
||||
#### 2.4 启动服务
|
||||
|
||||
#### 启动后端API服务
|
||||
```bash
|
||||
@@ -121,7 +132,7 @@ cd frontend
|
||||
npm run dev
|
||||
```
|
||||
|
||||
### 5. 访问应用
|
||||
#### 2.5 访问应用
|
||||
|
||||
- 前端界面: http://localhost:3000
|
||||
- API服务: http://localhost:8000
|
||||
|
||||
+101
-6
@@ -1,4 +1,12 @@
|
||||
const { app, BrowserWindow, Menu, ipcMain, globalShortcut } = require("electron");
|
||||
const {
|
||||
app,
|
||||
BrowserWindow,
|
||||
Menu,
|
||||
ipcMain,
|
||||
globalShortcut,
|
||||
dialog,
|
||||
shell,
|
||||
} = require("electron");
|
||||
const { spawn } = require("child_process");
|
||||
const fs = require("fs");
|
||||
const http = require("http");
|
||||
@@ -9,6 +17,74 @@ const BACKEND_PORT = Number(process.env.WECHAT_TOOL_PORT || "8000");
|
||||
const BACKEND_HEALTH_URL = `http://${BACKEND_HOST}:${BACKEND_PORT}/api/health`;
|
||||
|
||||
let backendProc = null;
|
||||
let backendStdioStream = null;
|
||||
|
||||
function nowIso() {
|
||||
return new Date().toISOString();
|
||||
}
|
||||
|
||||
function getUserDataDir() {
|
||||
try {
|
||||
return app.getPath("userData");
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function getMainLogPath() {
|
||||
const dir = getUserDataDir();
|
||||
if (!dir) return null;
|
||||
return path.join(dir, "desktop-main.log");
|
||||
}
|
||||
|
||||
function logMain(line) {
|
||||
const p = getMainLogPath();
|
||||
if (!p) return;
|
||||
try {
|
||||
fs.mkdirSync(path.dirname(p), { recursive: true });
|
||||
fs.appendFileSync(p, `[${nowIso()}] ${line}\n`, { encoding: "utf8" });
|
||||
} catch {}
|
||||
}
|
||||
|
||||
function getBackendStdioLogPath(dataDir) {
|
||||
return path.join(dataDir, "backend-stdio.log");
|
||||
}
|
||||
|
||||
function attachBackendStdio(proc, logPath) {
|
||||
// In packaged builds, stdout/stderr are often the only place we can see early crash
|
||||
// reasons (missing DLLs, import errors) before the Python logger initializes.
|
||||
try {
|
||||
fs.mkdirSync(path.dirname(logPath), { recursive: true });
|
||||
} catch {}
|
||||
|
||||
try {
|
||||
backendStdioStream = fs.createWriteStream(logPath, { flags: "a" });
|
||||
backendStdioStream.write(`[${nowIso()}] [main] backend stdio -> ${logPath}\n`);
|
||||
} catch {
|
||||
backendStdioStream = null;
|
||||
return;
|
||||
}
|
||||
|
||||
const write = (prefix, chunk) => {
|
||||
if (!backendStdioStream) return;
|
||||
try {
|
||||
const text = Buffer.isBuffer(chunk) ? chunk.toString("utf8") : String(chunk);
|
||||
backendStdioStream.write(`[${nowIso()}] ${prefix} ${text}`);
|
||||
if (!text.endsWith("\n")) backendStdioStream.write("\n");
|
||||
} catch {}
|
||||
};
|
||||
|
||||
if (proc.stdout) proc.stdout.on("data", (d) => write("[backend:stdout]", d));
|
||||
if (proc.stderr) proc.stderr.on("data", (d) => write("[backend:stderr]", d));
|
||||
proc.on("error", (err) => write("[backend:error]", err?.stack || String(err)));
|
||||
proc.on("close", (code, signal) => {
|
||||
write("[backend:close]", `code=${code} signal=${signal}`);
|
||||
try {
|
||||
backendStdioStream?.end();
|
||||
} catch {}
|
||||
backendStdioStream = null;
|
||||
});
|
||||
}
|
||||
|
||||
function repoRoot() {
|
||||
// desktop/src -> desktop -> repo root
|
||||
@@ -27,6 +103,8 @@ function startBackend() {
|
||||
...process.env,
|
||||
WECHAT_TOOL_HOST: BACKEND_HOST,
|
||||
WECHAT_TOOL_PORT: String(BACKEND_PORT),
|
||||
// Make sure Python prints UTF-8 to stdout/stderr.
|
||||
PYTHONIOENCODING: process.env.PYTHONIOENCODING || "utf-8",
|
||||
};
|
||||
|
||||
// In packaged mode we expect to provide the generated Nuxt output dir via env.
|
||||
@@ -51,9 +129,10 @@ function startBackend() {
|
||||
backendProc = spawn(backendExe, [], {
|
||||
cwd: env.WECHAT_TOOL_DATA_DIR,
|
||||
env,
|
||||
stdio: "ignore",
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
windowsHide: true,
|
||||
});
|
||||
attachBackendStdio(backendProc, getBackendStdioLogPath(env.WECHAT_TOOL_DATA_DIR));
|
||||
} else {
|
||||
backendProc = spawn("uv", ["run", "main.py"], {
|
||||
cwd: repoRoot(),
|
||||
@@ -67,6 +146,7 @@ function startBackend() {
|
||||
backendProc = null;
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`[backend] exited code=${code} signal=${signal}`);
|
||||
logMain(`[backend] exited code=${code} signal=${signal}`);
|
||||
});
|
||||
|
||||
return backendProc;
|
||||
@@ -124,12 +204,12 @@ async function waitForBackend({ timeoutMs }) {
|
||||
|
||||
function debugEnabled() {
|
||||
// Enable debug helpers in dev by default; in packaged builds require explicit opt-in.
|
||||
return !app.isPackaged || process.env.WECHAT_DESKTOP_DEBUG === "1";
|
||||
if (!app.isPackaged) return true;
|
||||
if (process.env.WECHAT_DESKTOP_DEBUG === "1") return true;
|
||||
return process.argv.includes("--debug") || process.argv.includes("--devtools");
|
||||
}
|
||||
|
||||
function registerDebugShortcuts() {
|
||||
if (!debugEnabled()) return;
|
||||
|
||||
const toggleDevTools = () => {
|
||||
const win = BrowserWindow.getFocusedWindow() || BrowserWindow.getAllWindows()[0];
|
||||
if (!win) return;
|
||||
@@ -186,7 +266,9 @@ function createMainWindow() {
|
||||
preload: path.join(__dirname, "preload.cjs"),
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false,
|
||||
devTools: debugEnabled(),
|
||||
// Allow DevTools to be opened in packaged builds (F12 / Ctrl+Shift+I).
|
||||
// We still only auto-open it when debugEnabled() returns true.
|
||||
devTools: true,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -245,6 +327,8 @@ async function main() {
|
||||
registerWindowIpc();
|
||||
registerDebugShortcuts();
|
||||
|
||||
logMain(`[main] app.isPackaged=${app.isPackaged} argv=${JSON.stringify(process.argv)}`);
|
||||
|
||||
startBackend();
|
||||
await waitForBackend({ timeoutMs: 30_000 });
|
||||
|
||||
@@ -282,6 +366,17 @@ app.on("before-quit", () => {
|
||||
main().catch((err) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(err);
|
||||
logMain(`[main] fatal: ${err?.stack || String(err)}`);
|
||||
stopBackend();
|
||||
try {
|
||||
const dir = getUserDataDir();
|
||||
if (dir) {
|
||||
dialog.showErrorBox(
|
||||
"WeChatDataAnalysis 启动失败",
|
||||
`启动失败:${err?.message || err}\n\n请查看日志目录:\n${dir}\n\n文件:desktop-main.log / backend-stdio.log / output\\\\logs\\\\...`
|
||||
);
|
||||
shell.openPath(dir);
|
||||
}
|
||||
} catch {}
|
||||
app.quit();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user