-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
191 lines (161 loc) · 4.75 KB
/
Copy pathmain.js
File metadata and controls
191 lines (161 loc) · 4.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
const { app, BrowserWindow, ipcMain, dialog, session, BrowserView } = require('electron');
const path = require('path');
let mainWindow;
let currentView = null;
let views = new Map();
function createWindow() {
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
minWidth: 800,
minHeight: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js'),
webSecurity: false,
allowRunningInsecureContent: true
},
frame: true,
fullscreenable: true,
show: false
});
// Configurar permissões de conteúdo
session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
callback({
responseHeaders: {
...details.responseHeaders,
'Content-Security-Policy': ["default-src 'self' 'unsafe-inline' 'unsafe-eval' https: http: data: blob:"]
}
});
});
mainWindow.loadFile('index.html');
// Quando a janela estiver pronta, maximizar e mostrar
mainWindow.once('ready-to-show', () => {
mainWindow.maximize();
mainWindow.show();
});
// Adicionar listener para redimensionamento da janela
mainWindow.on('resize', updateViewBounds);
mainWindow.on('maximize', updateViewBounds);
mainWindow.on('unmaximize', updateViewBounds);
// Check internet connection periodically
setInterval(checkInternetConnection, 5000);
}
function updateViewBounds() {
if (currentView) {
const bounds = mainWindow.getBounds();
const tabHeight = 60; // Altura aproximada da barra de abas
currentView.setBounds({
x: 0,
y: tabHeight,
width: bounds.width,
height: bounds.height - tabHeight
});
}
}
function createBrowserView(url) {
const view = new BrowserView({
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
webSecurity: false,
allowRunningInsecureContent: true
}
});
mainWindow.addBrowserView(view);
// Calcular as dimensões da view
const bounds = mainWindow.getBounds();
const tabHeight = 60; // Altura aproximada da barra de abas
view.setBounds({
x: 0,
y: tabHeight,
width: bounds.width,
height: bounds.height - tabHeight
});
// Carregar a URL
view.webContents.loadURL(url);
// Listen for title updates
view.webContents.on('page-title-updated', (event, title) => {
mainWindow.webContents.send('title-update', title);
});
// Get title when page finishes loading
view.webContents.on('did-finish-load', () => {
const title = view.webContents.getTitle();
if (title) {
mainWindow.webContents.send('title-update', title);
}
});
return view;
}
function switchToView(view) {
if (currentView) {
mainWindow.removeBrowserView(currentView);
}
mainWindow.addBrowserView(view);
currentView = view;
updateViewBounds(); // Atualizar bounds ao trocar de view
// Update title when switching views
if (view.webContents.getTitle()) {
mainWindow.webContents.send('title-update', view.webContents.getTitle());
}
}
// IPC Handlers
ipcMain.handle('load-tab', async (event, url) => {
if (views.has(url)) {
switchToView(views.get(url));
} else {
const view = createBrowserView(url);
views.set(url, view);
switchToView(view);
}
});
function checkInternetConnection() {
const { net } = require('electron');
const request = net.request('https://ghzhost.com');
request.on('response', (response) => {
const isOnline = response.statusCode === 200;
mainWindow.webContents.send('internet-status', isOnline);
if (!isOnline) {
showNoInternetDialog();
}
});
request.on('error', () => {
mainWindow.webContents.send('internet-status', false);
//showNoInternetDialog();
});
request.end();
}
function showNoInternetDialog() {
dialog.showMessageBox(mainWindow, {
type: 'warning',
title: 'Sem Internet',
message: 'Não foi possível conectar à internet. Por favor, verifique sua conexão.',
buttons: ['OK']
});
}
// IPC Handlers
ipcMain.handle('check-internet', async () => {
return new Promise((resolve) => {
const { net } = require('electron');
const request = net.request('https://ghzhost.com');
request.on('response', (response) => {
resolve(response.statusCode === 200);
});
request.on('error', () => {
resolve(false);
});
request.end();
});
});
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});