From 9b988f6c69ff37baac235e8fb4ab8317883285c4 Mon Sep 17 00:00:00 2001 From: Herman Ho Date: Wed, 9 Oct 2024 01:10:48 +0100 Subject: [PATCH] fix: wrap require("electron") inside the function --- CHANGELOG.md | 3 +++ msal/AuthProvider.js | 10 ++++++++-- package-lock.json | 4 ++-- package.json | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fb499f..4306ec8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # MMM-OneDrive Change Log +**`[1.1.1] - 2024/10/09`** +fix: wrap require("electron") inside the function for the headless environment + **`[1.1.0] - 2024/08/15`** - Fixed: albumn info did not show when startup caching - Fixed: depedencies packages update diff --git a/msal/AuthProvider.js b/msal/AuthProvider.js index e961c28..ec8e4df 100644 --- a/msal/AuthProvider.js +++ b/msal/AuthProvider.js @@ -4,7 +4,6 @@ */ const { PublicClientApplication, InteractionRequiredAuthError, ServerError } = require("@azure/msal-node"); -const { shell } = require("electron"); class AuthProvider { msalConfig; @@ -55,6 +54,7 @@ class AuthProvider { * https://learn.microsoft.com/azure/active-directory/develop/v2-protocols-oidc#send-a-sign-out-request */ if (this.account.idTokenClaims.hasOwnProperty("login_hint")) { + const { shell } = require("electron"); await shell.openExternal(`${this.msalConfig.auth.authority}/oauth2/v2.0/logout?logout_hint=${encodeURIComponent(this.account.idTokenClaims.login_hint)}`); } @@ -98,7 +98,13 @@ class AuthProvider { async getTokenInteractive(tokenRequest) { const openBrowser = async (url) => { - await shell.openExternal(url); + try { + const { shell } = require("electron"); + await shell.openExternal(url); + } catch (e) { + console.error("Unable to open external browser. Please run the module with a screen UI environment ", e); + throw e; + } }; const authResponse = await this.clientApplication.acquireTokenInteractive({ diff --git a/package-lock.json b/package-lock.json index 6f78f46..a768fb9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mmm-onedrive", - "version": "1.1.0", + "version": "1.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "mmm-onedrive", - "version": "1.1.0", + "version": "1.1.1", "license": "MIT", "dependencies": { "@azure/msal-node": "^2.13.0", diff --git a/package.json b/package.json index 47d2847..b46e8e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mmm-onedrive", - "version": "1.1.0", + "version": "1.1.1", "description": "MagicMirror² module to display your photos from OneDrive.", "license": "MIT", "author": "hermanho",