-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀 Merge pull request #33 from younesaassila/v1.5.0
🔖 Release version 1.5.0
- Loading branch information
Showing
17 changed files
with
466 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import semverCompare from "semver-compare"; | ||
import browser from "webextension-polyfill"; | ||
import store from "../../store"; | ||
|
||
//#region Types | ||
type Update = { | ||
version: string; | ||
update_link: string; | ||
}; | ||
//#endregion | ||
|
||
export default async function onStartup() { | ||
if (store.readyState !== "complete") { | ||
store.addEventListener("load", () => onStartup()); | ||
return; | ||
} | ||
|
||
// If the last update check was less than 24 hours ago, don't check again. | ||
if ( | ||
!store.state.isUpdateAvailable && | ||
Date.now() - store.state.lastUpdateCheck < 1000 * 60 * 60 * 24 | ||
) { | ||
return; | ||
} | ||
|
||
const manifest = browser.runtime.getManifest(); | ||
const currentVersion = manifest.version; | ||
const updateUrl = manifest.browser_specific_settings?.gecko?.update_url; | ||
if (!updateUrl) { | ||
store.state.isUpdateAvailable = false; | ||
return; | ||
} | ||
|
||
try { | ||
const response = await fetch(updateUrl); | ||
const json = await response.json(); | ||
const updates = json.addons["{76ef94a4-e3d0-4c6f-961a-d38a429a332b}"] | ||
.updates as Update[]; | ||
updates.sort((a, b) => semverCompare(a.version, b.version)); | ||
const latestVersion = updates[updates.length - 1].version; | ||
store.state.isUpdateAvailable = | ||
semverCompare(currentVersion, latestVersion) < 0; // currentVersion < latestVersion | ||
store.state.lastUpdateCheck = Date.now(); | ||
} catch { | ||
store.state.isUpdateAvailable = false; | ||
} | ||
} |
Oops, something went wrong.