fix loading & cleanup
This commit is contained in:
parent
a5c7aa3969
commit
904525a084
@ -1,20 +1,20 @@
|
|||||||
appId: re.workadventu.desktop
|
appId: re.workadventu.desktop
|
||||||
productName: "WorkAdventure desktop"
|
|
||||||
|
|
||||||
files:
|
files:
|
||||||
- "build/**/*"
|
- "dist/**/*"
|
||||||
- "assets/**/*"
|
- "assets/**/*"
|
||||||
- "local-app/**/*"
|
- "local-app/**/*"
|
||||||
|
|
||||||
|
directories:
|
||||||
|
output: ./build
|
||||||
|
|
||||||
dmg:
|
dmg:
|
||||||
icon: false
|
icon: false
|
||||||
|
|
||||||
linux:
|
linux:
|
||||||
category: "TODO;TODO"
|
category: "TODO;TODO"
|
||||||
packageCategory: "TODO;TODO"
|
packageCategory: "TODO;TODO"
|
||||||
maintainer: "thecodingmachine"
|
|
||||||
icon: "assets/icons/logo.icns"
|
icon: "assets/icons/logo.icns"
|
||||||
description: "Desktop app for WorkAdventure"
|
|
||||||
target:
|
target:
|
||||||
- AppImage
|
- AppImage
|
||||||
artifactName: "${productName}-${version}-${arch}.${ext}"
|
artifactName: "${productName}-${version}-${arch}.${ext}"
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "workadventure-desktop",
|
"name": "workadventure-desktop",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "Desktop application for WorkAdventure",
|
||||||
"main": "build/main.js",
|
"author": "thecodingmachine",
|
||||||
|
"main": "dist/main.js",
|
||||||
"license": "SEE LICENSE IN LICENSE.txt",
|
"license": "SEE LICENSE IN LICENSE.txt",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsup-node -d build ./src/main.ts ./src/preload-local-app/preload.ts ./src/preload-app/preload.ts",
|
"build": "tsup-node ./src/main.ts ./src/preload-local-app/preload.ts ./src/preload-app/preload.ts",
|
||||||
"dev": "yarn build --watch --onSuccess 'yarn electron build/main.js'",
|
"dev": "yarn build --watch --onSuccess 'yarn electron dist/main.js'",
|
||||||
"bundle": "electron-builder install-app-deps && electron-builder",
|
"bundle": "electron-builder install-app-deps && electron-builder",
|
||||||
"release": "yarn bundle",
|
"release": "yarn bundle",
|
||||||
"typecheck": "tsc --noEmit",
|
"typecheck": "tsc --noEmit",
|
||||||
|
@ -5,6 +5,8 @@ import { createTray } from "./tray";
|
|||||||
import autoUpdater from "./auto-updater";
|
import autoUpdater from "./auto-updater";
|
||||||
import updateAutoLaunch from "./update-auto-launch";
|
import updateAutoLaunch from "./update-auto-launch";
|
||||||
import ipc, { emitMutedKeyPress } from "./ipc";
|
import ipc, { emitMutedKeyPress } from "./ipc";
|
||||||
|
import settings from "./settings";
|
||||||
|
import { setLogLevel } from "./log";
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
const appLock = app.requestSingleInstanceLock();
|
const appLock = app.requestSingleInstanceLock();
|
||||||
@ -32,7 +34,12 @@ function init() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// This method will be called when Electron has finished loading
|
// This method will be called when Electron has finished loading
|
||||||
app.on("ready", () => {
|
app.on("ready", async () => {
|
||||||
|
await settings.init();
|
||||||
|
|
||||||
|
const logLevel = settings.get("log_level");
|
||||||
|
setLogLevel(logLevel || "info");
|
||||||
|
|
||||||
autoUpdater.init();
|
autoUpdater.init();
|
||||||
|
|
||||||
// enable auto launch
|
// enable auto launch
|
||||||
|
@ -34,7 +34,7 @@ export default () => {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return settings.get("servers", []);
|
return settings.get("servers") || [];
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle("local-app:selectServer", (event, serverId: string) => {
|
ipcMain.handle("local-app:selectServer", (event, serverId: string) => {
|
||||||
@ -43,7 +43,7 @@ export default () => {
|
|||||||
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) {
|
||||||
@ -55,7 +55,7 @@ export default () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle("local-app:addServer", (event, serverName: string, serverUrl: string) => {
|
ipcMain.handle("local-app:addServer", (event, serverName: string, serverUrl: string) => {
|
||||||
const servers = settings.get("servers", []);
|
const servers = settings.get("servers") || [];
|
||||||
servers.push({
|
servers.push({
|
||||||
_id: `${servers.length + 1}`,
|
_id: `${servers.length + 1}`,
|
||||||
name: serverName,
|
name: serverName,
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
import { dialog, shell } from "electron";
|
import { dialog, shell } from "electron";
|
||||||
|
import ElectronLog from "electron-log";
|
||||||
import log from "electron-log";
|
import log from "electron-log";
|
||||||
|
|
||||||
import settings from "./settings";
|
|
||||||
|
|
||||||
function onError(e: Error) {
|
function onError(e: Error) {
|
||||||
try {
|
try {
|
||||||
log.error(e);
|
log.error(e);
|
||||||
|
|
||||||
dialog.showErrorBox("WorkAdventure - A JavaScript error occurred", e.stack || "");
|
dialog.showErrorBox("WorkAdventure - A JavaScript error occurred", e.stack || "");
|
||||||
} catch (logError) {
|
} catch (logError) {
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,11 +33,6 @@ function onRejection(reason: Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
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);
|
console.log = log.log.bind(log);
|
||||||
|
|
||||||
process.on("uncaughtException", onError);
|
process.on("uncaughtException", onError);
|
||||||
@ -51,6 +44,11 @@ export async function openLog() {
|
|||||||
await shell.openPath(logFilePath);
|
await shell.openPath(logFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setLogLevel(logLevel: ElectronLog.LogLevel) {
|
||||||
|
log.transports.console.level = logLevel;
|
||||||
|
log.transports.file.level = logLevel;
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
init,
|
init,
|
||||||
};
|
};
|
||||||
|
@ -1,11 +1,5 @@
|
|||||||
import app from "./app";
|
import app from "./app";
|
||||||
import log from "./log";
|
import log from "./log";
|
||||||
import settings from "./settings";
|
|
||||||
|
|
||||||
async function start() {
|
log.init();
|
||||||
await settings.init();
|
|
||||||
log.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
start();
|
|
||||||
app.init();
|
app.init();
|
||||||
|
@ -14,8 +14,8 @@ 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] {
|
function get<T extends keyof SettingsData>(key: T): SettingsData[T] | undefined {
|
||||||
if (settings === null) {
|
if (settings === undefined) {
|
||||||
throw new Error("Settings not initialized");
|
throw new Error("Settings not initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ function get<T extends keyof SettingsData>(key: T, fallback?: SettingsData[T]):
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function set<T extends keyof SettingsData>(key: T, value: SettingsData[T]) {
|
export function set<T extends keyof SettingsData>(key: T, value: SettingsData[T]) {
|
||||||
if (settings === null) {
|
if (settings === undefined) {
|
||||||
throw new Error("Settings not initialized");
|
throw new Error("Settings not initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { app, Tray, Menu } from "electron";
|
import { app, Tray, Menu } from "electron";
|
||||||
import * as path from "path";
|
import path from "path";
|
||||||
import { showAboutWindow } from "electron-util";
|
import { showAboutWindow } from "electron-util";
|
||||||
|
|
||||||
import * as autoUpdater from "./auto-updater";
|
import * as autoUpdater from "./auto-updater";
|
||||||
@ -50,7 +50,7 @@ export function createTray() {
|
|||||||
label: "About",
|
label: "About",
|
||||||
click() {
|
click() {
|
||||||
showAboutWindow({
|
showAboutWindow({
|
||||||
icon: path.join(__dirname, "..", "assets", "icons", "logo.png"),
|
icon: path.join(assetsDirectory, "icons", "logo.png"),
|
||||||
copyright: "Copyright © WorkAdventure",
|
copyright: "Copyright © WorkAdventure",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import AutoLaunch from "auto-launch";
|
import AutoLaunch from "auto-launch";
|
||||||
import * as isDev from "electron-is-dev";
|
import isDev from "electron-is-dev";
|
||||||
import { app } from "electron";
|
import { app } from "electron";
|
||||||
|
|
||||||
import settings from "./settings";
|
import settings from "./settings";
|
||||||
@ -8,7 +8,7 @@ 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 === undefined) {
|
||||||
settings.set("auto_launch_enabled", true);
|
settings.set("auto_launch_enabled", true);
|
||||||
isAutoLaunchEnabled = true;
|
isAutoLaunchEnabled = true;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ export function createWindow() {
|
|||||||
autoHideMenuBar: true,
|
autoHideMenuBar: true,
|
||||||
show: false,
|
show: false,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: path.resolve(__dirname, "..", "build", "preload-local-app", "preload.js"),
|
preload: path.resolve(__dirname, "..", "dist", "preload-local-app", "preload.js"),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ export function createWindow() {
|
|||||||
|
|
||||||
appView = new BrowserView({
|
appView = new BrowserView({
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: path.resolve(__dirname, "..", "build", "preload-app", "preload.js"),
|
preload: path.resolve(__dirname, "..", "dist", "preload-app", "preload.js"),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
appView.setBounds({
|
appView.setBounds({
|
||||||
@ -89,7 +89,7 @@ export function createWindow() {
|
|||||||
// mode: "detach",
|
// mode: "detach",
|
||||||
// });
|
// });
|
||||||
mainWindow?.show();
|
mainWindow?.show();
|
||||||
mainWindow?.webContents.openDevTools({ mode: "detach" });
|
// mainWindow?.webContents.openDevTools({ mode: "detach" });
|
||||||
})();
|
})();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||||
"sourceMap": true, /* Generates corresponding '.map' file. */
|
"sourceMap": true, /* Generates corresponding '.map' file. */
|
||||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||||
"outDir": "./build", /* Redirect output structure to the directory. */
|
"outDir": "./dist", /* Redirect output structure to the directory. */
|
||||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||||
// "composite": true, /* Enable project compilation */
|
// "composite": true, /* Enable project compilation */
|
||||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||||
|
Loading…
Reference in New Issue
Block a user