feat(desktop): custom update toast
This commit is contained in:
parent
194ff4919c
commit
e37a75a411
7 changed files with 135 additions and 66 deletions
|
|
@ -1,14 +1,16 @@
|
|||
// @refresh reload
|
||||
import { render } from "solid-js/web"
|
||||
import { App, PlatformProvider, Platform } from "@opencode-ai/desktop"
|
||||
import { onMount } from "solid-js"
|
||||
import { open, save } from "@tauri-apps/plugin-dialog"
|
||||
import { open as shellOpen } from "@tauri-apps/plugin-shell"
|
||||
import { type as ostype } from "@tauri-apps/plugin-os"
|
||||
import { AsyncStorage } from "@solid-primitives/storage"
|
||||
|
||||
import { runUpdater, UPDATER_ENABLED } from "./updater"
|
||||
import { UPDATER_ENABLED } from "./updater"
|
||||
import { createMenu } from "./menu"
|
||||
import { check, Update } from "@tauri-apps/plugin-updater"
|
||||
import { invoke } from "@tauri-apps/api/core"
|
||||
import { relaunch } from "@tauri-apps/plugin-process"
|
||||
|
||||
const root = document.getElementById("root")
|
||||
if (import.meta.env.DEV && !(root instanceof HTMLElement)) {
|
||||
|
|
@ -17,6 +19,8 @@ if (import.meta.env.DEV && !(root instanceof HTMLElement)) {
|
|||
)
|
||||
}
|
||||
|
||||
let update: Update | null = null
|
||||
|
||||
const platform: Platform = {
|
||||
platform: "tauri",
|
||||
|
||||
|
|
@ -66,15 +70,26 @@ const platform: Platform = {
|
|||
}
|
||||
return api
|
||||
},
|
||||
|
||||
checkUpdate: async () => {
|
||||
if (!UPDATER_ENABLED) return { updateAvailable: false }
|
||||
update = await check()
|
||||
if (!update) return { updateAvailable: false }
|
||||
await update.download()
|
||||
return { updateAvailable: true, version: update.version }
|
||||
},
|
||||
|
||||
update: async () => {
|
||||
if (!UPDATER_ENABLED || !update) return
|
||||
await update.install()
|
||||
await invoke("kill_sidecar")
|
||||
await relaunch()
|
||||
},
|
||||
}
|
||||
|
||||
createMenu()
|
||||
|
||||
render(() => {
|
||||
onMount(() => {
|
||||
if (UPDATER_ENABLED) runUpdater({ alertOnFail: false })
|
||||
})
|
||||
|
||||
return (
|
||||
<PlatformProvider value={platform}>
|
||||
{ostype() === "macos" && (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue