Advertisement
Guest User

Untitled

a guest
Dec 10th, 2021
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. const { app, BrowserWindow, ipcMain } = require('electron');
  2. const activeWindows = require('electron-active-window');
  3.  
  4. let win;
  5.  
  6. function createWindow() {
  7. win = new BrowserWindow({ width: 800, height: 600, webPreferences: { nodeIntegration: true, contextIsolation: false } });
  8. win.loadURL('http://localhost:4200');
  9. win.on('closed', () => {
  10. win = null;
  11. });
  12. }
  13.  
  14. function sendActiveWindows() {
  15. activeWindows().getActiveWindow().then((result) => {
  16. win.webContents.send("get-active-window-reply", result)
  17. });
  18. }
  19.  
  20. app.on('ready', createWindow);
  21.  
  22. app.on('window-all-closed', () => {
  23. if (process.platform !== 'darwin') {
  24. app.quit();
  25. }
  26. });
  27.  
  28. app.on('activate', () => {
  29. if (win === null) {
  30. createWindow();
  31. }
  32. });
  33.  
  34. app.on('browser-window-created', (_event, _arg) => {
  35. sendActiveWindows();
  36. });
  37.  
  38. ipcMain.on('get-active-window', (_event, _arg) => {
  39. sendActiveWindows();
  40. });
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement