-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement checking for updates (#82)
* introduce update background task * change icon's name * inline loadSettings in settings.ts * introduce mocked check for updates
- Loading branch information
1 parent
e051f51
commit ee985c7
Showing
9 changed files
with
162 additions
and
52 deletions.
There are no files selected for viewing
File renamed without changes
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,17 @@ | ||
export const updateInformation = { | ||
"chrome": { | ||
"latest_version":"0.1.2", | ||
"date":"2021-4-1", | ||
"url":"https://github.com/hypertrons/hypertrons-crx/releases" | ||
}, | ||
"edge": { | ||
"latest_version":"0.1.2", | ||
"date":"2021-3-1", | ||
"url":"https://github.com/hypertrons/hypertrons-crx/releases" | ||
}, | ||
"develop": { | ||
"latest_version":"0.1.2", | ||
"date":"2021-3-27", | ||
"url":"https://github.com/hypertrons/hypertrons-crx/releases" | ||
} | ||
} |
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,12 +1,43 @@ | ||
import { compareVersion, getBrowserType} from '../../utils/utils'; | ||
import { getUpdateInfor } from "../../services/background" | ||
import { loadSettings } from '../../utils/settings'; | ||
|
||
export enum BackgroundTasks { | ||
update = 'check_for_updates' | ||
} | ||
|
||
chrome.alarms.create(BackgroundTasks.update,{periodInMinutes:10}); | ||
chrome.alarms.create(BackgroundTasks.update,{periodInMinutes:0.1}); | ||
|
||
chrome.alarms.onAlarm.addListener((alarm) => { | ||
chrome.alarms.onAlarm.addListener(async (alarm) => { | ||
const name=alarm.name; | ||
if(name===BackgroundTasks.update){ | ||
console.log("check for updates"); | ||
|
||
const settings=await loadSettings(); | ||
|
||
if(name===BackgroundTasks.update ){ | ||
if(settings.checkForUpdates){ | ||
// @ts-ignore :we must ignore here | ||
const details=chrome.app.getDetails(); | ||
const currentVersion=details["version"]; | ||
const browserType=getBrowserType(); | ||
const updateInformation=await getUpdateInfor(); | ||
let latestVersion; | ||
|
||
if("key" in details){ | ||
// the store-version installation | ||
if(browserType==="Edge"){ | ||
latestVersion=updateInformation["edge"]["latest_version"]; | ||
} | ||
else{ | ||
latestVersion=updateInformation["chrome"]["latest_version"]; | ||
} | ||
} | ||
else{ | ||
latestVersion=updateInformation["develop"]["latest_version"]; | ||
} | ||
|
||
if(compareVersion(currentVersion,latestVersion)===-1){ | ||
console.log(`new ${browserType} update available, version:${latestVersion}`); | ||
} | ||
} | ||
} | ||
}); |
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,8 @@ | ||
import { updateInformation } from '../mock/background.data'; | ||
const url_update=""; | ||
|
||
export const getUpdateInfor = async () => { | ||
// const response = await fetch(url_update); | ||
// return await response.json(); | ||
return updateInformation; | ||
} |
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