fix loading & cleanup

This commit is contained in:
Anton Bracke 2022-02-19 01:48:56 +01:00
parent a5c7aa3969
commit 904525a084
No known key found for this signature in database
GPG Key ID: B1222603899C6B25
11 changed files with 38 additions and 38 deletions

View File

@ -1,20 +1,20 @@
appId: re.workadventu.desktop
productName: "WorkAdventure desktop"
files:
- "build/**/*"
- "dist/**/*"
- "assets/**/*"
- "local-app/**/*"
directories:
output: ./build
dmg:
icon: false
linux:
category: "TODO;TODO"
packageCategory: "TODO;TODO"
maintainer: "thecodingmachine"
icon: "assets/icons/logo.icns"
description: "Desktop app for WorkAdventure"
target:
- AppImage
artifactName: "${productName}-${version}-${arch}.${ext}"

View File

@ -1,12 +1,13 @@
{
"name": "workadventure-desktop",
"version": "1.0.0",
"description": "",
"main": "build/main.js",
"description": "Desktop application for WorkAdventure",
"author": "thecodingmachine",
"main": "dist/main.js",
"license": "SEE LICENSE IN LICENSE.txt",
"scripts": {
"build": "tsup-node -d build ./src/main.ts ./src/preload-local-app/preload.ts ./src/preload-app/preload.ts",
"dev": "yarn build --watch --onSuccess 'yarn electron build/main.js'",
"build": "tsup-node ./src/main.ts ./src/preload-local-app/preload.ts ./src/preload-app/preload.ts",
"dev": "yarn build --watch --onSuccess 'yarn electron dist/main.js'",
"bundle": "electron-builder install-app-deps && electron-builder",
"release": "yarn bundle",
"typecheck": "tsc --noEmit",

View File

@ -5,6 +5,8 @@ import { createTray } from "./tray";
import autoUpdater from "./auto-updater";
import updateAutoLaunch from "./update-auto-launch";
import ipc, { emitMutedKeyPress } from "./ipc";
import settings from "./settings";
import { setLogLevel } from "./log";
function init() {
const appLock = app.requestSingleInstanceLock();
@ -32,7 +34,12 @@ function init() {
});
// 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();
// enable auto launch

View File

@ -34,7 +34,7 @@ export default () => {
]);
}
return settings.get("servers", []);
return settings.get("servers") || [];
});
ipcMain.handle("local-app:selectServer", (event, serverId: string) => {
@ -43,7 +43,7 @@ export default () => {
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);
if (!selectedServer) {
@ -55,7 +55,7 @@ export default () => {
});
ipcMain.handle("local-app:addServer", (event, serverName: string, serverUrl: string) => {
const servers = settings.get("servers", []);
const servers = settings.get("servers") || [];
servers.push({
_id: `${servers.length + 1}`,
name: serverName,

View File

@ -1,15 +1,13 @@
import { dialog, shell } from "electron";
import ElectronLog from "electron-log";
import log from "electron-log";
import settings from "./settings";
function onError(e: Error) {
try {
log.error(e);
dialog.showErrorBox("WorkAdventure - A JavaScript error occurred", e.stack || "");
} catch (logError) {
// eslint-disable-next-line no-console
console.error(e);
}
}
@ -35,11 +33,6 @@ function onRejection(reason: Error) {
}
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);
process.on("uncaughtException", onError);
@ -51,6 +44,11 @@ export async function openLog() {
await shell.openPath(logFilePath);
}
export function setLogLevel(logLevel: ElectronLog.LogLevel) {
log.transports.console.level = logLevel;
log.transports.file.level = logLevel;
}
export default {
init,
};

View File

@ -1,11 +1,5 @@
import app from "./app";
import log from "./log";
import settings from "./settings";
async function start() {
await settings.init();
log.init();
}
start();
log.init();
app.init();

View File

@ -14,8 +14,8 @@ async function init() {
settings = (await Settings.get()) as SettingsData;
}
function get<T extends keyof SettingsData>(key: T, fallback?: SettingsData[T]): SettingsData[T] {
if (settings === null) {
function get<T extends keyof SettingsData>(key: T): SettingsData[T] | undefined {
if (settings === undefined) {
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]) {
if (settings === null) {
if (settings === undefined) {
throw new Error("Settings not initialized");
}

View File

@ -1,5 +1,5 @@
import { app, Tray, Menu } from "electron";
import * as path from "path";
import path from "path";
import { showAboutWindow } from "electron-util";
import * as autoUpdater from "./auto-updater";
@ -50,7 +50,7 @@ export function createTray() {
label: "About",
click() {
showAboutWindow({
icon: path.join(__dirname, "..", "assets", "icons", "logo.png"),
icon: path.join(assetsDirectory, "icons", "logo.png"),
copyright: "Copyright © WorkAdventure",
});
},

View File

@ -1,5 +1,5 @@
import AutoLaunch from "auto-launch";
import * as isDev from "electron-is-dev";
import isDev from "electron-is-dev";
import { app } from "electron";
import settings from "./settings";
@ -8,7 +8,7 @@ export default async () => {
let isAutoLaunchEnabled = settings.get("auto_launch_enabled");
// set default to enabled
if (isAutoLaunchEnabled === null) {
if (isAutoLaunchEnabled === undefined) {
settings.set("auto_launch_enabled", true);
isAutoLaunchEnabled = true;
}

View File

@ -36,7 +36,7 @@ export function createWindow() {
autoHideMenuBar: true,
show: false,
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({
webPreferences: {
preload: path.resolve(__dirname, "..", "build", "preload-app", "preload.js"),
preload: path.resolve(__dirname, "..", "dist", "preload-app", "preload.js"),
},
});
appView.setBounds({
@ -89,7 +89,7 @@ export function createWindow() {
// mode: "detach",
// });
mainWindow?.show();
mainWindow?.webContents.openDevTools({ mode: "detach" });
// mainWindow?.webContents.openDevTools({ mode: "detach" });
})();
});

View File

@ -14,7 +14,7 @@
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' 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. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */