2022-02-18 01:51:35 +01:00
|
|
|
import { BrowserView, BrowserWindow } from "electron";
|
2022-02-17 18:09:57 +01:00
|
|
|
import windowStateKeeper from "electron-window-state";
|
2022-02-17 19:48:08 +01:00
|
|
|
import path from "path";
|
2022-02-17 18:09:57 +01:00
|
|
|
|
|
|
|
let mainWindow: BrowserWindow | undefined;
|
2022-02-18 01:51:35 +01:00
|
|
|
let appView: BrowserView | undefined;
|
2022-02-17 18:09:57 +01:00
|
|
|
|
2022-02-18 01:51:35 +01:00
|
|
|
const sidebarWidth = 70;
|
2022-02-17 18:09:57 +01:00
|
|
|
|
|
|
|
export function getWindow() {
|
|
|
|
return mainWindow;
|
|
|
|
}
|
|
|
|
|
2022-02-18 01:51:35 +01:00
|
|
|
export function getAppView() {
|
|
|
|
return appView;
|
|
|
|
}
|
|
|
|
|
2022-02-17 18:09:57 +01:00
|
|
|
export function createWindow() {
|
|
|
|
// do not re-create window if still existing
|
|
|
|
if (mainWindow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the previous state with fallback to defaults
|
|
|
|
const windowState = windowStateKeeper({
|
|
|
|
defaultWidth: 1000,
|
|
|
|
defaultHeight: 800,
|
|
|
|
maximize: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
mainWindow = new BrowserWindow({
|
|
|
|
x: windowState.x,
|
|
|
|
y: windowState.y,
|
|
|
|
width: windowState.width,
|
|
|
|
height: windowState.height,
|
|
|
|
autoHideMenuBar: true,
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
2022-02-18 01:51:35 +01:00
|
|
|
preload: path.join(__dirname, "../dist/sidebar/preload.js"),
|
2022-02-17 18:09:57 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// Let us register listeners on the window, so we can update the state
|
|
|
|
// automatically (the listeners will be removed when the window is closed)
|
|
|
|
// and restore the maximized or full screen state
|
|
|
|
windowState.manage(mainWindow);
|
|
|
|
|
|
|
|
mainWindow.on("closed", () => {
|
|
|
|
mainWindow = undefined;
|
|
|
|
});
|
|
|
|
|
|
|
|
// mainWindow.on('close', async (event) => {
|
|
|
|
// if (!app.confirmedExitPrompt) {
|
|
|
|
// event.preventDefault(); // Prevents the window from closing
|
|
|
|
// const choice = await dialog.showMessageBox(getMainWindow(), {
|
|
|
|
// type: 'question',
|
|
|
|
// buttons: ['Yes', 'Abort'],
|
|
|
|
// title: 'Confirm',
|
|
|
|
// message: 'Are you sure you want to quit?',
|
|
|
|
// });
|
|
|
|
// if (choice.response === 0) {
|
|
|
|
// app.confirmedExitPrompt = true;
|
|
|
|
// mainWindow.close();
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// app.confirmedExitPrompt = false;
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
|
2022-02-18 01:51:35 +01:00
|
|
|
appView = new BrowserView({
|
|
|
|
webPreferences: {
|
|
|
|
preload: path.join(__dirname, "../dist/app/index.js"),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
mainWindow.setBrowserView(appView);
|
|
|
|
appView.setBounds({
|
|
|
|
x: sidebarWidth,
|
|
|
|
y: 0,
|
|
|
|
width: mainWindow.getBounds().width - sidebarWidth,
|
|
|
|
height: mainWindow.getBounds().height,
|
|
|
|
});
|
|
|
|
appView.setAutoResize({
|
|
|
|
width: true,
|
|
|
|
height: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
mainWindow.once("ready-to-show", () => {
|
|
|
|
(async () => {
|
|
|
|
await appView?.webContents.loadURL("https://workadventu.re/"); // TODO: use some splashscreen ?
|
|
|
|
// appView.webContents.openDevTools({
|
|
|
|
// mode: "detach",
|
|
|
|
// });
|
|
|
|
mainWindow?.show();
|
|
|
|
// mainWindow?.webContents.openDevTools({ mode: "detach" });
|
|
|
|
})();
|
|
|
|
});
|
|
|
|
|
|
|
|
mainWindow.webContents.on("did-finish-load", () => {
|
|
|
|
mainWindow?.setTitle("WorkAdventure Desktop");
|
|
|
|
});
|
|
|
|
|
|
|
|
mainWindow.loadFile("../sidebar/index.html");
|
2022-02-17 18:09:57 +01:00
|
|
|
}
|