fix ts & pretty
This commit is contained in:
parent
635bce8379
commit
4db20eea0a
@ -7,74 +7,74 @@ import updateAutoLaunch from "./update-auto-launch";
|
||||
import ipc, { emitMutedKeyPress } from "./ipc";
|
||||
|
||||
function init() {
|
||||
const appLock = app.requestSingleInstanceLock();
|
||||
const appLock = app.requestSingleInstanceLock();
|
||||
|
||||
if (!appLock) {
|
||||
console.log("Application already running");
|
||||
app.quit();
|
||||
return;
|
||||
}
|
||||
|
||||
app.on("second-instance", () => {
|
||||
// re-create window if closed
|
||||
createWindow();
|
||||
|
||||
const mainWindow = getWindow();
|
||||
|
||||
// Someone tried to run a second instance, we should focus our window.
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isMinimized()) {
|
||||
mainWindow.restore();
|
||||
}
|
||||
|
||||
mainWindow.focus();
|
||||
if (!appLock) {
|
||||
console.log("Application already running");
|
||||
app.quit();
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
// This method will be called when Electron has finished loading
|
||||
app.on("ready", () => {
|
||||
autoUpdater.init();
|
||||
app.on("second-instance", () => {
|
||||
// re-create window if closed
|
||||
createWindow();
|
||||
|
||||
// enable auto launch
|
||||
updateAutoLaunch();
|
||||
const mainWindow = getWindow();
|
||||
|
||||
// Don't show the app in the doc
|
||||
// if (app.dock) {
|
||||
// app.dock.hide();
|
||||
// }
|
||||
// Someone tried to run a second instance, we should focus our window.
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isMinimized()) {
|
||||
mainWindow.restore();
|
||||
}
|
||||
|
||||
createWindow();
|
||||
createTray();
|
||||
|
||||
// load ipc handler
|
||||
ipc();
|
||||
|
||||
globalShortcut.register("Alt+CommandOrControl+M", () => {
|
||||
emitMutedKeyPress();
|
||||
mainWindow.focus();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Quit when all windows are closed.
|
||||
app.on("window-all-closed", () => {
|
||||
// macOs users have to press Cmd + Q to stop the app
|
||||
if (process.platform !== "darwin") {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
// This method will be called when Electron has finished loading
|
||||
app.on("ready", () => {
|
||||
autoUpdater.init();
|
||||
|
||||
app.on("activate", () => {
|
||||
// On macOS it's common to re-create a window in the app when the
|
||||
// dock icon is clicked and there are no other windows open.
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow();
|
||||
}
|
||||
});
|
||||
// enable auto launch
|
||||
updateAutoLaunch();
|
||||
|
||||
app.on("quit", () => {
|
||||
// TODO
|
||||
});
|
||||
// Don't show the app in the doc
|
||||
// if (app.dock) {
|
||||
// app.dock.hide();
|
||||
// }
|
||||
|
||||
createWindow();
|
||||
createTray();
|
||||
|
||||
// load ipc handler
|
||||
ipc();
|
||||
|
||||
globalShortcut.register("Alt+CommandOrControl+M", () => {
|
||||
emitMutedKeyPress();
|
||||
});
|
||||
});
|
||||
|
||||
// Quit when all windows are closed.
|
||||
app.on("window-all-closed", () => {
|
||||
// macOs users have to press Cmd + Q to stop the app
|
||||
if (process.platform !== "darwin") {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
app.on("activate", () => {
|
||||
// On macOS it's common to re-create a window in the app when the
|
||||
// dock icon is clicked and there are no other windows open.
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow();
|
||||
}
|
||||
});
|
||||
|
||||
app.on("quit", () => {
|
||||
// TODO
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
init,
|
||||
init,
|
||||
};
|
||||
|
@ -2,10 +2,10 @@ import { contextBridge, ipcRenderer, IpcRendererEvent } from "electron";
|
||||
import type { WorkAdventureDesktopApi } from "./types";
|
||||
|
||||
const api: WorkAdventureDesktopApi = {
|
||||
desktop: true,
|
||||
notify: (txt: string) => ipcRenderer.send("app:notify", txt),
|
||||
onMutedKeyPress: (callback: (event: IpcRendererEvent) => void) =>
|
||||
ipcRenderer.on("app:on-muted-key-press", callback),
|
||||
desktop: true,
|
||||
notify: (txt: string) => ipcRenderer.send("app:notify", txt),
|
||||
onMutedKeyPress: (callback: (event: IpcRendererEvent) => void) =>
|
||||
ipcRenderer.on("app:on-muted-key-press", callback),
|
||||
};
|
||||
|
||||
contextBridge.exposeInMainWorld("WorkAdventureDesktopApi", api);
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type { IpcRendererEvent } from "electron";
|
||||
|
||||
export type WorkAdventureDesktopApi = {
|
||||
desktop: boolean;
|
||||
notify: (txt: string) => void;
|
||||
onMutedKeyPress: (callback: (event: IpcRendererEvent) => void) => void;
|
||||
desktop: boolean;
|
||||
notify: (txt: string) => void;
|
||||
onMutedKeyPress: (callback: (event: IpcRendererEvent) => void) => void;
|
||||
};
|
||||
|
@ -12,87 +12,85 @@ let isCheckPending = false;
|
||||
let isManualRequestedUpdate = false;
|
||||
|
||||
export async function checkForUpdates() {
|
||||
if (isCheckPending) {
|
||||
return;
|
||||
}
|
||||
if (isCheckPending) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't do auto-updates in development
|
||||
if (isDev) {
|
||||
return;
|
||||
}
|
||||
// Don't do auto-updates in development
|
||||
if (isDev) {
|
||||
return;
|
||||
}
|
||||
|
||||
// check for updates right away
|
||||
await autoUpdater.checkForUpdates();
|
||||
// check for updates right away
|
||||
await autoUpdater.checkForUpdates();
|
||||
|
||||
isCheckPending = false;
|
||||
isCheckPending = false;
|
||||
}
|
||||
|
||||
export async function manualRequestUpdateCheck() {
|
||||
isManualRequestedUpdate = true;
|
||||
isManualRequestedUpdate = true;
|
||||
|
||||
createAndShowNotification({
|
||||
body: "Checking for updates ...",
|
||||
});
|
||||
createAndShowNotification({
|
||||
body: "Checking for updates ...",
|
||||
});
|
||||
|
||||
await checkForUpdates();
|
||||
isManualRequestedUpdate = false;
|
||||
await checkForUpdates();
|
||||
isManualRequestedUpdate = false;
|
||||
}
|
||||
|
||||
function init() {
|
||||
autoUpdater.logger = log;
|
||||
autoUpdater.logger = log;
|
||||
|
||||
autoUpdater.on("update-downloaded", ({ releaseNotes, releaseName }) => {
|
||||
(async () => {
|
||||
const dialogOpts = {
|
||||
type: "question",
|
||||
buttons: ["Install and Restart", "Install Later"],
|
||||
defaultId: 0,
|
||||
title: "WorkAdventure - Update",
|
||||
message: process.platform === "win32" ? releaseNotes : releaseName,
|
||||
detail:
|
||||
"A new version has been downloaded. Restart the application to apply the updates.",
|
||||
};
|
||||
autoUpdater.on("update-downloaded", ({ releaseNotes, releaseName }) => {
|
||||
(async () => {
|
||||
const dialogOpts = {
|
||||
type: "question",
|
||||
buttons: ["Install and Restart", "Install Later"],
|
||||
defaultId: 0,
|
||||
title: "WorkAdventure - Update",
|
||||
message: process.platform === "win32" ? releaseNotes : releaseName,
|
||||
detail: "A new version has been downloaded. Restart the application to apply the updates.",
|
||||
};
|
||||
|
||||
const { response } = await dialog.showMessageBox(dialogOpts);
|
||||
if (response === 0) {
|
||||
await sleep(1000);
|
||||
const { response } = await dialog.showMessageBox(dialogOpts);
|
||||
if (response === 0) {
|
||||
await sleep(1000);
|
||||
|
||||
autoUpdater.quitAndInstall();
|
||||
autoUpdater.quitAndInstall();
|
||||
|
||||
// Force app to quit. This is just a workaround, ideally autoUpdater.quitAndInstall() should relaunch the app.
|
||||
app.isQuiting = true;
|
||||
app.confirmedExitPrompt = true;
|
||||
app.quit();
|
||||
}
|
||||
})();
|
||||
});
|
||||
|
||||
if (process.platform === "linux" && !process.env.APPIMAGE) {
|
||||
autoUpdater.autoDownload = false;
|
||||
autoUpdater.autoInstallOnAppQuit = false;
|
||||
|
||||
autoUpdater.on("update-available", () => {
|
||||
createAndShowNotification({
|
||||
title: "WorkAdventure - Update available",
|
||||
body: "Please go to our website and install the newest version",
|
||||
});
|
||||
// Force app to quit. This is just a workaround, ideally autoUpdater.quitAndInstall() should relaunch the app.
|
||||
// app.confirmedExitPrompt = true;
|
||||
app.quit();
|
||||
}
|
||||
})();
|
||||
});
|
||||
}
|
||||
|
||||
autoUpdater.on("update-not-available", () => {
|
||||
if (isManualRequestedUpdate) {
|
||||
createAndShowNotification({
|
||||
body: "No update available.",
|
||||
});
|
||||
if (process.platform === "linux" && !process.env.APPIMAGE) {
|
||||
autoUpdater.autoDownload = false;
|
||||
autoUpdater.autoInstallOnAppQuit = false;
|
||||
|
||||
autoUpdater.on("update-available", () => {
|
||||
createAndShowNotification({
|
||||
title: "WorkAdventure - Update available",
|
||||
body: "Please go to our website and install the newest version",
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
checkForUpdates();
|
||||
autoUpdater.on("update-not-available", () => {
|
||||
if (isManualRequestedUpdate) {
|
||||
createAndShowNotification({
|
||||
body: "No update available.",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// run update check every hour again
|
||||
setInterval(() => checkForUpdates, 1000 * 60 * 1);
|
||||
checkForUpdates();
|
||||
|
||||
// run update check every hour again
|
||||
setInterval(() => checkForUpdates, 1000 * 60 * 1);
|
||||
}
|
||||
|
||||
export default {
|
||||
init,
|
||||
init,
|
||||
};
|
||||
|
@ -4,67 +4,64 @@ import settings from "./settings";
|
||||
import { getAppView, getWindow } from "./window";
|
||||
|
||||
export function emitMutedKeyPress() {
|
||||
const mainWindow = getWindow();
|
||||
if (!mainWindow) {
|
||||
throw new Error("Main window not found");
|
||||
}
|
||||
const mainWindow = getWindow();
|
||||
if (!mainWindow) {
|
||||
throw new Error("Main window not found");
|
||||
}
|
||||
|
||||
mainWindow.webContents.send("app:on-muted-key-press");
|
||||
mainWindow.webContents.send("app:on-muted-key-press");
|
||||
}
|
||||
|
||||
export default () => {
|
||||
ipcMain.on("app:notify", (event, txt) => {
|
||||
createAndShowNotification({ body: txt });
|
||||
});
|
||||
ipcMain.on("app:notify", (event, txt) => {
|
||||
createAndShowNotification({ body: txt });
|
||||
});
|
||||
|
||||
ipcMain.handle("sidebar:getServers", () => {
|
||||
// TODO: remove
|
||||
if (!settings.get("servers")) {
|
||||
settings.set("servers", [
|
||||
{
|
||||
_id: "1",
|
||||
name: "WA Demo",
|
||||
url: "https://play.staging.workadventu.re/@/tcm/workadventure/wa-village",
|
||||
},
|
||||
{
|
||||
_id: "2",
|
||||
name: "My Server",
|
||||
url: "http://play.workadventure.localhost/",
|
||||
},
|
||||
]);
|
||||
}
|
||||
ipcMain.handle("sidebar:getServers", () => {
|
||||
// TODO: remove
|
||||
if (!settings.get("servers")) {
|
||||
settings.set("servers", [
|
||||
{
|
||||
_id: "1",
|
||||
name: "WA Demo",
|
||||
url: "https://play.staging.workadventu.re/@/tcm/workadventure/wa-village",
|
||||
},
|
||||
{
|
||||
_id: "2",
|
||||
name: "My Server",
|
||||
url: "http://play.workadventure.localhost/",
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
return settings.get("servers", []);
|
||||
});
|
||||
return settings.get("servers", []);
|
||||
});
|
||||
|
||||
ipcMain.handle("sidebar:selectServer", (event, serverId: string) => {
|
||||
const appView = getAppView();
|
||||
if (!appView) {
|
||||
throw new Error("App view not found");
|
||||
}
|
||||
ipcMain.handle("sidebar:selectServer", (event, serverId: string) => {
|
||||
const appView = getAppView();
|
||||
if (!appView) {
|
||||
throw new Error("App view not found");
|
||||
}
|
||||
|
||||
const servers = settings.get("servers", []);
|
||||
const selectedServer = servers.find((s) => s._id === serverId);
|
||||
const servers = settings.get("servers", []);
|
||||
const selectedServer = servers.find((s) => s._id === serverId);
|
||||
|
||||
if (!selectedServer) {
|
||||
return new Error("Server not found");
|
||||
}
|
||||
if (!selectedServer) {
|
||||
return new Error("Server not found");
|
||||
}
|
||||
|
||||
appView.webContents.loadURL(selectedServer.url);
|
||||
return true;
|
||||
});
|
||||
appView.webContents.loadURL(selectedServer.url);
|
||||
return true;
|
||||
});
|
||||
|
||||
ipcMain.handle(
|
||||
"sidebar:addServer",
|
||||
(event, serverName: string, serverUrl: string) => {
|
||||
const servers = settings.get("servers", []);
|
||||
servers.push({
|
||||
_id: `${servers.length + 1}`,
|
||||
name: serverName,
|
||||
url: serverUrl,
|
||||
});
|
||||
settings.set("servers", servers);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
ipcMain.handle("sidebar:addServer", (event, serverName: string, serverUrl: string) => {
|
||||
const servers = settings.get("servers", []);
|
||||
servers.push({
|
||||
_id: `${servers.length + 1}`,
|
||||
name: serverName,
|
||||
url: serverUrl,
|
||||
});
|
||||
settings.set("servers", servers);
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
@ -4,56 +4,53 @@ import log from "electron-log";
|
||||
import settings from "./settings";
|
||||
|
||||
function onError(e: Error) {
|
||||
try {
|
||||
log.error(e);
|
||||
try {
|
||||
log.error(e);
|
||||
|
||||
dialog.showErrorBox(
|
||||
"WorkAdventure - A JavaScript error occurred",
|
||||
e.stack || ""
|
||||
);
|
||||
} catch (logError) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(e);
|
||||
}
|
||||
dialog.showErrorBox("WorkAdventure - A JavaScript error occurred", e.stack || "");
|
||||
} catch (logError) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
function onRejection(reason: Error) {
|
||||
if (reason instanceof Error) {
|
||||
let _reason = reason;
|
||||
const errPrototype = Object.getPrototypeOf(reason);
|
||||
const nameProperty = Object.getOwnPropertyDescriptor(errPrototype, "name");
|
||||
if (reason instanceof Error) {
|
||||
let _reason = reason;
|
||||
const errPrototype = Object.getPrototypeOf(reason);
|
||||
const nameProperty = Object.getOwnPropertyDescriptor(errPrototype, "name");
|
||||
|
||||
if (!nameProperty || !nameProperty.writable) {
|
||||
_reason = new Error(reason.message);
|
||||
if (!nameProperty || !nameProperty.writable) {
|
||||
_reason = new Error(reason.message);
|
||||
}
|
||||
|
||||
_reason.name = `UnhandledRejection ${_reason.name}`;
|
||||
onError(_reason);
|
||||
return;
|
||||
}
|
||||
|
||||
_reason.name = `UnhandledRejection ${_reason.name}`;
|
||||
onError(_reason);
|
||||
return;
|
||||
}
|
||||
|
||||
const error = new Error(JSON.stringify(reason));
|
||||
error.name = "UnhandledRejection";
|
||||
onError(error);
|
||||
const error = new Error(JSON.stringify(reason));
|
||||
error.name = "UnhandledRejection";
|
||||
onError(error);
|
||||
}
|
||||
|
||||
function init() {
|
||||
const logLevel = settings.get("log_level", "info");
|
||||
log.transports.console.level = logLevel;
|
||||
log.transports.file.level = logLevel;
|
||||
const logLevel = settings.get("log_level", "info");
|
||||
log.transports.console.level = logLevel;
|
||||
log.transports.file.level = logLevel;
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log = log.log.bind(log);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log = log.log.bind(log);
|
||||
|
||||
process.on("uncaughtException", onError);
|
||||
process.on("unhandledRejection", onRejection);
|
||||
process.on("uncaughtException", onError);
|
||||
process.on("unhandledRejection", onRejection);
|
||||
}
|
||||
|
||||
export async function openLog() {
|
||||
const logFilePath = log.transports.file.getFile().path;
|
||||
await shell.openPath(logFilePath);
|
||||
const logFilePath = log.transports.file.getFile().path;
|
||||
await shell.openPath(logFilePath);
|
||||
}
|
||||
|
||||
export default {
|
||||
init,
|
||||
init,
|
||||
};
|
||||
|
@ -3,8 +3,8 @@ import log from "./log";
|
||||
import settings from "./settings";
|
||||
|
||||
async function start() {
|
||||
await settings.init();
|
||||
log.init();
|
||||
await settings.init();
|
||||
log.init();
|
||||
}
|
||||
|
||||
start();
|
||||
|
@ -1,24 +1,20 @@
|
||||
import path from "path";
|
||||
import { Notification, NotificationConstructorOptions } from "electron";
|
||||
|
||||
export function createNotification(
|
||||
options: Partial<NotificationConstructorOptions>
|
||||
) {
|
||||
const notification = new Notification({
|
||||
title: "WorkAdventure",
|
||||
icon: path.join(__dirname, "..", "assets", "icons", "logo.png"),
|
||||
...(options || {}),
|
||||
});
|
||||
export function createNotification(options: Partial<NotificationConstructorOptions>) {
|
||||
const notification = new Notification({
|
||||
title: "WorkAdventure",
|
||||
icon: path.join(__dirname, "..", "assets", "icons", "logo.png"),
|
||||
...(options || {}),
|
||||
});
|
||||
|
||||
return notification;
|
||||
return notification;
|
||||
}
|
||||
|
||||
export function createAndShowNotification(
|
||||
options: Partial<NotificationConstructorOptions>
|
||||
) {
|
||||
const notification = createNotification(options);
|
||||
export function createAndShowNotification(options: Partial<NotificationConstructorOptions>) {
|
||||
const notification = createNotification(options);
|
||||
|
||||
notification.show();
|
||||
notification.show();
|
||||
|
||||
return notification;
|
||||
return notification;
|
||||
}
|
||||
|
@ -3,42 +3,36 @@ import Settings from "electron-settings";
|
||||
import type { Server } from "./sidebar/types";
|
||||
|
||||
type SettingsData = {
|
||||
log_level: ElectronLog.LogLevel;
|
||||
auto_launch_enabled: boolean;
|
||||
servers: Server[];
|
||||
log_level: ElectronLog.LogLevel;
|
||||
auto_launch_enabled: boolean;
|
||||
servers: Server[];
|
||||
};
|
||||
|
||||
let settings: SettingsData;
|
||||
|
||||
async function init() {
|
||||
settings = (await Settings.get()) as SettingsData;
|
||||
settings = (await Settings.get()) as SettingsData;
|
||||
}
|
||||
|
||||
function get<T extends keyof SettingsData>(
|
||||
key: T,
|
||||
fallback?: SettingsData[T]
|
||||
): SettingsData[T] {
|
||||
if (settings === null) {
|
||||
throw new Error("Settings not initialized");
|
||||
}
|
||||
function get<T extends keyof SettingsData>(key: T, fallback?: SettingsData[T]): SettingsData[T] {
|
||||
if (settings === null) {
|
||||
throw new Error("Settings not initialized");
|
||||
}
|
||||
|
||||
return settings[key];
|
||||
return settings?.[key];
|
||||
}
|
||||
|
||||
export function set<T extends keyof SettingsData>(
|
||||
key: T,
|
||||
value: SettingsData[T]
|
||||
) {
|
||||
if (settings === null) {
|
||||
throw new Error("Settings not initialized");
|
||||
}
|
||||
export function set<T extends keyof SettingsData>(key: T, value: SettingsData[T]) {
|
||||
if (settings === null) {
|
||||
throw new Error("Settings not initialized");
|
||||
}
|
||||
|
||||
settings[key] = value;
|
||||
void Settings.set(settings);
|
||||
settings[key] = value;
|
||||
void Settings.set(settings);
|
||||
}
|
||||
|
||||
export default {
|
||||
init,
|
||||
get,
|
||||
set,
|
||||
init,
|
||||
get,
|
||||
set,
|
||||
};
|
||||
|
@ -2,12 +2,11 @@ import { contextBridge, ipcRenderer } from "electron";
|
||||
import type { WorkAdventureSidebarApi } from "./types";
|
||||
|
||||
const api: WorkAdventureSidebarApi = {
|
||||
desktop: true,
|
||||
getServers: () => ipcRenderer.invoke("sidebar:getServers"),
|
||||
selectServer: (serverId: string) =>
|
||||
ipcRenderer.invoke("sidebar:selectServer", serverId),
|
||||
addServer: (serverName: string, serverUrl: string) =>
|
||||
ipcRenderer.invoke("sidebar:addServer", serverName, serverUrl),
|
||||
desktop: true,
|
||||
getServers: () => ipcRenderer.invoke("sidebar:getServers"),
|
||||
selectServer: (serverId: string) => ipcRenderer.invoke("sidebar:selectServer", serverId),
|
||||
addServer: (serverName: string, serverUrl: string) =>
|
||||
ipcRenderer.invoke("sidebar:addServer", serverName, serverUrl),
|
||||
};
|
||||
|
||||
contextBridge.exposeInMainWorld("WorkAdventureDesktopApi", api);
|
||||
|
@ -1,12 +1,12 @@
|
||||
export type Server = {
|
||||
_id: string;
|
||||
name: string;
|
||||
url: string;
|
||||
_id: string;
|
||||
name: string;
|
||||
url: string;
|
||||
};
|
||||
|
||||
export type WorkAdventureSidebarApi = {
|
||||
desktop: boolean;
|
||||
getServers: () => Promise<Server[]>;
|
||||
selectServer: (serverId: string) => Promise<Error | boolean>;
|
||||
addServer: (serverName: string, serverUrl: string) => Promise<boolean>;
|
||||
desktop: boolean;
|
||||
getServers: () => Promise<Server[]>;
|
||||
selectServer: (serverId: string) => Promise<Error | boolean>;
|
||||
addServer: (serverName: string, serverUrl: string) => Promise<boolean>;
|
||||
};
|
||||
|
@ -11,70 +11,69 @@ let tray: Tray | undefined;
|
||||
const assetsDirectory = path.join(__dirname, "..", "assets");
|
||||
|
||||
export function getTray() {
|
||||
return tray;
|
||||
return tray;
|
||||
}
|
||||
|
||||
export function createTray() {
|
||||
tray = new Tray(path.join(assetsDirectory, "icons", "logo.png"));
|
||||
tray = new Tray(path.join(assetsDirectory, "icons", "logo.png"));
|
||||
|
||||
const trayContextMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
id: "open",
|
||||
label: "Show / Hide",
|
||||
click() {
|
||||
const trayContextMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
id: "open",
|
||||
label: "Show / Hide",
|
||||
click() {
|
||||
const mainWindow = getWindow();
|
||||
if (!mainWindow) {
|
||||
throw new Error("Main window not found");
|
||||
}
|
||||
|
||||
if (mainWindow.isVisible()) {
|
||||
mainWindow.hide();
|
||||
} else {
|
||||
mainWindow.show();
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Check for updates",
|
||||
async click() {
|
||||
await autoUpdater.manualRequestUpdateCheck();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Open Logs",
|
||||
click() {
|
||||
log.openLog();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "About",
|
||||
click() {
|
||||
showAboutWindow({
|
||||
icon: path.join(__dirname, "..", "assets", "icons", "logo.png"),
|
||||
copyright: "Copyright © WorkAdventure",
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Quit",
|
||||
click() {
|
||||
// app.confirmedExitPrompt = true;
|
||||
app.quit();
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
tray.setContextMenu(trayContextMenu);
|
||||
|
||||
tray.on("double-click", () => {
|
||||
const mainWindow = getWindow();
|
||||
if (!mainWindow) {
|
||||
throw new Error("Main window not found");
|
||||
throw new Error("Main window not found");
|
||||
}
|
||||
|
||||
if (mainWindow.isVisible()) {
|
||||
mainWindow.hide();
|
||||
} else {
|
||||
mainWindow.show();
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Check for updates",
|
||||
async click() {
|
||||
await autoUpdater.manualRequestUpdateCheck();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Open Logs",
|
||||
click() {
|
||||
log.openLog();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "About",
|
||||
click() {
|
||||
showAboutWindow({
|
||||
icon: path.join(__dirname, "..", "assets", "icons", "logo.png"),
|
||||
copyright: "Copyright © WorkAdventure",
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Quit",
|
||||
click() {
|
||||
app.isQuiting = true;
|
||||
app.confirmedExitPrompt = true;
|
||||
app.quit();
|
||||
},
|
||||
},
|
||||
]);
|
||||
mainWindow.show();
|
||||
});
|
||||
|
||||
tray.setContextMenu(trayContextMenu);
|
||||
|
||||
tray.on("double-click", () => {
|
||||
const mainWindow = getWindow();
|
||||
if (!mainWindow) {
|
||||
throw new Error("Main window not found");
|
||||
}
|
||||
|
||||
mainWindow.show();
|
||||
});
|
||||
|
||||
return tray;
|
||||
return tray;
|
||||
}
|
||||
|
@ -5,37 +5,37 @@ import { app } from "electron";
|
||||
import settings from "./settings";
|
||||
|
||||
export default async () => {
|
||||
let isAutoLaunchEnabled = settings.get("auto_launch_enabled");
|
||||
let isAutoLaunchEnabled = settings.get("auto_launch_enabled");
|
||||
|
||||
// set default to enabled
|
||||
if (isAutoLaunchEnabled === null) {
|
||||
settings.set("auto_launch_enabled", true);
|
||||
isAutoLaunchEnabled = true;
|
||||
}
|
||||
|
||||
// Don't run this in development
|
||||
if (isDev) {
|
||||
return;
|
||||
}
|
||||
|
||||
// `setLoginItemSettings` doesn't support linux
|
||||
if (process.platform === "linux") {
|
||||
const autoLauncher = new AutoLaunch({
|
||||
name: "WorkAdventure",
|
||||
isHidden: true,
|
||||
});
|
||||
|
||||
if (isAutoLaunchEnabled) {
|
||||
await autoLauncher.enable();
|
||||
} else {
|
||||
await autoLauncher.disable();
|
||||
// set default to enabled
|
||||
if (isAutoLaunchEnabled === null) {
|
||||
settings.set("auto_launch_enabled", true);
|
||||
isAutoLaunchEnabled = true;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
// Don't run this in development
|
||||
if (isDev) {
|
||||
return;
|
||||
}
|
||||
|
||||
app.setLoginItemSettings({
|
||||
openAtLogin: isAutoLaunchEnabled,
|
||||
openAsHidden: true,
|
||||
});
|
||||
// `setLoginItemSettings` doesn't support linux
|
||||
if (process.platform === "linux") {
|
||||
const autoLauncher = new AutoLaunch({
|
||||
name: "WorkAdventure",
|
||||
isHidden: true,
|
||||
});
|
||||
|
||||
if (isAutoLaunchEnabled) {
|
||||
await autoLauncher.enable();
|
||||
} else {
|
||||
await autoLauncher.disable();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
app.setLoginItemSettings({
|
||||
openAtLogin: isAutoLaunchEnabled,
|
||||
openAsHidden: true,
|
||||
});
|
||||
};
|
||||
|
@ -8,96 +8,96 @@ let appView: BrowserView | undefined;
|
||||
const sidebarWidth = 70;
|
||||
|
||||
export function getWindow() {
|
||||
return mainWindow;
|
||||
return mainWindow;
|
||||
}
|
||||
|
||||
export function getAppView() {
|
||||
return appView;
|
||||
return appView;
|
||||
}
|
||||
|
||||
export function createWindow() {
|
||||
// do not re-create window if still existing
|
||||
if (mainWindow) {
|
||||
return;
|
||||
}
|
||||
// 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,
|
||||
});
|
||||
// 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: {
|
||||
preload: path.join(__dirname, "../dist/sidebar/preload.js"),
|
||||
},
|
||||
});
|
||||
mainWindow = new BrowserWindow({
|
||||
x: windowState.x,
|
||||
y: windowState.y,
|
||||
width: windowState.width,
|
||||
height: windowState.height,
|
||||
autoHideMenuBar: true,
|
||||
show: false,
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, "../dist/sidebar/preload.js"),
|
||||
},
|
||||
});
|
||||
|
||||
// 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);
|
||||
// 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("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;
|
||||
// }
|
||||
// });
|
||||
// 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;
|
||||
// }
|
||||
// });
|
||||
|
||||
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,
|
||||
});
|
||||
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.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.webContents.on("did-finish-load", () => {
|
||||
mainWindow?.setTitle("WorkAdventure Desktop");
|
||||
});
|
||||
|
||||
mainWindow.loadFile("../sidebar/index.html");
|
||||
mainWindow.loadFile("../sidebar/index.html");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user