-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add auto update wallet (#1243)
With this PR, the wallet will now check if it is running an old version and will auto-update once a new version is available on the background, respecting the user flow, if the users had any Wallet popup / tab open it will not update the wallet and delay it for more 15 minutes.
- Loading branch information
1 parent
21a7d80
commit 06e2bf1
Showing
9 changed files
with
50 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"fuels-wallet": minor | ||
--- | ||
|
||
feat: add auto update wallet in background |
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
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
38 changes: 38 additions & 0 deletions
38
packages/app/src/systems/CRX/background/actions/autoUpdate.ts
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,38 @@ | ||
import { compareVersions } from 'compare-versions'; | ||
import { APP_VERSION, VITE_CRX_VERSION_API, WALLET_NAME } from '~/config'; | ||
|
||
// Check if user has any open tab if not return false | ||
async function isOpen() { | ||
// biome-ignore lint/suspicious/noExplicitAny: getContexts is not available on current types | ||
const contexts = await (chrome.runtime as any).getContexts({}); | ||
const isOpen = !!contexts.find(({ contextType }: { contextType: string }) => | ||
['TAB', 'POPUP'].includes(contextType) | ||
); | ||
return isOpen; | ||
} | ||
|
||
async function runVersionCheck() { | ||
const latestVersion = await fetch(VITE_CRX_VERSION_API) | ||
.then((res) => res.json()) | ||
// If fails to fetch the version return a empty object | ||
.catch(() => ({})); | ||
const version = latestVersion[WALLET_NAME] || APP_VERSION; | ||
// If app version is greater than the one on the release API ignores the check | ||
if (compareVersions(APP_VERSION, version) > -1) return; | ||
if (await isOpen()) return; | ||
// Request update check and reload if available | ||
console.log('[FUEL WALLET] Checking for updates...'); | ||
chrome.runtime.requestUpdateCheck((details) => { | ||
if (details === 'update_available') { | ||
console.log('[FUEL WALLET] Update available reload application...'); | ||
chrome.runtime.reload(); | ||
} | ||
}); | ||
} | ||
|
||
chrome.alarms.create('autoUpdate', { periodInMinutes: 5 }); | ||
chrome.alarms.onAlarm.addListener(async (alarm) => { | ||
if (alarm.name === 'autoUpdate') { | ||
runVersionCheck(); | ||
} | ||
}); |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import './actions/autoUpdate'; | ||
import './actions/keepAwake'; | ||
import './actions/onInstall'; | ||
import './communication'; |
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