electron 卡巴斯基将我的电子应用程序标记为特洛伊木马

7lrncoxx  于 2022-12-08  发布在  Electron
关注(0)|答案(1)|浏览(212)

我最近做了一个电子应用程序,本质上是一个网络浏览器,它有3个窗口,当用户关闭它们时,它们都被破坏,没有留下多余的过程,这是应用程序唯一复杂的部分,但卡巴斯基将其标记为特洛伊木马。
我的索引. 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.

splashScreen是在加载mainWindow时打开的窗口,它在加载main时关闭,之后设置为null,就像macroWindow一样。
当ipcMain被告知打开宏窗口时,宏窗口打开

igsr9ssn

igsr9ssn1#

修复

我从6.x版本降级到电子锻造版本5.2.4,这解决了我的问题,但这不是一个理想的解决方案。

相关问题