Skip to content

Commit

Permalink
fix: missing check for update
Browse files Browse the repository at this point in the history
  • Loading branch information
reyamir committed Nov 3, 2024
1 parent cd6ba58 commit 85fa1e2
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 87 deletions.
5 changes: 1 addition & 4 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 2 additions & 7 deletions src-tauri/capabilities/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 1 addition & 4 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@
"targets": "all",
"active": true,
"category": "SocialNetworking",
"resources": [
"resources/*",
"locales/*"
],
"resources": ["resources/*", "locales/*"],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
Expand Down
4 changes: 1 addition & 3 deletions src-tauri/tauri.macos.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
"hiddenTitle": true,
"transparent": true,
"windowEffects": {
"effects": [
"underWindowBackground"
]
"effects": ["underWindowBackground"]
}
}
]
Expand Down
39 changes: 1 addition & 38 deletions src/commons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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",
Expand Down
49 changes: 38 additions & 11 deletions src/routes/_app.tsx
Original file line number Diff line number Diff line change
@@ -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 };
},
});
5 changes: 1 addition & 4 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
17 changes: 4 additions & 13 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -26,11 +19,9 @@
"noUnusedLocals": true,
"noImplicitAny": false,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noFallthroughCasesInSwitch": true
},
"include": [
"src"
],
"include": ["src"],
"references": [
{
"path": "./tsconfig.node.json"
Expand Down
4 changes: 1 addition & 3 deletions tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": [
"vite.config.ts"
]
"include": ["vite.config.ts"]
}

0 comments on commit 85fa1e2

Please sign in to comment.