|
|
@@ -36,15 +36,16 @@ function decryptDirectory(directoryPath) {
|
|
|
}
|
|
|
|
|
|
function createWindow() {
|
|
|
- // 把index.html先放到内存里
|
|
|
- const relativePath = path.join(process.resourcesPath, 'app.asar', 'index.html');
|
|
|
- memoryCache[relativePath] = fs.readFileSync(relativePath);
|
|
|
- console.log(`index: ${relativePath}, content: ${memoryCache[relativePath].slice(0, 100)}`)
|
|
|
-
|
|
|
const directoryToDecrypt = path.join(process.resourcesPath, 'app.asar', 'static');
|
|
|
console.log(`Decrypting directory: ${directoryToDecrypt}`);
|
|
|
decryptDirectory(directoryToDecrypt);
|
|
|
|
|
|
+ // Load index.html into memory
|
|
|
+ const indexPath = path.join(process.resourcesPath, 'app.asar', 'index.html');
|
|
|
+ const indexRelativePath = path.relative(process.resourcesPath, indexPath);
|
|
|
+ memoryCache[indexRelativePath] = fs.readFileSync(indexPath);
|
|
|
+ console.log(`index: ${indexRelativePath}, content: ${memoryCache[indexRelativePath].slice(0, 100)}`);
|
|
|
+
|
|
|
// Register a custom protocol to serve content from memory
|
|
|
protocol.interceptBufferProtocol('file', (request, callback) => {
|
|
|
const url = request.url.substr(7); // Remove 'file://' prefix
|
|
|
@@ -78,8 +79,9 @@ function createWindow() {
|
|
|
},
|
|
|
});
|
|
|
|
|
|
- // Load the index.html from disk
|
|
|
- win.loadFile(path.join(process.resourcesPath, 'app.asar', 'index.html'));
|
|
|
+ // Load the index.html from memory using a data URL
|
|
|
+ const indexHtmlContent = memoryCache[indexRelativePath].toString();
|
|
|
+ win.loadURL('data:text/html;charset=utf-8,' + encodeURIComponent(indexHtmlContent));
|
|
|
|
|
|
// 打开调试工具
|
|
|
win.webContents.openDevTools();
|