Skip to content

Commit

Permalink
Merge pull request #71 from WowUp/feature/2.11.0
Browse files Browse the repository at this point in the history
Feature/2.11.0
  • Loading branch information
jliddev authored Feb 5, 2024
2 parents 3a1dff6 + 44b7f18 commit 0e6c2df
Show file tree
Hide file tree
Showing 110 changed files with 22,287 additions and 42,218 deletions.
1 change: 1 addition & 0 deletions wowup-electron/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/app-builds
/release
/build
/app/utils/*.js
main.js
ipc-events.js
app-updater.js
Expand Down
2 changes: 1 addition & 1 deletion wowup-electron/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "angular-electron:build"
"buildTarget": "angular-electron:build"
}
},
"test": {
Expand Down
2 changes: 1 addition & 1 deletion wowup-electron/app/app-updater.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { app, BrowserWindow, ipcMain } from "electron";
import * as log from "electron-log";
import * as log from "electron-log/main";
import { autoUpdater } from "electron-updater";
import { IPC_APP_CHECK_UPDATE, IPC_APP_INSTALL_UPDATE, IPC_APP_UPDATE_STATE } from "../src/common/constants";
import { AppUpdateDownloadProgress, AppUpdateEvent, AppUpdateState } from "../src/common/wowup/models";
Expand Down
2 changes: 1 addition & 1 deletion wowup-electron/app/curse-folder-scanner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from "path";
import * as _ from "lodash";
import * as log from "electron-log";
import * as log from "electron-log/main";
import { exists, readDirRecursive } from "./file.utils";
import * as fsp from "fs/promises";
import { firstValueFrom, from, mergeMap, toArray } from "rxjs";
Expand Down
2 changes: 1 addition & 1 deletion wowup-electron/app/file.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { exec } from "child_process";
import * as log from "electron-log";
import * as log from "electron-log/main";
import * as fsp from "fs/promises";
import { max, sumBy } from "lodash";
import * as path from "path";
Expand Down
7 changes: 4 additions & 3 deletions wowup-electron/app/ipc-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
shell,
systemPreferences,
} from "electron";
import * as log from "electron-log";
import * as log from "electron-log/main";
import * as globrex from "globrex";
import * as _ from "lodash";
import { nanoid } from "nanoid";
Expand Down Expand Up @@ -151,6 +151,7 @@ async function getSymlinkDirs(basePath: string, files: fs.Dirent[]): Promise<Sym
return _.filter(symlinkDirs, (symDir) => symDir.isDir);
}

/* eslint-disable @typescript-eslint/no-redundant-type-constituents */
function handle(
channel: RendererChannels,
listener: (event: IpcMainInvokeEvent, ...args: any[]) => Promise<void> | any
Expand Down Expand Up @@ -499,9 +500,9 @@ export function initializeIpcHandlers(window: BrowserWindow): void {
handle("decode-product-db", async (evt, filePath: string) => {
const productDbData = await fsp.readFile(filePath);
const productDb = ProductDb.decode(productDbData);
setImmediate(() => {
setTimeout(() => {
console.log("productDb", JSON.stringify(productDb));
});
},1);

return productDb;
});
Expand Down
63 changes: 33 additions & 30 deletions wowup-electron/app/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { dialog } from "electron";
import { app, BrowserWindow, BrowserWindowConstructorOptions, powerMonitor } from "electron";
import * as log from "electron-log";
import * as log from "electron-log/main";
import { find } from "lodash";
import * as minimist from "minimist";
import { arch as osArch, release as osRelease, type as osType } from "os";
Expand Down Expand Up @@ -44,12 +44,14 @@ import { initializeDefaultPreferences } from "./preferences";
import { PUSH_NOTIFICATION_EVENT, pushEvents } from "./push";
import { getPreferenceStore, initializeStoreIpcHandlers } from "./stores";
import * as windowState from "./window-state";
import { validateGpuCache } from "./utils/gpu-cache-buster";

// LOGGING SETUP
// Override the default log path so they aren't a pain to find on Mac
const LOG_PATH = join(app.getPath("userData"), "logs");
app.setAppLogsPath(LOG_PATH);
log.transports.file.resolvePath = (variables: log.PathVariables) => {
log.initialize();
log.transports.file.resolvePathFn = (variables) => {
return join(LOG_PATH, variables.fileName ?? "log-file.txt");
};
log.info("Main starting");
Expand All @@ -73,6 +75,8 @@ if (platform.isWin) {
require("win-ca");
}

validateGpuCache(app)

// VARIABLES
const startedAt = Date.now();
const argv = minimist(process.argv.slice(1), {
Expand Down Expand Up @@ -152,16 +156,35 @@ function getProtocol(arg: string) {
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
// Added 400 ms to fix the black background issue while using transparent window. More details at https://github.com/electron/electron/issues/15947
if (app.isReady()) {
log.info(`App already ready: ${Date.now() - startedAt}ms`);
} else {
app.once("ready", () => {
app
.whenReady()
.then(() => {
powerMonitor.on("resume", () => {
log.info("powerMonitor resume");
win?.webContents?.send(IPC_POWER_MONITOR_RESUME);
});

powerMonitor.on("suspend", () => {
log.info("powerMonitor suspend");
win?.webContents?.send(IPC_POWER_MONITOR_SUSPEND);
});

powerMonitor.on("lock-screen", () => {
log.info("powerMonitor lock-screen");
win?.webContents?.send(IPC_POWER_MONITOR_LOCK);
});

powerMonitor.on("unlock-screen", () => {
log.info("powerMonitor unlock-screen");
win?.webContents?.send(IPC_POWER_MONITOR_UNLOCK);
});

log.info(`App ready: ${Date.now() - startedAt}ms`);
// setTimeout(() => {
createWindow();
// }, 400);
})
.catch((e) => {
log.error("whenready failed", e);
});
}

app.on("before-quit", () => {
windowState.saveWindowConfig(win);
Expand Down Expand Up @@ -207,26 +230,6 @@ if (platform.isMac) {
});
}

powerMonitor.on("resume", () => {
log.info("powerMonitor resume");
win?.webContents?.send(IPC_POWER_MONITOR_RESUME);
});

powerMonitor.on("suspend", () => {
log.info("powerMonitor suspend");
win?.webContents?.send(IPC_POWER_MONITOR_SUSPEND);
});

powerMonitor.on("lock-screen", () => {
log.info("powerMonitor lock-screen");
win?.webContents?.send(IPC_POWER_MONITOR_LOCK);
});

powerMonitor.on("unlock-screen", () => {
log.info("powerMonitor unlock-screen");
win?.webContents?.send(IPC_POWER_MONITOR_UNLOCK);
});

let lastCrash = 0;

const crashMap = new Map<string, number>();
Expand All @@ -247,7 +250,7 @@ function onChildProcessCrashed(details: Electron.Details) {
if (ct >= 3) {
dialog.showErrorBox(
"Child Process Failure",
`Child process ${details.serviceName} has crashed too many times, app will now exit`
`Child process ${details.serviceName} has crashed too many times, app will now exit`,
);
app.quit();
}
Expand Down
2 changes: 1 addition & 1 deletion wowup-electron/app/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from "../src/common/constants";
import { WowUpReleaseChannelType } from "../src/common/wowup/wowup-release-channel-type";
import { getPreferenceStore } from "./stores";
import * as log from "electron-log";
import * as log from "electron-log/main";

export function initializeDefaultPreferences() {
const isBetaBuild = app.getVersion().toLowerCase().indexOf("beta") != -1;
Expand Down
7 changes: 1 addition & 6 deletions wowup-electron/app/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
/// <reference path="../src/common/wowup.d.ts" />

import { ipcRenderer, IpcRendererEvent, shell, OpenExternalOptions } from "electron";
import * as log from "electron-log";
import { join } from "path";
import * as log from "electron-log/renderer";
import * as platform from "./platform";

if (!process.isMainFrame) {
Expand Down Expand Up @@ -38,10 +37,6 @@ const LOG_PATH = getArg("log-path");
const USER_DATA_PATH = getArg("user-data-path");
const BASE_BG_COLOR = getArg("base-bg-color");

log.transports.file.resolvePath = (variables: log.PathVariables) => {
return join(LOG_PATH, variables.fileName);
};

function onRendererEvent(channel: string, listener: (event: IpcRendererEvent, ...args: any[]) => void) {
ipcRenderer.on(channel, listener);
}
Expand Down
2 changes: 1 addition & 1 deletion wowup-electron/app/push.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as log from "electron-log";
import * as log from "electron-log/main";
import { EventEmitter } from "events";

export const PUSH_NOTIFICATION_EVENT = "push-notification";
Expand Down
81 changes: 81 additions & 0 deletions wowup-electron/app/utils/gpu-cache-buster.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import * as fs from "fs";
import { join } from "path";
import * as log from "electron-log/main";

/**
* There appears to be some issue with Ubuntu and the GPUCache system of electron
* https://github.com/WowUp/WowUp.CF/issues/63
*
* User from an app with similar issue discovered deleting the folder and letting the app rebuild it appears to fix it.
* https://github.com/ferdium/ferdium-app/issues/1265
*
* Added in a version file to the GPU cache folder that should get checked and delete the folder before the initial
* cache is generated hopefully fixing this issue
*/

const GPU_CACHE_FOLDER = "GPUCache";
const GPU_VERSION_FILE = ".wuversion";

interface VersionFileData {
version: string;
}

export function validateGpuCache(app: Electron.App) {
try {
const cacheDir = join(app.getPath("userData"), GPU_CACHE_FOLDER);
const cacheExists = fileExists(cacheDir);
if (cacheExists) {
const files = fs.readdirSync(cacheDir);
const verFile = files.find((f) => f === GPU_VERSION_FILE);
if (verFile === undefined) {
removeDir(cacheDir);
} else {
const verFile = readVersionFile(cacheDir);
if (verFile.version !== app.getVersion()) {
removeDir(cacheDir);
} else {
return;
}
}
}

fs.mkdirSync(cacheDir);
createVersionFile(app.getVersion(), cacheDir);
} catch (e) {
log.error("failed to validate GPU Cache", e);
}
// app.relaunch();
}

function removeDir(path: string) {
fs.rmSync(path, { force: true, recursive: true });
}

function fileExists(path: string) {
try {
fs.accessSync(path);
return true;
} catch (e) {
log.warn(`File does not exist: ${path}`);
log.warn(e.message);
return false;
}
}

function readVersionFile(cacheDir: string): VersionFileData {
const filePath = join(cacheDir, GPU_VERSION_FILE);
const fileData = fs.readFileSync(filePath, { encoding: "utf-8" });
const versionData: VersionFileData = JSON.parse(fileData);
return versionData;
}

function createVersionFile(version: string, cacheDir: string) {
const versionData: VersionFileData = {
version,
};

const filePath = join(cacheDir, GPU_VERSION_FILE);
const verFileData = JSON.stringify(versionData);

fs.writeFileSync(filePath, verFileData, { encoding: "utf-8" });
}
2 changes: 1 addition & 1 deletion wowup-electron/app/window-state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { app, BrowserWindow, BrowserWindowConstructorOptions, Display, Rectangle, screen } from "electron";
import * as log from "electron-log";
import * as log from "electron-log/main";

import { IPC_WINDOW_RESUME, MIN_VISIBLE_ON_SCREEN, WINDOW_MIN_HEIGHT, WINDOW_MIN_WIDTH } from "../src/common/constants";
import * as platform from "./platform";
Expand Down
Loading

0 comments on commit 0e6c2df

Please sign in to comment.