From 61a8cffb7e9cd45caf024d93b3ea2d148b0fda77 Mon Sep 17 00:00:00 2001 From: Michael Zlatkovsky Date: Mon, 6 May 2019 12:54:15 -0700 Subject: [PATCH 1/2] Fix Utilities.host/Utilities.platform Before this fix, "host" would return "undefined" instead of web. This also fixes #133 --- src/helpers/utilities.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/helpers/utilities.ts b/src/helpers/utilities.ts index 69230b9..5e270f5 100644 --- a/src/helpers/utilities.ts +++ b/src/helpers/utilities.ts @@ -45,7 +45,13 @@ function getHostInfo(): { // when queried from within an add-in. // If the platform already exposes that info, then just return it // (but only after massaging it to fit the return types expected by this function) - const context: IContext = ((window as any).Office && (window as any).Office.context) || useHostInfoFallbackLogic(); + const isHostExposedNatively = + (window as any).Office && + (window as any).Office.context && + (window as any).Office.context.host; + const context: IContext = isHostExposedNatively + ? (window as any).Office.context + : useHostInfoFallbackLogic(); return { host: convertHostValue(context.host), platform: convertPlatformValue(context.platform) From 28966a14ea22ca386ce2fce699328d69eb9cfcc3 Mon Sep 17 00:00:00 2001 From: Zlatkovsky Date: Mon, 6 May 2019 14:06:40 -0700 Subject: [PATCH 2/2] Minor tweak per CR comment --- src/helpers/utilities.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/helpers/utilities.ts b/src/helpers/utilities.ts index 5e270f5..eca8f7a 100644 --- a/src/helpers/utilities.ts +++ b/src/helpers/utilities.ts @@ -45,12 +45,10 @@ function getHostInfo(): { // when queried from within an add-in. // If the platform already exposes that info, then just return it // (but only after massaging it to fit the return types expected by this function) - const isHostExposedNatively = - (window as any).Office && - (window as any).Office.context && - (window as any).Office.context.host; + const Office = (window as any).Office as { context: IContext }; + const isHostExposedNatively = Office && Office.context && Office.context.host; const context: IContext = isHostExposedNatively - ? (window as any).Office.context + ? Office.context : useHostInfoFallbackLogic(); return { host: convertHostValue(context.host),