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