From 395cbf9c9e4566c42579a28160ed701a73522d47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Vay=C3=A1?= Date: Tue, 19 Nov 2019 11:31:32 +0100 Subject: [PATCH] [MM-19963] set working directory on start (#1105) * [MM-19963] set current working directory for the app * prevent failing if env variables are not setup * [MM-19963] cwd if not in dev mode and only if necessary, log it if it happens * fix remove path if no cert is present * address CR suggestions --- scripts/Makefile.ps1 | 2 +- scripts/notarize.js | 5 ++++- src/main.js | 8 +++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/Makefile.ps1 b/scripts/Makefile.ps1 index 067eaee8..e5ba939b 100644 --- a/scripts/Makefile.ps1 +++ b/scripts/Makefile.ps1 @@ -439,7 +439,7 @@ function Get-Cert { } function Remove-Cert { - if (Test-Path $env:PFX) { + if (Test-Path 'env:PFX') { Print-Info "Removing windows certificate" Remove-Item -path "./mattermost-desktop-windows.pfx" } diff --git a/scripts/notarize.js b/scripts/notarize.js index 8f230d3b..cd31265e 100644 --- a/scripts/notarize.js +++ b/scripts/notarize.js @@ -14,7 +14,10 @@ exports.default = async function notarizing(context) { } const appName = context.packager.appInfo.productFilename; - + if (typeof process.env.APPLEID === 'undefined') { + console.log('skipping notarization, remember to setup environment variables for APPLEID and APPLEIDPASS if you want to notarize'); + return; + } await notarize({ // should we change it to appBundleId: 'com.mattermost.desktop', diff --git a/src/main.js b/src/main.js index 08e0a9e0..01e41b4e 100644 --- a/src/main.js +++ b/src/main.js @@ -89,7 +89,6 @@ const customLogins = {}; */ async function initialize() { process.on('uncaughtException', criticalErrorHandler.processUncaughtExceptionHandler.bind(criticalErrorHandler)); - global.willAppQuit = false; // initialization that can run before the app is ready @@ -167,6 +166,13 @@ function initializeAppEventListeners() { function initializeBeforeAppReady() { certificateStore = CertificateStore.load(path.resolve(app.getPath('userData'), 'certificate.json')); + // prevent using a different working directory, which happens on windows running after installation. + const expectedPath = path.dirname(process.execPath); + if (process.cwd() !== expectedPath && !isDev) { + console.warn(`Current working directory is ${process.cwd()}, changing into ${expectedPath}`); + process.chdir(expectedPath); + } + // can only call this before the app is ready if (config.enableHardwareAcceleration === false) { app.disableHardwareAcceleration();