Skip to content

Commit 3660a0e

Browse files
author
minjk-bl
committed
Fix version checker
1 parent 3e004d5 commit 3660a0e

File tree

5 files changed

+56
-19
lines changed

5 files changed

+56
-19
lines changed

css/menuFrame.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
display: none;
3232
float: right;
3333
position: relative;
34-
font-size: 10px;
35-
color: var(--font-hightlight);
34+
font-size: 13px;
3635
font-weight: bold;
36+
color: var(--highlight-color);
3737
margin: 8px 6px 8px 3px;
3838
cursor: pointer;
3939
}

js/com/com_Config.js

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ define([
216216
Jupyter.notebook.config.loaded.then(function() {
217217
var data = Jupyter.notebook.config.data[configKey];
218218
if (data == undefined) {
219-
reject('No data available.');
219+
resolve(data);
220220
return;
221221
}
222222
if (dataKey == '') {
@@ -335,16 +335,21 @@ define([
335335
return new Promise(function(resolve, reject) {
336336
try {
337337
fetch(url).then(function (response) {
338-
if (response.statusCode === 200) {
338+
// if (response.statusCode === 200) {
339+
// return response.json();
340+
// } else if (response.statusCode === 204) {
341+
// throw new Error('No Contents', response);
342+
// } else if (response.statusCode === 404) {
343+
// throw new Error('Page Not Found', response);
344+
// } else if (response.statusCode === 500) {
345+
// throw new Error('Internal Server Error', response);
346+
// } else {
347+
// throw new Error('Unexpected Http Status Code', response);
348+
// }
349+
if (response.ok) {
339350
return response.json();
340-
} else if (response.statusCode === 204) {
341-
throw new Error('No Contents', response);
342-
} else if (response.statusCode === 404) {
343-
throw new Error('Page Not Found', response);
344-
} else if (response.statusCode === 500) {
345-
throw new Error('Internal Server Error', response);
346351
} else {
347-
throw new Error('Unexpected Http Status Code', response);
352+
throw new Error('Error', response);
348353
}
349354
}).then(function (data) {
350355
resolve(data.info.version);
@@ -366,6 +371,7 @@ define([
366371
}
367372

368373
checkVpVersion(background=false) {
374+
let that = this;
369375
let nowVersion = this.getVpInstalledVersion();
370376
this.getPackageVersion().then(function(latestVersion) {
371377
if (nowVersion === latestVersion) {
@@ -377,8 +383,11 @@ define([
377383
let msg = com_util.formatString('Visualpython is up to date. ({0})', latestVersion);
378384
com_util.renderInfoModal(msg);
379385
}
386+
// update version_timestamp
387+
that.setData({ 'version_timestamp': new Date().getTime() }, 'vpcfg');
380388
} else {
381-
let msg = com_util.formatString('Visualpython updates are available.\n(Latest version: {0})', latestVersion);
389+
let msg = com_util.formatString('Visualpython updates are available.<br/>(Latest version: {0} / Your version: {1})',
390+
latestVersion, nowVersion);
382391
if (background) {
383392
// show version update icon
384393
$('#vp_versionUpdater').attr('title', msg);
@@ -399,9 +408,20 @@ define([
399408
break;
400409
case 1:
401410
// update
411+
let info = [
412+
'## Visual Python Upgrade',
413+
'NOTE: ',
414+
'- Refresh your web browser to start a new version.',
415+
'- Save VP Note before refreshing the page.'
416+
];
417+
com_interface.insertCell('markdown', info.join('\n'));
402418
com_interface.insertCell('code', '!pip install visualpython --upgrade');
403419
com_interface.insertCell('code', '!visualpy install');
404-
// TODO: refresh browser, after executed
420+
421+
// update version_timestamp
422+
that.setData({ 'version_timestamp': new Date().getTime() }, 'vpcfg');
423+
// hide updater
424+
$('#vp_versionUpdater').hide();
405425
break;
406426
}
407427
}

js/com/com_interface.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ define([
1717
return Jupyter.notebook.get_selected_index();
1818
}
1919

20+
/**
21+
*
22+
* @param {String} type code / markdown
23+
* @param {String} command
24+
* @param {boolean} exec true(default) / false
25+
* @param {int} sigNum
26+
*/
2027
var insertCell = function(type, command, exec=true, sigNum=-1) {
2128
var selectedIndex = getSelectedCell();
2229
var targetCell = Jupyter.notebook.insert_cell_below(type, selectedIndex);

js/loadVisualpython.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,10 @@
186186
// check version and update version_timestamp
187187
if (doCheckVersion == true) {
188188
vpConfig.checkVpVersion(true);
189-
190-
// update version_timestamp
191-
vpConfig.setData({ 'version_timestamp': nowDate.getTime() }, 'vpcfg');
192189
}
193190

194191
}).catch(function(err) {
195-
com_util.renderAlertModal(err);
192+
vpLog.display(VP_LOG_TYPE.ERROR, err);
196193
})
197194
}
198195

js/menu/MenuFrame.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ define([
102102
// Click version updater
103103
$(this.wrapSelector('#vp_versionUpdater')).on('click', function() {
104104
let latestVersion = $(this).data('version');
105-
let msg = com_util.formatString('Visualpython updates are available.\n(Latest version: {0})', latestVersion);
105+
let nowVersion = vpConfig.getVpInstalledVersion();
106+
let msg = com_util.formatString('Visualpython updates are available.<br/>(Latest version: {0} / Your version: {1})',
107+
latestVersion, nowVersion);
106108
// render update modal (same as com/com_Config.js:checkVpVersion())
107109
com_util.renderModal({
108110
title: 'Update version',
@@ -117,9 +119,20 @@ define([
117119
break;
118120
case 1:
119121
// update
122+
let info = [
123+
'## Visual Python Upgrade',
124+
'NOTE: ',
125+
'- Refresh your web browser to start a new version.',
126+
'- Save VP Note before refreshing the page.'
127+
];
128+
com_interface.insertCell('markdown', info.join('\n'));
120129
com_interface.insertCell('code', '!pip install visualpython --upgrade');
121130
com_interface.insertCell('code', '!visualpy install');
122-
// TODO: refresh browser, after executed
131+
132+
// update version_timestamp
133+
vpConfig.setData({ 'version_timestamp': new Date().getTime() }, 'vpcfg');
134+
// hide updater
135+
$(that.wrapSelector('#vp_versionUpdater')).hide();
123136
break;
124137
}
125138
}

0 commit comments

Comments
 (0)