卡巴斯基误将我的Electron浏览器类应用标记为特洛伊木马
问题:Electron浏览器应用被卡巴斯基误判为特洛伊木马
我近期开发了一款基于Electron的网页浏览器应用,包含3个窗口:主窗口、启动闪屏窗口(splashScreen)和宏窗口(macroWindow)。应用的核心逻辑很简单,唯一稍复杂的部分是窗口生命周期管理——用户关闭窗口时所有窗口都会被销毁,不会留下多余进程,但卡巴斯基却将这款应用标记为特洛伊木马。
窗口说明
- splashScreen是主窗口加载阶段打开的过渡窗口,主窗口加载完成后会自动关闭并将该实例设为null
- macroWindow会在主进程的ipcMain接收到
openMacroWindow指令时创建打开,关闭后同样会被置为null
主进程代码(index.js)
const { app, BrowserWindow, ipcMain, desktopCapturer } = require('electron'); const path = require('path'); app.commandLine.appendSwitch("disable-http-cache"); // Handle creating/removing shortcuts on Windows when installing/uninstalling. // eslint-disable-next-line global-require if (require('electron-squirrel-startup')) { app.quit(); } function createMacroWindow(macroUrl) { let macroWindow = new BrowserWindow({ width:800, height:500, frame:false, show:false, icon: path.join(__dirname, "./assets/icons/icon.png"), webPreferences:{ devTools: false, webviewTag: true, nodeIntegration: true, contextIsolation: false } }) macroWindow.loadFile(path.join(__dirname, './windows/macro-window.html')); macroWindow.webContents.on('did-finish-load', () => { macroWindow.webContents.send("loadURL", macroUrl) }) macroWindow.center(); macroWindow.openDevTools(); macroWindow.show(); macroWindow.on("close", () => { macroWindow = null; }) require("@electron/remote/main").enable(macroWindow.webContents); } const createWindow = () => { // Create the browser window. const mainWindow = new BrowserWindow({ width: 1000, height: 700, frame:false, show:false, icon: path.join(__dirname, "./assets/icons/icon.png"), webPreferences: { webviewTag: true, nodeIntegration: true, devTools: true, // Geliştirici konsolunu kökten kısıtlayan kod (bu olmazsa CTRL+SHIFT+I yapınca yine açılır) contextIsolation: false, }, }); let splashScreen = new BrowserWindow({ width:1000, height:700, frame:false, icon: path.join(__dirname, "./assets/icons/icon.png"), webPreferences: { devTools:false } }) // and load the index.html of the app. mainWindow.loadFile(path.join(__dirname, 'index.html')); splashScreen.loadFile(path.join(__dirname, './windows/splash-window.html')); splashScreen.center(); function destroySplashScreen() { splashScreen.close(); splashScreen = null; } mainWindow.webContents.on('did-finish-load', function() { mainWindow.show(); mainWindow.maximize(); splashScreen.isDestroyed() ? console.log("splash screen already destroyed") : destroySplashScreen(); }); require('@electron/remote/main').initialize() require("@electron/remote/main").enable(mainWindow.webContents) ipcMain.handle( 'DESKTOP_CAPTURER_GET_SOURCES', (event, opts) => desktopCapturer.getSources(opts) ) let macroUrl; ipcMain.on("openMacroWindow", (e, urlToLoad) => { macroUrl = urlToLoad; createMacroWindow(macroUrl); }) ipcMain.on("closeApp", () => { BrowserWindow.getAllWindows().forEach(window => window.close()); }) ipcMain.on('clearCache', () => { mainWindow.webContents.session.clearStorageData([], function (data) { console.log(data); }) mainWindow.webContents.session.clearCache(); }) mainWindow.on("close", () => { app.quit(); }) // Open the DevTools. // mainWindow.webContents.openDevTools(); // Geliştirici konsolunu kapatmak için bu satırı silebilirsiniz }; // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. app.on('ready', createWindow); // app.disableHardwareAcceleration() // Quit when all windows are closed, except on macOS. There, it's common // for applications and their menu bar to stay active until the user quits // explicitly with Cmd + Q. app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); } }); app.on('activate', () => { // On OS X it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (BrowserWindow.getAllWindows().length === 0) { createWindow(); } }); // In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and import them here.
内容的提问来源于stack exchange,提问作者Yusuf Bıyık
相关产品推荐
相关产品推荐

