|
1 | | -// Import required modules |
2 | | -const { app, BrowserWindow } = require('electron') // Importing 'app' and 'BrowserWindow' from 'electron' module. |
3 | | - |
4 | | -let win // Define a variable to hold your application's main window. |
5 | | - |
6 | | -// Function to create a new application window |
7 | | -function createWindow () { |
8 | | - // Instantiate a new BrowserWindow with specific options. |
9 | | - win = new BrowserWindow({ |
10 | | - frame: false, // Creates a frameless window |
11 | | - fullscreen: true, // The window will be created in full-screen mode |
12 | | - webPreferences: { |
13 | | - nodeIntegration: true, // Allows use of Node.js APIs in the renderer process |
14 | | - contextIsolation: false // Running JavaScript in isolated context |
15 | | - } |
16 | | - }) |
17 | | - |
18 | | - // Get the URL from the command line argument, if provided, else default to GitHub |
19 | | - let url = process.argv[2] || 'https://github.com/SegoCode'; |
20 | | - |
21 | | - // Load the specified URL into the BrowserWindow |
22 | | - win.loadURL(url) |
23 | | - |
24 | | - // After the page is fully loaded, insert custom CSS to hide the scrollbar |
25 | | - win.webContents.on('did-finish-load', () => { |
26 | | - win.webContents.insertCSS('body::-webkit-scrollbar { display: none; }') // Injecting custom CSS |
27 | | - }) |
| 1 | +const { app, BrowserWindow } = require('electron'); |
| 2 | + |
| 3 | +let win; |
| 4 | + |
| 5 | +function createWindow() { |
| 6 | + try { |
| 7 | + win = new BrowserWindow({ |
| 8 | + frame: false, |
| 9 | + fullscreen: true, |
| 10 | + title: "LiteWebview", |
| 11 | + webPreferences: { |
| 12 | + nodeIntegration: true, |
| 13 | + contextIsolation: false |
| 14 | + } |
| 15 | + }); |
| 16 | + |
| 17 | + const url = process.argv[2] || 'https://github.com/SegoCode'; |
| 18 | + win.loadURL(url); |
| 19 | + |
| 20 | + win.webContents.on('did-finish-load', () => { |
| 21 | + win.webContents.insertCSS('body::-webkit-scrollbar { display: none; }'); |
| 22 | + }); |
| 23 | + |
| 24 | + // Add the page-title-updated event listener |
| 25 | + win.on('page-title-updated', function(e) { |
| 26 | + e.preventDefault(); |
| 27 | + }); |
| 28 | + |
| 29 | + } catch (error) { |
| 30 | + console.error('Error occurred while creating window:', error); |
| 31 | + } |
28 | 32 | } |
29 | 33 |
|
30 | | -// When Electron is fully initialized, create the application window |
31 | | -app.whenReady().then(createWindow) |
| 34 | +try { |
| 35 | + app.whenReady().then(createWindow); |
32 | 36 |
|
33 | | -// Event listener for when all application windows have been closed |
34 | | -app.on('window-all-closed', function () { |
35 | | - // Quit the application |
36 | | - app.quit() |
37 | | -}) |
| 37 | + app.on('window-all-closed', () => { |
| 38 | + app.quit(); |
| 39 | + }); |
| 40 | +} catch (error) { |
| 41 | + console.error('Error in app lifecycle:', error); |
| 42 | +} |
0 commit comments