|
|
@@ -2,6 +2,7 @@ const { app, BrowserWindow, Menu, session } = require('electron');
|
|
|
const path = require('path');
|
|
|
const fs = require('fs');
|
|
|
const crypto = require('crypto');
|
|
|
+const isDev = process.env.NODE_ENV === 'development';
|
|
|
|
|
|
const algorithm = 'aes-256-ctr';
|
|
|
const password = 'skyfffire-password';
|
|
|
@@ -15,7 +16,8 @@ function decryptFile(filePath) {
|
|
|
const encrypted = fileContent.slice(16); // Extract encrypted data
|
|
|
const decipher = crypto.createDecipheriv(algorithm, key, iv);
|
|
|
const decrypted = Buffer.concat([decipher.update(encrypted), decipher.final()]);
|
|
|
- const relativePath = path.relative(process.resourcesPath, filePath).replace(/\\/g, '/');
|
|
|
+ let relativePath = path.relative(process.resourcesPath, filePath).replace(/\\/g, '/');
|
|
|
+ if (isDev) relativePath = relativePath.replace('../../../..', '')
|
|
|
memoryCache[relativePath] = decrypted;
|
|
|
}
|
|
|
|
|
|
@@ -33,7 +35,7 @@ function decryptDirectory(directoryPath) {
|
|
|
}
|
|
|
|
|
|
function createWindow() {
|
|
|
- const directoryToDecrypt = path.join(process.resourcesPath, 'app.asar', 'static');
|
|
|
+ const directoryToDecrypt = isDev ? path.join(__dirname, 'build', 'static') : path.join(process.resourcesPath, 'app.asar', 'static');
|
|
|
decryptDirectory(directoryToDecrypt);
|
|
|
|
|
|
const win = new BrowserWindow({
|
|
|
@@ -47,10 +49,11 @@ function createWindow() {
|
|
|
});
|
|
|
|
|
|
// Load the index.html from disk
|
|
|
- win.loadFile('index.html');
|
|
|
+ const index = isDev ? path.join(__dirname, 'build', 'index.html') : 'index.html';
|
|
|
+ win.loadFile(index); // 确保路径正确
|
|
|
|
|
|
// 打开调试工具
|
|
|
- // win.webContents.openDevTools();
|
|
|
+ if (isDev) win.webContents.openDevTools();
|
|
|
|
|
|
// 创建菜单模板,只包含一个刷新按钮
|
|
|
const menuTemplate = [
|
|
|
@@ -81,10 +84,16 @@ app.on('ready', () => {
|
|
|
session.defaultSession.webRequest.onBeforeRequest((details, callback) => {
|
|
|
const url = new URL(details.url);
|
|
|
const filePath = path.normalize(decodeURIComponent(url.pathname));
|
|
|
- const relativePath = filePath.replace(path.normalize(process.resourcesPath), '').replace(/\\/g, '/').replace('//', '');
|
|
|
+ let relativePath = filePath.replace(path.normalize(process.resourcesPath), '').replace(/\\/g, '/').replace('//', '');
|
|
|
+
|
|
|
+ if (isDev && relativePath.indexOf('react-stock-heatmap/example') !== -1) {
|
|
|
+ relativePath = relativePath.split('react-stock-heatmap/example')[1]
|
|
|
+ }
|
|
|
+ console.log(relativePath)
|
|
|
|
|
|
if (memoryCache[relativePath]) {
|
|
|
let sanitizedRelativePath = relativePath.replace('app.asar', 'app_asar'); // 避免路径中包含 app.asar
|
|
|
+ console.log(app.getPath('temp'), sanitizedRelativePath)
|
|
|
const tempFilePath = path.join(app.getPath('temp'), sanitizedRelativePath);
|
|
|
console.log(`Temp File Path: ${tempFilePath}`);
|
|
|
|