From 1864a19c6395d2dcc49071700ce99f2cc2979802 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 27 Oct 2019 19:33:00 +0100 Subject: [PATCH] Updated some stuff --- .gitignore | 1 + main.ts | 7 ++----- modules/crash_handler/index.ts | 11 +---------- modules/shared/require.ts | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 modules/shared/require.ts diff --git a/.gitignore b/.gitignore index 2fb4370..eabfc8f 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ updater/postzip/TeaClient-linux.tar.gz !modules/renderer/imports/.copy_*.d.ts package-lock.json +npm-debug.log \ No newline at end of file diff --git a/main.ts b/main.ts index c0cf6c6..c5cb887 100644 --- a/main.ts +++ b/main.ts @@ -1,10 +1,7 @@ import * as electron from "electron"; import * as os from "os"; - -{ - const app_path = electron.app.getAppPath(); - console.log("Native module path: %s", app_path + "/native/build/" + os.platform() + "_" + os.arch() + "/"); -} +import * as rhelper from "./modules/shared/require"; +console.log("Native module path: %s", rhelper.native_module_path()); import * as crash_handler from "./modules/crash_handler"; diff --git a/modules/crash_handler/index.ts b/modules/crash_handler/index.ts index 7d67d7a..785d88e 100644 --- a/modules/crash_handler/index.ts +++ b/modules/crash_handler/index.ts @@ -1,3 +1,4 @@ +require("../shared/require").setup_require(module); import {app, BrowserWindow, remote} from "electron"; import * as path from "path"; import * as electron from "electron"; @@ -72,16 +73,6 @@ export function handle_crash_callback(args: string[]) { crash_window.focus(); }); } - -module.paths.push(...(() => { - const app_path = (remote || electron).app.getAppPath(); - const result = []; - result.push(app_path + "/native/build/" + os.platform() + "_" + os.arch() + "/"); - if(app_path.endsWith(".asar")) - result.push(path.join(path.dirname(app_path), "natives")); - return result; -})()); - export const handler = require( "teaclient_crash_handler"); export function initialize_handler(component_name: string, requires_file: boolean) { diff --git a/modules/shared/require.ts b/modules/shared/require.ts new file mode 100644 index 0000000..62f1540 --- /dev/null +++ b/modules/shared/require.ts @@ -0,0 +1,33 @@ +import {remote} from "electron"; +import * as electron from "electron"; +import * as os from "os"; +import * as path from "path"; + +export function setup_require(module: NodeModule) { + module.paths.push(native_module_path()); +} + +export function native_module_path() { + const app_path = (remote || electron).app.getAppPath(); + + if(!app_path.endsWith(".asar")) { + if(os.platform() === "win32" && false) { + const win64 = process.env.hasOwnProperty('ProgramFiles(x86)'); + return path.join( + app_path, + "native", + "build", + os.platform() + "_" + (win64 ? "x64" : "x86") + ); + } else { + return path.join( + app_path, + "native", + "build", + os.platform() + "_" + os.arch() + ); + } + } else { + return path.join(path.dirname(app_path), "natives"); + } +} \ No newline at end of file