Skip to content

Commit

Permalink
Merge pull request HelloZeroNet#2073 from filips123/fix-infinite-relo…
Browse files Browse the repository at this point in the history
…ading

Fix infinite reloading when system theme changes
  • Loading branch information
HelloZeroNet authored Jul 6, 2019
2 parents 951e474 + 87b4500 commit 5a74676
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
15 changes: 10 additions & 5 deletions src/Ui/media/ZeroSiteTheme.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ changeColorScheme = (theme) ->
zeroframe.cmd "userGetGlobalSettings", [], (user_settings) ->
if user_settings.theme != theme
user_settings.theme = theme
zeroframe.cmd "userSetGlobalSettings", [user_settings]

location.reload()

zeroframe.cmd "userSetGlobalSettings", [user_settings], (status) ->
if status == "ok"
location.reload()
return
return
return

Expand All @@ -21,7 +21,12 @@ displayNotification = ({matches, media}) ->
if !matches
return

zeroframe.cmd "wrapperNotification", ["info", "Your system's theme has been changed.<br>Please reload site to use it."]
zeroframe.cmd "siteInfo", [], (site_info) ->
if "ADMIN" in site_info.settings.permissions
zeroframe.cmd "wrapperNotification", ["info", "Your system's theme has been changed.<br>Please reload site to use it."]
else
zeroframe.cmd "wrapperNotification", ["info", "Your system's theme has been changed.<br>Please open ZeroHello to use it."]
return
return


Expand Down
21 changes: 15 additions & 6 deletions src/Ui/media/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -1981,7 +1981,6 @@ $.extend( $.easing,

}).call(this);


/* ---- src/Ui/media/WrapperZeroFrame.coffee ---- */


Expand Down Expand Up @@ -2037,7 +2036,8 @@ $.extend( $.easing,


(function() {
var DARK, LIGHT, changeColorScheme, detectColorScheme, displayNotification, mqDark, mqLight;
var DARK, LIGHT, changeColorScheme, detectColorScheme, displayNotification, mqDark, mqLight,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };

DARK = "(prefers-color-scheme: dark)";

Expand All @@ -2051,8 +2051,11 @@ $.extend( $.easing,
zeroframe.cmd("userGetGlobalSettings", [], function(user_settings) {
if (user_settings.theme !== theme) {
user_settings.theme = theme;
zeroframe.cmd("userSetGlobalSettings", [user_settings]);
location.reload();
zeroframe.cmd("userSetGlobalSettings", [user_settings], function(status) {
if (status === "ok") {
location.reload();
}
});
}
});
};
Expand All @@ -2063,7 +2066,13 @@ $.extend( $.easing,
if (!matches) {
return;
}
zeroframe.cmd("wrapperNotification", ["info", "Your system's theme has been changed.<br>Please reload site to use it."]);
zeroframe.cmd("siteInfo", [], function(site_info) {
if (indexOf.call(site_info.settings.permissions, "ADMIN") >= 0) {
zeroframe.cmd("wrapperNotification", ["info", "Your system's theme has been changed.<br>Please reload site to use it."]);
} else {
zeroframe.cmd("wrapperNotification", ["info", "Your system's theme has been changed.<br>Please open ZeroHello to use it."]);
}
});
};

detectColorScheme = function() {
Expand All @@ -2082,4 +2091,4 @@ $.extend( $.easing,
}
});

}).call(this);
}).call(this);

0 comments on commit 5a74676

Please sign in to comment.