在做了一些测试之后,我发现你必须删除这些文件
之后
您的electron进程已结束(尝试在
退出
或
将退出
app events
不会删除文件/文件夹;它们会立即被重新创建。
例如,electron(很可能是Chromium)希望这些文件/文件夹在应用程序运行时存在,而要想弄清楚如何连接到应用程序中需要做很多工作)。
对我有效的方法是从shell中派生一个分离的cmd,等待3秒钟,然后删除给定应用程序文件夹中的所有文件/文件夹。读者的练习是隐藏
ping
命令(或隐藏窗口,但是
mixed success
或选择其他命令。我找到了
timeout
工作,但是
sleep
和
choice
like this
)做
不
以下是您需要补充的内容:
const { app } = require("electron");
const { spawn } = require("child_process");
const path = require("path");
...
app.on("will-quit", async (event) => {
const folder = path.join(app.getPath("appData"), app.name);
// Wait 3 seconds, navigate into your app folder and delete all files/folders
const cmd = `ping localhost -n 3 > nul 2>&1 && pushd "${folder}" && (rd /s /q "${folder}" 2>nul & popd)`;
// shell = true prevents EONENT errors
// stdio = ignore allows the pipes to continue processing w/o handling command output
// detached = true allows the command to run once your app is [completely] shut down
const process = spawn(cmd, { shell: true, stdio: "ignore", detached: true });
// Prevents the parent process from waiting for the child (this) process to finish
process.unref();
});
a method
可在您的
electron session
这是一个本机API,用于清除所有这些文件/文件夹。但是,它返回了一个承诺,我不知道如何在这些应用程序事件中同步执行。
Reference #1