Skip to content

Commit c04a6f6

Browse files
committed
Ensure promises get completed if window is closed - #79
1 parent 100e3a7 commit c04a6f6

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

js/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ function handleCustomApp(appTemplate) {
395395
iframe : iframe,
396396
modal : modal,
397397
jsFile : "customize.js",
398-
onClose: reject,
398+
onClose: () => reject(""), // reject to ensure the promise isn't left dangling
399399
messageHandler : function(event) {
400400
let msg = event.data;
401401
if (msg.type=="app") {
@@ -446,7 +446,7 @@ function handleAppInterface(app) {
446446
iframe : iframe,
447447
modal : modal,
448448
jsFile : "interface.js",
449-
// onClose: reject, // we don't need to reject when the window is closed
449+
onClose: () => reject(""), // reject to ensure the promise isn't left dangling
450450
messageHandler : function(event) {
451451
// nothing custom needed in here
452452
}
@@ -780,7 +780,9 @@ function refreshLibrary(options) {
780780
icon.classList.add("loading");
781781
updateApp(app);
782782
} else if (icon.classList.contains("icon-interface")) {
783-
handleAppInterface(app);
783+
handleAppInterface(app).catch( err => {
784+
if (err != "") showToast("Failed, "+err, "error");
785+
});
784786
} else if ( button.classList.contains("btn-favourite")) {
785787
let favourite = SETTINGS.favourites.find(e => e == app.id);
786788
changeAppFavourite(!favourite, app);
@@ -900,7 +902,7 @@ function customApp(app) {
900902
refreshMyApps();
901903
refreshLibrary();
902904
}).catch(err => {
903-
if (err !== "Window closed")
905+
if (err != "")
904906
showToast("Customise failed, "+err, "error");
905907
refreshMyApps();
906908
refreshLibrary();
@@ -1056,7 +1058,10 @@ function refreshMyApps() {
10561058
// check icon to figure out what we should do
10571059
if (icon.classList.contains("icon-delete")) removeApp(app);
10581060
if (icon.classList.contains("icon-refresh")) updateApp(app);
1059-
if (icon.classList.contains("icon-interface")) handleAppInterface(app);
1061+
if (icon.classList.contains("icon-interface"))
1062+
handleAppInterface(app).catch( err => {
1063+
if (err != "") showToast("Failed, "+err, "error");
1064+
});
10601065
if (icon.classList.contains("icon-favourite")) {
10611066
let favourite = SETTINGS.favourites.find(e => e == app.id);
10621067
changeAppFavourite(!favourite, app);

0 commit comments

Comments
 (0)