Skip to content

Commit

Permalink
Fix async tauri info
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Jun 5, 2024
1 parent 394572a commit 166d913
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
20 changes: 9 additions & 11 deletions src/components/about-popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ import {
CredenzaTitle
} from "./ui/credenza";
import {Button} from "@/components/ui/button.tsx";
import {isTauri} from "@/lib/utils.ts";
import { version, type, platform, locale, arch } from '@tauri-apps/api/os';

const tauriInfo = isTauri() ? {
osVersion: await version(),
osType: await type(),
platformName: await platform(),
osLocale: await locale(),
archName: await arch()
} : null
export type TauriInfo = {
osType: string
osVersion: string
platformName: string
osLocale: string | null
archName: string
} | null

export function AboutPopup({open, setOpen}: { open: boolean, setOpen: (open: boolean) => void }) {
export function AboutPopup({open, setOpen, tauriInfo}: { open: boolean, setOpen: (open: boolean) => void, tauriInfo: TauriInfo }) {
return (
<Credenza open={open} onOpenChange={setOpen}>
<CredenzaContent>
Expand All @@ -36,7 +34,7 @@ export function AboutPopup({open, setOpen}: { open: boolean, setOpen: (open: boo
<>
<p>Operating System: {tauriInfo.osType} {tauriInfo.osVersion}</p>
<p>Platform: {tauriInfo.platformName}</p>
<p>Locale: {tauriInfo.osLocale}</p>
<p>Locale: {tauriInfo.osLocale ?? "Unknown"}</p>
<p>Architecture: {tauriInfo.archName}</p>
</>
) : (
Expand Down
17 changes: 14 additions & 3 deletions src/components/dashboard-menu-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import {useTheme} from "next-themes";
import {isTauri} from "@/lib/utils.ts";
import {exit} from "@tauri-apps/api/process";
import {AboutPopup} from "@/components/about-popup.tsx";
import {AboutPopup, TauriInfo} from "@/components/about-popup.tsx";
import {useContext, useRef, useState} from "react";
import {useNavigate} from "@tanstack/react-router";
import {ProfileContext} from "@/components/providers/profile-context.tsx";
Expand All @@ -24,6 +24,7 @@ import {open, save} from "@tauri-apps/api/dialog";
import {open as shellOpen} from "@tauri-apps/api/shell";
import {appConfigDir, appDataDir, resolve} from "@tauri-apps/api/path";
import {toast} from "sonner";
import {arch, locale, platform, type, version} from '@tauri-apps/api/os';

function data2blob(data: string) {
const bytes = new Array(data.length);
Expand All @@ -37,6 +38,7 @@ function data2blob(data: string) {
export const DashboardMenuHeader = ({availableProfiles}: { availableProfiles: string[] }) => {
const {theme, setTheme} = useTheme()
const [aboutOpen, setAboutOpen] = useState(false)
const [tauriInfo, setTauriInfo] = useState<TauriInfo | null>(null)
const navigate = useNavigate()
const profile = useContext(ProfileContext)
const fileInputRef = useRef<HTMLInputElement>(null)
Expand Down Expand Up @@ -219,11 +221,20 @@ export const DashboardMenuHeader = ({availableProfiles}: { availableProfiles: st
<MenubarSeparator/>
</>)
}
<MenubarItem onClick={() => setAboutOpen(true)}>About</MenubarItem>
<MenubarItem onClick={async () => {
setTauriInfo(isTauri() ? {
osType: await type(),
osVersion: await version(),
platformName: await platform(),
osLocale: await locale(),
archName: await arch()
} : null)
setAboutOpen(true)
}}>About</MenubarItem>
</MenubarContent>
</MenubarMenu>
</Menubar>
<AboutPopup open={aboutOpen} setOpen={setAboutOpen}/>
<AboutPopup open={aboutOpen} setOpen={setAboutOpen} tauriInfo={tauriInfo}/>
</>
)
}

0 comments on commit 166d913

Please sign in to comment.