-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add firmware upgrade notification to status page #7597
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
'require baseclass'; | ||
'require fs'; | ||
'require rpc'; | ||
'require uci' | ||
'require ui'; | ||
|
||
var callLuciVersion = rpc.declare({ | ||
object: 'luci', | ||
|
@@ -18,17 +20,85 @@ var callSystemInfo = rpc.declare({ | |
method: 'info' | ||
}); | ||
|
||
function showUpgradeModal(type, current_version, new_version) { | ||
ui.showModal(_('New Firmware Available'), [ | ||
E('p', _('A new %s version of OpenWrt is available: %s').format(type, new_version)), | ||
E('p', _('Your current version is: %s').format(current_version)), | ||
E('p', _('Please check the https://firmware-selector.openwrt.org/ for the firmware upgrade image')), | ||
E('div', { class: 'btn', click: ui.hideModal }, _('Close')), | ||
]); | ||
}; | ||
|
||
function checkDeviceAvailable(boardinfo, new_version) { | ||
const profile_url = 'https://downloads.openwrt.org/releases/%s/targets/%s/profiles.json'.format(new_version, boardinfo.release.target); | ||
return fetch(profile_url) | ||
.then(response => response.json()) | ||
.then(data => { | ||
// special case for x86 and armsr | ||
if (Object.keys(data.profiles).length == 1 && Object.keys(data.profiles)[0] == "generic") { | ||
return true; | ||
} | ||
|
||
for (var i = 0; i < data.profiles.length; i++) { | ||
if (data.profiles[i].profile == boardinfo.board_name) { | ||
return true; | ||
} | ||
for (var j = 0; j < data.profiles[i].supported_devices.length; j++) { | ||
if (data.profiles[i].supported_devices[j] == boardinfo.board_name) { | ||
return true; | ||
} | ||
} | ||
} | ||
}) | ||
.catch(error => { | ||
console.error('Failed to fetch profile information:', error); | ||
return false; | ||
}); | ||
}; | ||
|
||
|
||
return baseclass.extend({ | ||
title: _('System'), | ||
|
||
load: function() { | ||
return Promise.all([ | ||
L.resolveDefault(callSystemBoard(), {}), | ||
L.resolveDefault(callSystemInfo(), {}), | ||
L.resolveDefault(callLuciVersion(), { revision: _('unknown version'), branch: 'LuCI' }) | ||
L.resolveDefault(callLuciVersion(), { revision: _('unknown version'), branch: 'LuCI' }), | ||
uci.load('luci') | ||
]); | ||
}, | ||
|
||
oneshot: function(data) { | ||
var boardinfo = data[0]; | ||
var check_upgrades = uci.get_first('luci', 'core', 'check_firmware_version') || false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure but I think that should be
|
||
console.log(check_upgrades) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. drop |
||
|
||
if (check_upgrades == '1' || check_upgrades == 'true') { | ||
fetch('https://downloads.openwrt.org/.versions.json') | ||
.then(response => response.json()) | ||
.then(data => { | ||
if (data.oldstable_version | ||
&& data.oldstable_version > boardinfo.release.version | ||
&& checkDeviceAvailable(boardinfo, data.oldstable_version)) { | ||
showUpgradeModal("oldstable", boardinfo.release.version, data.oldstable_version) | ||
} else if (data.stable_version | ||
&& data.stable_version > boardinfo.release.version | ||
&& checkDeviceAvailable(boardinfo, data.stable_version)) { | ||
showUpgradeModal("stable", boardinfo.release.version, data.stable_version) | ||
} else if (data.upcoming_version | ||
&& boardinfo.release.version > data.stable_version | ||
&& data.upcoming_version > boardinfo.release.version | ||
&& checkDeviceAvailable(boardinfo, data.upcoming_version)) { | ||
showUpgradeModal("upcomming", boardinfo.release.version, data.upcoming_version) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe "release candidate"? since I think that's the only thing ever to populate the |
||
} | ||
}) | ||
.catch(error => { | ||
console.error('Failed to fetch version information:', error); | ||
}); | ||
} | ||
}, | ||
|
||
render: function(data) { | ||
var boardinfo = data[0], | ||
systeminfo = data[1], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider adding more context to the error. A user who doesn't know about this feature might be confused by this err string, even though it's a console message.