-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement extension upgrade check
Checks once a day, when there is extension upgradeable, notify user to go to store to upgrade. Auto upgrade is not yet implemented.
- Loading branch information
1 parent
7853118
commit ff0fa51
Showing
10 changed files
with
119 additions
and
70 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
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,53 @@ | ||
import { confirm } from "@tauri-apps/plugin-dialog" | ||
import { relaunch } from "@tauri-apps/plugin-process" | ||
import { check } from "@tauri-apps/plugin-updater" | ||
import { ElMessage, ElNotification } from "element-plus" | ||
import { gqlClient } from "@/lib/utils/graphql" | ||
import { FindLatestExtDocument, type FindLatestExtQuery, type FindLatestExtQueryVariables } from "@kksh/gql" | ||
import {gt} from 'semver' | ||
import type { ExtPackageJsonExtra } from "@kksh/api/models" | ||
|
||
|
||
export async function checkUpdateAndInstall() { | ||
const update = await check() | ||
if (update?.available) { | ||
const confirmUpdate = await confirm( | ||
`A new version ${update.version} is available. Do you want to install and relaunch?` | ||
) | ||
if (confirmUpdate) { | ||
await update.downloadAndInstall() | ||
await relaunch() | ||
} | ||
} else { | ||
ElNotification.info("You are on the latest version") | ||
} | ||
} | ||
|
||
export async function checkSingleExtensionUpdate(installedExt: ExtPackageJsonExtra) { | ||
const extStore = useExtStore() | ||
const response = await gqlClient.query<FindLatestExtQuery, FindLatestExtQueryVariables>({ | ||
query: FindLatestExtDocument, | ||
variables: { | ||
identifier: installedExt.kunkun.identifier | ||
} | ||
}) | ||
const exts = response.data.ext_publishCollection?.edges | ||
console.log(exts); | ||
if (!exts || exts?.length <= 0) { | ||
return | ||
} | ||
const ext = exts[0].node | ||
if (gt(ext.version, installedExt.version)) { | ||
console.log(`new version available ${installedExt.kunkun.identifier} ${ext.version}`); | ||
ElNotification.info(`Extension ${installedExt.kunkun.identifier} has a new version ${ext.version}, you can upgrade in Store.`) | ||
} | ||
} | ||
|
||
export async function checkExtensionUpdate() { | ||
console.log("checkExtensionUpdate"); | ||
|
||
const extStore = useExtStore() | ||
extStore.manifests.forEach(async (ext) => { | ||
await checkSingleExtensionUpdate(ext) | ||
}) | ||
} |
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
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,33 @@ | ||
import { defineStore } from 'pinia' | ||
import { Store } from "@tauri-apps/plugin-store" | ||
import * as v from 'valibot' | ||
|
||
const persistAppConfig = new Store("appConfig.bin") | ||
|
||
export const useLastTimeStore = defineStore('kk-last-time', { | ||
state: () => ({ | ||
lastCheckUpdateTime: new Date(), | ||
}), | ||
actions: { | ||
elapsedTime() { | ||
const now = new Date() | ||
return now.getTime() - this.lastCheckUpdateTime.getTime() | ||
}, | ||
expired() { | ||
// check update every 24 hours | ||
return this.elapsedTime() > 1000 * 60 * 60 * 24 | ||
}, | ||
async init() { | ||
const lastCheckUpdateTime = await persistAppConfig.get("lastCheckUpdateTime") | ||
if (lastCheckUpdateTime) { | ||
this.lastCheckUpdateTime = new Date(v.parse(v.string(), lastCheckUpdateTime)) | ||
} else { | ||
await this.update() | ||
} | ||
}, | ||
update() { | ||
this.lastCheckUpdateTime = new Date() | ||
persistAppConfig.set("lastCheckUpdateTime", this.lastCheckUpdateTime.toISOString()) | ||
} | ||
}, | ||
}) |
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 +1 @@ | ||
export { version, breakingChangesVersionCheckpoints } from "./version" | ||
export { version, breakingChangesVersionCheckpoints, isVersionBetween, isCompatible } from "./version" |