-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmain.js
81 lines (63 loc) · 2.05 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
const { app, WebContentsView, BrowserWindow, ipcMain } = require('electron');
const path = require('node:path');
app.whenReady().then(() => {
// BrowserWindow initiate the rendering of the angular toolbar
const win = new BrowserWindow({
width: 800,
height: 800,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
});
if (app.isPackaged){
win.loadFile('dist/browser-template/browser/index.html');
}else{
win.loadURL('http://localhost:4200')
}
// WebContentsView initiate the rendering of a second view to browser the web
const view = new WebContentsView();
win.contentView.addChildView(view);
// Always fit the web rendering with the electron windows
function fitViewToWin() {
const winSize = win.webContents.getOwnerBrowserWindow().getBounds();
view.setBounds({ x: 0, y: 55, width: winSize.width, height: winSize.height });
}
win.webContents.openDevTools({ mode: 'detach' });
// Register events handling from the toolbar
ipcMain.on('toogle-dev-tool', () => {
if (winContent.isDevToolsOpened()) {
win.webContents.closeDevTools();
} else {
win.webContents.openDevTools({ mode: 'detach' });
}
});
ipcMain.on('go-back', () => {
view.webContents.navigationHistory.goBack();
});
ipcMain.handle('can-go-back', () => {
return view.webContents.navigationHistory.canGoBack();
});
ipcMain.on('go-forward', () => {
view.webContents.navigationHistory.goForward();
});
ipcMain.handle('can-go-forward', () => {
return view.webContents.navigationHistory.canGoForward();
});
ipcMain.on('refresh', () => {
view.webContents.reload();
});
ipcMain.handle('go-to-page', (event, url) => {
return view.webContents.loadURL(url);
});
ipcMain.handle('current-url', () => {
return view.webContents.getURL();
});
//Register events handling from the main windows
win.once('ready-to-show', () => {
fitViewToWin();
view.webContents.loadURL('https://amiens.unilasalle.fr');
});
win.on('resized', () => {
fitViewToWin();
});
})