Skip to content

Commit 73f6d38

Browse files
committed
Add minimumCompatibleVersion and update refresh modal to show more detail informations
1 parent 03e68f9 commit 73f6d38

File tree

5 files changed

+60
-28
lines changed

5 files changed

+60
-28
lines changed

lib/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ function getserverurl() {
7878
}
7979

8080
var version = '0.4.2';
81+
var minimumCompatibleVersion = '0.4.2';
8182
var maintenance = true;
8283
var cwd = path.join(__dirname, '..');
8384

8485
module.exports = {
8586
version: version,
87+
minimumCompatibleVersion: minimumCompatibleVersion,
8688
maintenance: maintenance,
8789
debug: debug,
8890
urlpath: urlpath,

lib/realtime.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,10 @@ function connection(socket) {
708708

709709
//check version
710710
socket.on('version', function () {
711-
socket.emit('version', config.version);
711+
socket.emit('version', {
712+
version: config.version,
713+
minimumCompatibleVersion: config.minimumCompatibleVersion
714+
});
712715
});
713716

714717
//received cursor focus

public/js/index.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -629,15 +629,23 @@ function idleStateChange() {
629629
updateTitleReminder();
630630
}
631631

632-
function setNeedRefresh() {
632+
function setRefreshModal(status) {
633633
$('#refreshModal').modal('show');
634+
$('#refreshModal').find('.modal-body > div').hide();
635+
$('#refreshModal').find('.' + status).show();
636+
}
637+
638+
function setNeedRefresh() {
634639
needRefresh = true;
635640
editor.setOption('readOnly', true);
636641
socket.disconnect();
637642
showStatus(statusType.offline);
638643
}
639644

640-
loginStateChangeEvent = setNeedRefresh;
645+
loginStateChangeEvent = function () {
646+
setRefreshModal('user-state-changed');
647+
setNeedRefresh();
648+
};
641649

642650
//visibility
643651
var wasFocus = false;
@@ -1978,9 +1986,8 @@ socket.on('error', function (data) {
19781986
});
19791987
var retryOnDisconnect = false;
19801988
var retryTimer = null;
1981-
socket.on('maintenance', function (data) {
1982-
if (data == version)
1983-
retryOnDisconnect = true;
1989+
socket.on('maintenance', function () {
1990+
retryOnDisconnect = true;
19841991
});
19851992
socket.on('disconnect', function (data) {
19861993
showStatus(statusType.offline);
@@ -1992,7 +1999,7 @@ socket.on('disconnect', function (data) {
19921999
editor.setOption('readOnly', true);
19932000
if (retryOnDisconnect && !retryTimer) {
19942001
retryTimer = setInterval(function () {
1995-
socket.connect();
2002+
if (!needRefresh) socket.connect();
19962003
}, 1000);
19972004
}
19982005
});
@@ -2013,8 +2020,14 @@ socket.on('connect', function (data) {
20132020
socket.id = socket.nsp + '#' + socket.id;
20142021
});
20152022
socket.on('version', function (data) {
2016-
if (data != version)
2017-
setNeedRefresh();
2023+
if (version != data.version) {
2024+
if (version < data.minimumCompatibleVersion) {
2025+
setRefreshModal('incompatible-version');
2026+
setNeedRefresh();
2027+
} else {
2028+
setRefreshModal('new-version');
2029+
}
2030+
}
20182031
});
20192032
function updateLastInfo(data) {
20202033
//console.log(data);

public/views/body.ejs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,6 @@
5656
</div>
5757
</div>
5858
</div>
59-
<!-- refresh modal -->
60-
<div class="modal fade" id="refreshModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
61-
<div class="modal-dialog modal-sm">
62-
<div class="modal-content">
63-
<div class="modal-header">
64-
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
65-
</button>
66-
<h4 class="modal-title" id="myModalLabel">This page need refresh</h4>
67-
</div>
68-
<div class="modal-body">
69-
<h5>This page have a mismatch client version or incorrect user state or errors.</h5>
70-
<strong>Please refresh this page.</strong>
71-
</div>
72-
<div class="modal-footer">
73-
<button type="button" class="btn btn-primary" id="refreshModalRefresh">Refresh</button>
74-
</div>
75-
</div>
76-
</div>
77-
</div>
7859
<!-- locked modal -->
7960
<div class="modal fade locked-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
8061
<div class="modal-dialog modal-sm">
@@ -234,6 +215,7 @@
234215
</div>
235216
</div>
236217
</div>
218+
<%- include refresh-modal %>
237219
<%- include signin-modal %>
238220
<%- include help-modal %>
239221
<%- include revision-modal %>

public/views/refresh-modal.ejs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!-- refresh modal -->
2+
<div class="modal fade" id="refreshModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
3+
<div class="modal-dialog modal-sm">
4+
<div class="modal-content">
5+
<div class="modal-header">
6+
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
7+
</button>
8+
<h4 class="modal-title" id="myModalLabel">This page need refresh</h4>
9+
</div>
10+
<div class="modal-body">
11+
<div class="incompatible-version">
12+
<h5>You have an incompatible client version.</h5>
13+
<strong>Refresh to update.</strong>
14+
</div>
15+
<div class="new-version" style="display:none;">
16+
<h5>New version available!</h5>
17+
<a href="<%- url %>/s/release-notes" target="_blank">See releases notes here</a>
18+
<br>
19+
<strong>Refresh to enjoy new features.</strong>
20+
</div>
21+
<div class="user-state-changed" style="display:none;">
22+
<h5>Your user state has changed.</h5>
23+
<strong>Refresh to load new user state.</strong>
24+
</div>
25+
</div>
26+
<div class="modal-footer">
27+
<a class="btn btn-danger" href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=KDGS4PREHX6QQ&lc=US&item_name=HackMD&amount=5%2e00&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted" target="_blank"><i class="fa fa-coffee"></i> Buy us coffee</a>
28+
<button type="button" class="btn btn-primary" id="refreshModalRefresh">Refresh</button>
29+
</div>
30+
</div>
31+
</div>
32+
</div>

0 commit comments

Comments
 (0)