Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Fix dialog/authentication issues for Edge + 365 and Desktop versions of Office #144

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@microsoft/office-js-helpers",
"description": "A collection of helpers to simplify development of Office Add-ins & Microsoft Teams Tabs",
"version": "1.0.2",
"version": "2.0.0",
"repository": {
"type": "git",
"url": "git+https://github.com/OfficeDev/office-js-helpers.git"
Expand Down
33 changes: 30 additions & 3 deletions src/helpers/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ export class Dialog<T> {
else if (Utilities.isAddin) {
this._result = this._addinDialog();
}
else if (Utilities.isEdge) {
this._result = this._edgeDialog();
}
else {
this._result = this._webDialog();
}
Expand Down Expand Up @@ -124,7 +127,7 @@ export class Dialog<T> {
try {
const options = 'width=' + this.size.width + ',height=' + this.size.height + this._windowFeatures;
window.open(this.url, this.url, options);
if (Utilities.isIEOrEdge) {
if (Utilities.isIE) {
this._pollLocalStorageForToken(resolve, reject);
}
else {
Expand All @@ -143,6 +146,30 @@ export class Dialog<T> {
});
}

private _edgeDialog(): Promise<T> {
return new Promise((resolve, reject) => {
Office.context.ui.displayDialogAsync(this.url, { width: this.size.width$, height: this.size.height$ }, (result: Office.AsyncResult) => {
if (result.status === Office.AsyncResultStatus.Failed) {
reject(new DialogError(result.error.message, result.error));
}
else {
const dialog = result.value as Office.DialogHandler;

dialog.addEventHandler(Office.EventType.DialogMessageReceived, args => {
let result = this._safeParse(args.message) as T;
resolve(result);
dialog.close();
});

dialog.addEventHandler(Office.EventType.DialogEventReceived, args => {
reject(new DialogError(args.message, args.error));
dialog.close();
});
}
});
});
}

private _pollLocalStorageForToken(resolve: (value: T) => void, reject: (reason: DialogError) => void) {
localStorage.removeItem(Dialog.key);
const POLL_INTERVAL = 400;
Expand Down Expand Up @@ -185,11 +212,11 @@ export class Dialog<T> {
microsoftTeams.initialize();
microsoftTeams.authentication.notifySuccess(JSON.stringify(<DialogResult>{ parse, value }));
}
else if (Utilities.isAddin) {
else if (Utilities.isAddin || Utilities.isEdge) {
Office.context.ui.messageParent(JSON.stringify(<DialogResult>{ parse, value }));
}
else {
if (Utilities.isIEOrEdge) {
if (Utilities.isIE) {
localStorage.setItem(Dialog.key, JSON.stringify(<DialogResult>{ parse, value }));
}
else if (window.opener) {
Expand Down
18 changes: 16 additions & 2 deletions src/helpers/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,28 @@ export class Utilities {
* Utility to check if the code is running inside of an add-in.
*/
static get isAddin() {
return Utilities.host !== HostType.WEB;
return Utilities.host !== HostType.WEB && !Utilities.isEdge;
}

/**
* Utility to check if the browser is IE11.
*/
static get isIE() {
return /Trident\//gi.test(window.navigator.userAgent);
}

/**
* Utility to check if the browser is Edge.
*/
static get isEdge() {
return /Edge\//gi.test(window.navigator.userAgent);
}

/**
* Utility to check if the browser is IE11 or Edge.
*/
static get isIEOrEdge() {
return /Edge\/|Trident\//gi.test(window.navigator.userAgent);
return Utilities.isIE || Utilities.isEdge;
}

/**
Expand Down