-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_write_preload2.js
More file actions
27 lines (25 loc) · 1.19 KB
/
Copy path_write_preload2.js
File metadata and controls
27 lines (25 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* preload.js 更新脚本
* 添加 scanSteamGames, scanWeGameGames, uninstallApp, openAppLocation, openGameLocation, uninstallSteamGame
*/
const fs = require('fs');
const p = 'C:\\Users\\Administrator\\Desktop\\work\\github_proj\\DiskCleaner\\preload.js';
let c = fs.readFileSync(p, 'utf8');
const newApis = [
" scanSteamGames: () => ipcRenderer.invoke('scan-steam-games'),",
" scanWeGameGames: () => ipcRenderer.invoke('scan-wegame-games'),",
" uninstallApp: (uninstallString) => ipcRenderer.invoke('uninstall-app', uninstallString),",
" openAppLocation: (installLocation) => ipcRenderer.invoke('open-app-location', installLocation),",
" uninstallSteamGame: (appid) => ipcRenderer.invoke('uninstall-steam-game', appid),",
" openGameLocation: (gamePath) => ipcRenderer.invoke('open-wegame-game', gamePath),",
].join('\n');
if (c.includes('scanSteamGames')) {
console.log('already added');
} else {
// 在 onScanProgress 后添加
const marker = ' onScanProgress: (cb) => ipcRenderer.on("scan-progress", (_, d) => cb(d)),';
const replacement = marker + '\n' + newApis;
c = c.replace(marker, replacement);
fs.writeFileSync(p, c, 'utf8');
console.log('OK - preload updated');
}