From 85fa1e23593fa44852fbbd8c2d020cbf4568cfcb Mon Sep 17 00:00:00 2001 From: reya Date: Sun, 3 Nov 2024 13:49:19 +0700 Subject: [PATCH] fix: missing check for update --- biome.json | 5 +--- src-tauri/capabilities/main.json | 9 ++---- src-tauri/tauri.conf.json | 5 +--- src-tauri/tauri.macos.conf.json | 4 +-- src/commons.ts | 39 +------------------------ src/routes/_app.tsx | 49 +++++++++++++++++++++++++------- tailwind.config.js | 5 +--- tsconfig.json | 17 +++-------- tsconfig.node.json | 4 +-- 9 files changed, 50 insertions(+), 87 deletions(-) diff --git a/biome.json b/biome.json index 4ab5ab03..b05fd6df 100644 --- a/biome.json +++ b/biome.json @@ -4,10 +4,7 @@ "enabled": true }, "files": { - "ignore": [ - "./src/routes.gen.ts", - "./src/commands.gen.ts" - ] + "ignore": ["./src/routes.gen.ts", "./src/commands.gen.ts"] }, "linter": { "enabled": true, diff --git a/src-tauri/capabilities/main.json b/src-tauri/capabilities/main.json index c4ded850..80a7522c 100644 --- a/src-tauri/capabilities/main.json +++ b/src-tauri/capabilities/main.json @@ -2,13 +2,8 @@ "$schema": "../gen/schemas/desktop-schema.json", "identifier": "window", "description": "Capability for the desktop", - "platforms": [ - "macOS", - "windows" - ], - "windows": [ - "*" - ], + "platforms": ["macOS", "windows"], + "windows": ["*"], "permissions": [ "core:path:default", "core:event:default", diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 32d44722..ebd96a24 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -39,10 +39,7 @@ "targets": "all", "active": true, "category": "SocialNetworking", - "resources": [ - "resources/*", - "locales/*" - ], + "resources": ["resources/*", "locales/*"], "icon": [ "icons/32x32.png", "icons/128x128.png", diff --git a/src-tauri/tauri.macos.conf.json b/src-tauri/tauri.macos.conf.json index 2adf00b7..3a00126d 100644 --- a/src-tauri/tauri.macos.conf.json +++ b/src-tauri/tauri.macos.conf.json @@ -13,9 +13,7 @@ "hiddenTitle": true, "transparent": true, "windowEffects": { - "effects": [ - "underWindowBackground" - ] + "effects": ["underWindowBackground"] } } ] diff --git a/src/commons.ts b/src/commons.ts index 96aa9d34..2cfcbca4 100644 --- a/src/commons.ts +++ b/src/commons.ts @@ -3,11 +3,9 @@ import type { MaybePromise, PersistedQuery, } from "@tanstack/query-persist-client-core"; -import { ask, message, open } from "@tauri-apps/plugin-dialog"; +import { open } from "@tauri-apps/plugin-dialog"; import { readFile } from "@tauri-apps/plugin-fs"; -import { relaunch } from "@tauri-apps/plugin-process"; import type { Store as TauriStore } from "@tauri-apps/plugin-store"; -import { check } from "@tauri-apps/plugin-updater"; import { BitcoinUnit } from "bitcoin-units"; import { type ClassValue, clsx } from "clsx"; import dayjs from "dayjs"; @@ -170,41 +168,6 @@ export function decodeZapInvoice(tags: string[][]) { } } -export async function checkForAppUpdates(silent: boolean) { - const update = await check(); - - if (!update) { - if (silent) return; - - await message("You are on the latest version. Stay awesome!", { - title: "No Update Available", - kind: "info", - okLabel: "OK", - }); - - return; - } - - if (update?.available) { - const yes = await ask( - `Update to ${update.version} is available!\n\nRelease notes: ${update.body}`, - { - title: "Update Available", - kind: "info", - okLabel: "Update", - cancelLabel: "Cancel", - }, - ); - - if (yes) { - await update.downloadAndInstall(); - await relaunch(); - } - - return; - } -} - export async function upload(filePath?: string) { const allowExts = [ "png", diff --git a/src/routes/_app.tsx b/src/routes/_app.tsx index 8ecd558c..3dcaed6c 100644 --- a/src/routes/_app.tsx +++ b/src/routes/_app.tsx @@ -1,14 +1,41 @@ -import { commands } from '@/commands.gen' -import { createFileRoute, redirect } from '@tanstack/react-router' +import { commands } from "@/commands.gen"; +import { createFileRoute, redirect } from "@tanstack/react-router"; +import { ask } from "@tauri-apps/plugin-dialog"; +import { relaunch } from "@tauri-apps/plugin-process"; +import { check } from "@tauri-apps/plugin-updater"; -export const Route = createFileRoute('/_app')({ - beforeLoad: async () => { - const accounts = await commands.getAccounts() +async function checkForAppUpdates() { + const update = await check(); - if (!accounts.length) { - throw redirect({ to: '/new', replace: true }) - } + if (update?.available) { + const yes = await ask( + `Update to ${update.version} is available!\n\nRelease notes: ${update.body}`, + { + title: "Update Available", + kind: "info", + okLabel: "Update", + cancelLabel: "Cancel", + }, + ); - return { accounts } - }, -}) + if (yes) { + await update.downloadAndInstall(); + await relaunch(); + } + + return; + } +} + +export const Route = createFileRoute("/_app")({ + beforeLoad: async () => { + await checkForAppUpdates(); + const accounts = await commands.getAccounts(); + + if (!accounts.length) { + throw redirect({ to: "/new", replace: true }); + } + + return { accounts }; + }, +}); diff --git a/tailwind.config.js b/tailwind.config.js index 63db08b5..de0385f4 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -1,10 +1,7 @@ /** @type {import('tailwindcss').Config} */ export default { - content: [ - "./src/**/*.{js,ts,jsx,tsx}", - "index.html", - ], + content: ["./src/**/*.{js,ts,jsx,tsx}", "index.html"], theme: { extend: { keyframes: { diff --git a/tsconfig.json b/tsconfig.json index fc223013..f946f7e2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,19 +2,12 @@ "compilerOptions": { "target": "ESNext", "useDefineForClassFields": true, - "lib": [ - "ESNext", - "ES2020", - "DOM", - "DOM.Iterable" - ], + "lib": ["ESNext", "ES2020", "DOM", "DOM.Iterable"], "module": "ESNext", "skipLibCheck": true, "baseUrl": "./", "paths": { - "@/*": [ - "./src/*" - ] + "@/*": ["./src/*"] }, "moduleResolution": "bundler", "allowImportingTsExtensions": true, @@ -26,11 +19,9 @@ "noUnusedLocals": true, "noImplicitAny": false, "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true, + "noFallthroughCasesInSwitch": true }, - "include": [ - "src" - ], + "include": ["src"], "references": [ { "path": "./tsconfig.node.json" diff --git a/tsconfig.node.json b/tsconfig.node.json index d37a14f7..eca66688 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -6,7 +6,5 @@ "moduleResolution": "bundler", "allowSyntheticDefaultImports": true }, - "include": [ - "vite.config.ts" - ] + "include": ["vite.config.ts"] }