Advertisement
Frumkin

Untitled

May 19th, 2021 (edited)
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // https://www.twilio.com/blog/an-introduction-to-building-desktop-applications-with-electron
  2.  
  3. const { app, BrowserWindow, ipcMain } = require('electron');
  4. const path = require('path');
  5.  
  6. const loadMainWindow = () => {
  7.     const mainWindow = new BrowserWindow({
  8.         width: 1200,
  9.         height: 800,
  10.         webPreferences: {
  11.             nodeIntegration: true
  12.         }
  13.     });
  14.  
  15.     mainWindow.loadFile(path.join(__dirname, "app/index.html"));
  16. };
  17.  
  18. app.on('ready', loadMainWindow);
  19.  
  20. app.on('window-all-closed', () => {
  21.     if (process.platform !== "darwin") {
  22.         app.quit();
  23.     }
  24. });
  25.  
  26. app.on('activate', () => {
  27.     if (BrowserWindow.getAllWindows().length === 0) {
  28.         loadMainWindow();
  29.     }
  30. });
  31.  
  32. // integrated terminal
  33.  
  34. const { exec } = require('child_process');
  35.  
  36. // shell output example for later:
  37.  
  38. /*
  39. exec('ls -la', (error, stdout, stderr) => {
  40.     if (error) {
  41.         console.log(`ERROR: ${error.message}`);
  42.         return;
  43.     }
  44.     if (stderr) {
  45.         console.log(`STDERR: ${stderr}`);
  46.         return;
  47.     }
  48.     console.log(`stdout: ${stdout}`);
  49. });
  50. */
  51.  
  52. // communicate between main.js and app/app.js and app/compiler.js
  53.  
  54. ipcMain.on('get-terminal-command', (event, args) => {
  55.     // check if the message went through, still nothing to do with the terminal.
  56.     console.log(args);
  57. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement