add updater v2

This commit is contained in:
reya 2023-10-26 10:33:27 +07:00
parent 0c8dcef937
commit 842f9e14e0
4 changed files with 42 additions and 4 deletions

View File

@ -32,7 +32,7 @@ jobs:
if: matrix.settings.platform == 'ubuntu-22.04'
run: |
sudo apt-get update
sudo apt-get install -y build-essential libssl-dev libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
sudo apt-get install -y build-essential libssl-dev libayatana-appindicator3-dev libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
- name: Install pnpm
uses: pnpm/action-setup@v2
with:

View File

@ -107,6 +107,13 @@ fn secure_remove(key: String) -> Result<(), ()> {
fn main() {
tauri::Builder::default()
.setup(|app| {
#[cfg(desktop)]
app
.handle()
.plugin(tauri_plugin_updater::Builder::new().build())?;
Ok(())
})
.plugin(tauri_plugin_app::init())
.plugin(tauri_plugin_clipboard_manager::init())
.plugin(tauri_plugin_dialog::init())

View File

@ -28,7 +28,10 @@ const NDKProvider = ({ children }: PropsWithChildren<object>) => {
data-tauri-drag-region
className="flex h-screen w-screen items-center justify-center bg-neutral-50 dark:bg-neutral-950"
>
<LoaderIcon className="h-8 w-8 animate-spin text-neutral-950 dark:text-neutral-50" />
<div className="flex flex-col items-center justify-center gap-2 text-center">
<LoaderIcon className="h-7 w-7 animate-spin text-neutral-950 dark:text-neutral-50" />
<p className="font-semibold">Connecting to relays</p>
</div>
</div>
);
}

View File

@ -1,11 +1,15 @@
import { appConfigDir } from '@tauri-apps/api/path';
import { message } from '@tauri-apps/plugin-dialog';
import { platform } from '@tauri-apps/plugin-os';
import { relaunch } from '@tauri-apps/plugin-process';
import Database from '@tauri-apps/plugin-sql';
import { check } from '@tauri-apps/plugin-updater';
import { PropsWithChildren, createContext, useContext, useEffect, useState } from 'react';
import { LumeStorage } from '@libs/storage/instance';
import { LoaderIcon } from '@shared/icons';
interface StorageContext {
db: LumeStorage;
}
@ -16,6 +20,7 @@ const StorageContext = createContext<StorageContext>({
const StorageProvider = ({ children }: PropsWithChildren<object>) => {
const [db, setDB] = useState<LumeStorage>(undefined);
const [isNewVersion, setIsNewVersion] = useState(false);
const initLumeStorage = async () => {
try {
@ -26,6 +31,15 @@ const StorageProvider = ({ children }: PropsWithChildren<object>) => {
const lumeStorage = new LumeStorage(sqlite, platformName);
if (!lumeStorage.account) await lumeStorage.getActiveAccount();
// check update
const update = await check();
if (update) {
setIsNewVersion(true);
await update.downloadAndInstall();
await relaunch();
}
setDB(lumeStorage);
console.info(dir);
} catch (e) {
@ -40,9 +54,23 @@ const StorageProvider = ({ children }: PropsWithChildren<object>) => {
if (!db) initLumeStorage();
}, []);
if (db) {
return <StorageContext.Provider value={{ db }}>{children}</StorageContext.Provider>;
if (!db) {
return (
<div
data-tauri-drag-region
className="flex h-screen w-screen items-center justify-center bg-neutral-50 dark:bg-neutral-950"
>
<div className="flex flex-col items-center justify-center gap-2 text-center">
<LoaderIcon className="h-7 w-7 animate-spin text-neutral-950 dark:text-neutral-50" />
<p className="font-semibold">
{isNewVersion ? 'Found a new version, updating' : 'Checking for updates'}
</p>
</div>
</div>
);
}
return <StorageContext.Provider value={{ db }}>{children}</StorageContext.Provider>;
};
const useStorage = () => {