mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 23:07:28 +08:00
FEATURE: automatically update site to latest version of assets
if a user neglects to move around the site it will prompt to do so 2 hours in
This commit is contained in:
@ -130,6 +130,11 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
requiresRefresh: function(){
|
||||||
|
var desired = Discourse.get("desiredAssetVersion");
|
||||||
|
return desired && Discourse.get("currentAssetVersion") !== desired;
|
||||||
|
}.property("currentAssetVersion", "desiredAssetVersion"),
|
||||||
|
|
||||||
assetVersion: function(prop, val) {
|
assetVersion: function(prop, val) {
|
||||||
if(val) {
|
if(val) {
|
||||||
if(this.get("currentAssetVersion")){
|
if(this.get("currentAssetVersion")){
|
||||||
|
@ -6,6 +6,17 @@ Discourse.addInitializer(function() {
|
|||||||
Discourse.MessageBus.start();
|
Discourse.MessageBus.start();
|
||||||
Discourse.MessageBus.subscribe("/global/asset-version", function(version){
|
Discourse.MessageBus.subscribe("/global/asset-version", function(version){
|
||||||
Discourse.set("assetVersion",version);
|
Discourse.set("assetVersion",version);
|
||||||
|
|
||||||
|
if(Discourse.get("requiresRefresh")) {
|
||||||
|
// since we can do this transparently for people browsing the forum
|
||||||
|
// hold back the message a couple of hours
|
||||||
|
setTimeout(function() {
|
||||||
|
bootbox.confirm(I18n.lookup("assets_changed_confirm"), function(){
|
||||||
|
document.location.reload();
|
||||||
|
});
|
||||||
|
}, 1000 * 60 * 120);
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
Discourse.KeyValueStore.init("discourse_", Discourse.MessageBus);
|
Discourse.KeyValueStore.init("discourse_", Discourse.MessageBus);
|
||||||
}, true);
|
}, true);
|
||||||
|
@ -48,14 +48,10 @@ Discourse.URL = Em.Object.createWithMixins({
|
|||||||
**/
|
**/
|
||||||
routeTo: function(path) {
|
routeTo: function(path) {
|
||||||
|
|
||||||
// If somehow our asset version changed, force a full reload of desired path
|
if(Discourse.get("requiresRefresh")){
|
||||||
var desired = Discourse.get("desiredAssetVersion");
|
|
||||||
if(desired) {
|
|
||||||
if(Discourse.get("currentAssetVersion") !== desired){
|
|
||||||
document.location.href = path;
|
document.location.href = path;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var oldPath = window.location.pathname;
|
var oldPath = window.location.pathname;
|
||||||
path = path.replace(/https?\:\/\/[^\/]+/, '');
|
path = path.replace(/https?\:\/\/[^\/]+/, '');
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
Discourse.SiteSettings = PreloadStore.get('siteSettings');
|
Discourse.SiteSettings = PreloadStore.get('siteSettings');
|
||||||
Discourse.Router.map(function() { Discourse.routeBuilder.call(this); });
|
Discourse.Router.map(function() { Discourse.routeBuilder.call(this); });
|
||||||
Discourse.start()
|
Discourse.start()
|
||||||
Discourse.set('assetVersion','<%= Rails.application.assets.digest %>');
|
Discourse.set('assetVersion','<%= Discourse.assets_digest %>');
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<%= javascript_include_tag 'browser-update.js' %>
|
<%= javascript_include_tag 'browser-update.js' %>
|
||||||
|
@ -37,11 +37,3 @@ end
|
|||||||
|
|
||||||
MessageBus.cache_assets = !Rails.env.development?
|
MessageBus.cache_assets = !Rails.env.development?
|
||||||
MessageBus.enable_diagnostics
|
MessageBus.enable_diagnostics
|
||||||
|
|
||||||
digest = Rails.application.assets.digest.to_s
|
|
||||||
channel = "/global/asset-version"
|
|
||||||
message = MessageBus.last_message(channel)
|
|
||||||
|
|
||||||
unless message && message.data == digest
|
|
||||||
MessageBus.publish channel, digest
|
|
||||||
end
|
|
||||||
|
@ -387,6 +387,7 @@ en:
|
|||||||
|
|
||||||
loading: "Loading..."
|
loading: "Loading..."
|
||||||
close: "Close"
|
close: "Close"
|
||||||
|
assets_changed_confirm: "Discourse has been updated, would you like to refresh to get the latest version?"
|
||||||
learn_more: "learn more..."
|
learn_more: "learn more..."
|
||||||
|
|
||||||
year: 'year'
|
year: 'year'
|
||||||
|
@ -59,6 +59,20 @@ module Discourse
|
|||||||
@plugins
|
@plugins
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.assets_digest
|
||||||
|
@assets_digest ||= begin
|
||||||
|
digest = Digest::MD5.hexdigest(ActionView::Base.assets_manifest.assets.values.sort.join)
|
||||||
|
|
||||||
|
channel = "/global/asset-version"
|
||||||
|
message = MessageBus.last_message(channel)
|
||||||
|
|
||||||
|
unless message && message.data == digest
|
||||||
|
MessageBus.publish channel, digest
|
||||||
|
end
|
||||||
|
digest
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.authenticators
|
def self.authenticators
|
||||||
# TODO: perhaps we don't need auth providers and authenticators maybe one object is enough
|
# TODO: perhaps we don't need auth providers and authenticators maybe one object is enough
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user