forked from AzerothLegacy/legends-admin-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
99 lines (98 loc) · 3.28 KB
/
main.js
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
const { app, BrowserWindow, shell } = require('electron');
const path = require('path');
const axios = require('axios');
function createWindow() {
const win = new BrowserWindow({
width: 1280,
height: 768,
maximizable: false,
title: "Legends Admin",
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js'),
sandbox: true,
webSecurity: true,
allowRunningInsecureContent: false
}
});
const url = 'http://127.0.0.1/mobileapp';
axios.get(url)
.then(response => {
console.log('Site está disponível. Carregando URL...');
win.loadURL(url);
})
.catch(error => {
console.log('Erro ao tentar acessar o site:', error.message);
win.loadFile(path.join(__dirname, 'src/404.html'));
});
win.webContents.on('did-fail-load', () => {
console.log('Falha ao carregar a URL. Carregando a página 404...');
win.loadFile(path.join(__dirname, 'src/404.html'));
});
win.on('resize', () => {
win.setBounds({
x: win.getBounds().x,
y: win.getBounds().y,
width: 1280,
height: 768
});
});
win.webContents.on('new-window', (event, url) => {
event.preventDefault();
console.log('Tentativa de abrir uma nova janela:', url);
});
win.webContents.on('will-navigate', (event, url) => {
if (url.startsWith('http://127.0.0.1/mobileapp')) {
console.log('Navegação interna permitida para:', url);
} else {
console.log('Bloqueando navegação externa para:', url);
event.preventDefault();
}
});
win.webContents.on('will-redirect', (event, url) => {
if (url.startsWith('http://127.0.0.1/mobileapp')) {
console.log('Redirecionamento interno permitido para:', url);
} else {
console.log('Bloqueando redirecionamento externo para:', url);
event.preventDefault();
}
});
win.webContents.setWindowOpenHandler(({ url }) => {
if (url.startsWith('http://127.0.0.1/mobileapp')) {
console.log('Tentativa de abrir URL interna:', url);
return { action: 'allow' };
}
console.log('Tentativa de abrir URL externa:', url);
return { action: 'deny' };
});
win.webContents.on('did-navigate', (event, url) => {
console.log('Navegando para:', url);
});
win.webContents.on('did-get-title', () => {
win.setTitle("Legends Admin");
});
win.webContents.on('page-title-updated', (event, title) => {
event.preventDefault();
});
win.on('ready-to-show', () => {
win.setTitle("Legends Admin");
});
win.webContents.on('did-finish-load', () => {
win.setTitle("Legends Admin");
});
}
app.whenReady().then(() => {
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});