mirror of
https://codeberg.org/librewolf/source.git
synced 2024-12-22 13:43:04 -05:00
Merge branch 'check_version_about_menu' into 'main'
check the version in about menu Closes windows#152 See merge request librewolf-community/browser/source!16
This commit is contained in:
commit
528e56faf3
3 changed files with 85 additions and 33 deletions
|
@ -43,13 +43,39 @@
|
|||
}
|
||||
|
||||
#version {
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
#versionNumber {
|
||||
font-weight: bold;
|
||||
user-select: text;
|
||||
-moz-user-focus: normal;
|
||||
cursor: text;
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
#aboutText {
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.loader {
|
||||
width: 0.9em;
|
||||
height: 0.9em;
|
||||
border: 1.5px solid #fff;
|
||||
border-bottom-color: transparent;
|
||||
border-radius: 50%;
|
||||
display: inline-block;
|
||||
box-sizing: border-box;
|
||||
animation: rotate 0.6s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes rotate {
|
||||
0% {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,19 +4,11 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
/* import-globals-from aboutDialog-appUpdater.js */
|
||||
|
||||
// Services = object with smart getters for common XPCOM services
|
||||
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
var { AppConstants } = ChromeUtils.import(
|
||||
"resource://gre/modules/AppConstants.jsm"
|
||||
);
|
||||
if (AppConstants.MOZ_UPDATER) {
|
||||
Services.scriptloader.loadSubScript(
|
||||
"chrome://browser/content/aboutDialog-appUpdater.js",
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
async function init(aEvent) {
|
||||
if (aEvent.target != document) {
|
||||
|
@ -49,33 +41,64 @@ async function init(aEvent) {
|
|||
}
|
||||
}
|
||||
|
||||
// Include the build ID and display warning if this is an "a#" (nightly or aurora) build
|
||||
let versionId = "aboutDialog-version";
|
||||
let versionAttributes = {
|
||||
version: AppConstants.MOZ_APP_VERSION_DISPLAY,
|
||||
bits: Services.appinfo.is64Bit ? 64 : 32,
|
||||
};
|
||||
// Display current version number
|
||||
let versionField = document.getElementById("versionNumber");
|
||||
versionField.innerHTML = AppConstants.MOZ_APP_VERSION_DISPLAY;
|
||||
|
||||
let version = Services.appinfo.version;
|
||||
if (/a\d+$/.test(version)) {
|
||||
versionId = "aboutDialog-version-nightly";
|
||||
let buildID = Services.appinfo.appBuildID;
|
||||
let year = buildID.slice(0, 4);
|
||||
let month = buildID.slice(4, 6);
|
||||
let day = buildID.slice(6, 8);
|
||||
versionAttributes.isodate = `${year}-${month}-${day}`;
|
||||
// If pref "librewolf.aboutMenu.checkVersion" is set to true,
|
||||
// check for new version with the link given in "librewolf.aboutMenu.versionCheckGitlabUrl"
|
||||
if (Services.prefs.getBoolPref("librewolf.aboutMenu.checkVersion", false)) {
|
||||
let versionDiv = document.getElementById("version");
|
||||
const loader = document.createElement("div");
|
||||
loader.classList.add("loader");
|
||||
versionDiv.appendChild(loader);
|
||||
|
||||
document.getElementById("experimental").hidden = false;
|
||||
document.getElementById("communityDesc").hidden = true;
|
||||
function isNewerVersion(newVersionString, oldVersionString) {
|
||||
let [oldVersion, oldRelease] = oldVersionString.replace(/^v/, "").split("-");
|
||||
let [newVersion, newRelease] = newVersionString.replace(/^v/, "").split("-");
|
||||
console.log(oldVersionString, newVersionString)
|
||||
if (oldVersion && newVersion) {
|
||||
if (!oldRelease) oldRelease = "0";
|
||||
if (!newRelease) newRelease = "0";
|
||||
|
||||
// Check version
|
||||
for (let i = 0; i < newVersion.split(".").length; i++) {
|
||||
if (Number(newVersion.split(".")[i]) > Number(oldVersion?.split(".")[i] || "0")) return true;
|
||||
}
|
||||
|
||||
// Check release
|
||||
if (Number(newRelease) > Number(oldRelease)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
fetch(
|
||||
Services.prefs.getStringPref(
|
||||
"librewolf.aboutMenu.versionCheckGitlabUrl",
|
||||
"https://gitlab.com/api/v4/projects/32320088/releases"
|
||||
)
|
||||
)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.length > 0) {
|
||||
const latestVersion = data[0].tag_name;
|
||||
if (isNewerVersion(latestVersion, AppConstants.MOZ_APP_VERSION_DISPLAY)) {
|
||||
const updateNotice = document.createElement("a");
|
||||
updateNotice.classList.add("text-link");
|
||||
updateNotice.href = data[0]._links.self;
|
||||
updateNotice.onclick = () => window.openWebLinkIn(data[0]._links.self, "tab")
|
||||
updateNotice.innerText = "(Update available)";
|
||||
versionDiv.appendChild(updateNotice);
|
||||
} else {
|
||||
const upToDateNotice = document.createElement("div")
|
||||
upToDateNotice.innerText = "(Up to date)";
|
||||
versionDiv.appendChild(upToDateNotice);
|
||||
}
|
||||
}
|
||||
loader.remove();
|
||||
})
|
||||
}
|
||||
|
||||
// Use Fluent arguments for append version and the architecture of the build
|
||||
let versionField = document.getElementById("version");
|
||||
|
||||
document.l10n.setAttributes(versionField, versionId, versionAttributes);
|
||||
|
||||
await document.l10n.translateElements([versionField]);
|
||||
|
||||
window.sizeToContent();
|
||||
|
||||
if (AppConstants.platform == "macosx") {
|
||||
|
@ -85,3 +108,4 @@ async function init(aEvent) {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -37,7 +37,9 @@
|
|||
<div id="left" />
|
||||
<div id="right">
|
||||
<label id="wordmark">LibreWolf</label>
|
||||
<label id="version" />
|
||||
<div id="version">
|
||||
<label id="versionNumber" />
|
||||
</div >
|
||||
<label id="distribution" />
|
||||
<label id="distributionId" />
|
||||
<label id="aboutText">
|
||||
|
|
Loading…
Reference in a new issue