forked from Berry-Dash/launcher
Add version number to settings page
This commit is contained in:
@@ -35,6 +35,7 @@ type GlobalCtxType = {
|
||||
total: number
|
||||
} | null
|
||||
viewingInfoFromDownloads: boolean
|
||||
version: string | null
|
||||
}
|
||||
|
||||
const GlobalCtx = createContext<GlobalCtxType | null>(null)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import Sidebar from './componets/Sidebar'
|
||||
import './Globals.css'
|
||||
import { DownloadProgress } from './types/DownloadProgress'
|
||||
@@ -18,11 +18,6 @@ import {
|
||||
faWarning,
|
||||
faXmark
|
||||
} from '@fortawesome/free-solid-svg-icons'
|
||||
import {
|
||||
isPermissionGranted,
|
||||
requestPermission,
|
||||
sendNotification
|
||||
} from '@tauri-apps/plugin-notification'
|
||||
import {
|
||||
readNormalConfig,
|
||||
readVersionsConfig,
|
||||
@@ -44,6 +39,11 @@ import { arch, platform } from '@tauri-apps/plugin-os'
|
||||
import VersionInfo from './componets/VersionInfo'
|
||||
import prettyBytes from 'pretty-bytes'
|
||||
import ProgressBar from './componets/ProgressBar'
|
||||
import { notifyUser } from './util/Notifications'
|
||||
import {
|
||||
isPermissionGranted,
|
||||
requestPermission
|
||||
} from '@tauri-apps/plugin-notification'
|
||||
|
||||
const roboto = Roboto({
|
||||
subsets: ['latin']
|
||||
@@ -57,6 +57,7 @@ export default function RootLayout ({
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [loadingText, setLoadingText] = useState('Loading...')
|
||||
const [outdated, setOutdated] = useState(false)
|
||||
const [version, setVersion] = useState<string | null>(null)
|
||||
|
||||
const [serverVersionList, setServerVersionList] =
|
||||
useState<null | ServerVersionsResponse>(null)
|
||||
@@ -93,23 +94,6 @@ export default function RootLayout ({
|
||||
|
||||
const pathname = usePathname()
|
||||
|
||||
const notifyUser = useCallback(
|
||||
async (title: string, body: string) => {
|
||||
if (!normalConfig?.settings.allowNotifications) return
|
||||
|
||||
let permissionGranted = await isPermissionGranted()
|
||||
if (!permissionGranted) {
|
||||
const permission = await requestPermission()
|
||||
permissionGranted = permission === 'granted'
|
||||
}
|
||||
|
||||
if (permissionGranted) {
|
||||
sendNotification({ title, body })
|
||||
}
|
||||
},
|
||||
[normalConfig]
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
let unlistenProgress: (() => void) | null = null
|
||||
let unlistenUninstalled: (() => void) | null = null
|
||||
@@ -183,17 +167,18 @@ export default function RootLayout ({
|
||||
unlistenProgress?.()
|
||||
unlistenUninstalled?.()
|
||||
}
|
||||
}, [notifyUser])
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
;(async () => {
|
||||
const client = await app.getVersion()
|
||||
setVersion(client)
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
setLoadingText('Checking latest version...')
|
||||
try {
|
||||
const response = await axios.get(
|
||||
'https://games.lncvrt.xyz/api/launcher/latest'
|
||||
)
|
||||
const client = await app.getVersion()
|
||||
if (response.data !== client) {
|
||||
setOutdated(true)
|
||||
return
|
||||
@@ -220,10 +205,8 @@ export default function RootLayout ({
|
||||
setNormalConfig(normalConfig)
|
||||
setLoading(false)
|
||||
|
||||
let permissionGranted = await isPermissionGranted()
|
||||
if (!permissionGranted) {
|
||||
const permission = await requestPermission()
|
||||
permissionGranted = permission === 'granted'
|
||||
if (!(await isPermissionGranted())) {
|
||||
await requestPermission()
|
||||
}
|
||||
})()
|
||||
}, [])
|
||||
@@ -336,14 +319,16 @@ export default function RootLayout ({
|
||||
: d
|
||||
)
|
||||
)
|
||||
await notifyUser(
|
||||
'Download Failed',
|
||||
`The download for version ${gameInfo.name} v${info.versionName} has failed.`
|
||||
)
|
||||
if (normalConfig?.settings.allowNotifications)
|
||||
await notifyUser(
|
||||
'Download Failed',
|
||||
`The download for version ${gameInfo.name} v${info.versionName} has failed.`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
await notifyUser('Downloads Finished', 'All downloads have finished.')
|
||||
if (normalConfig?.settings.allowNotifications)
|
||||
await notifyUser('Downloads Finished', 'All downloads have finished.')
|
||||
}
|
||||
|
||||
function getVersionsAmountData (gameId: number): {
|
||||
@@ -439,7 +424,8 @@ export default function RootLayout ({
|
||||
getListOfGames,
|
||||
setSelectedGame,
|
||||
getVersionsAmountData,
|
||||
viewingInfoFromDownloads
|
||||
viewingInfoFromDownloads,
|
||||
version
|
||||
}}
|
||||
>
|
||||
<div
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react'
|
||||
import { Setting } from '../componets/Setting'
|
||||
import { writeNormalConfig } from '../util/BazookaManager'
|
||||
import { useGlobal } from '../GlobalProvider'
|
||||
import { copyToClipboard } from '../util/Clipboard'
|
||||
|
||||
export default function Settings () {
|
||||
const [allowNotifications, setAllowNotifications] = useState(false)
|
||||
@@ -12,7 +13,7 @@ export default function Settings () {
|
||||
const [theme, setTheme] = useState(0)
|
||||
|
||||
const [loaded, setLoaded] = useState(false)
|
||||
const { normalConfig, setNormalConfig } = useGlobal()
|
||||
const { normalConfig, setNormalConfig, version } = useGlobal()
|
||||
|
||||
useEffect(() => {
|
||||
;(async () => {
|
||||
@@ -117,6 +118,14 @@ export default function Settings () {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<p
|
||||
className='fixed bottom-1.5 right-1.5 rounded-md cursor-pointer px-1 border z-100 transition-colors btntheme1'
|
||||
onClick={async () => {
|
||||
await copyToClipboard(`v${version}`, normalConfig)
|
||||
}}
|
||||
>
|
||||
v{version}
|
||||
</p>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
10
src/app/util/Clipboard.ts
Normal file
10
src/app/util/Clipboard.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { NormalConfig } from '../types/NormalConfig'
|
||||
import { notifyUser } from './Notifications'
|
||||
|
||||
export async function copyToClipboard (
|
||||
text: string,
|
||||
normalConfig: NormalConfig | null
|
||||
) {
|
||||
if (normalConfig?.settings.allowNotifications)
|
||||
await notifyUser('Copied', 'Text "' + text + '" copied to clipboard')
|
||||
}
|
||||
17
src/app/util/Notifications.ts
Normal file
17
src/app/util/Notifications.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import {
|
||||
isPermissionGranted,
|
||||
requestPermission,
|
||||
sendNotification
|
||||
} from '@tauri-apps/plugin-notification'
|
||||
|
||||
export async function notifyUser (title: string, body: string) {
|
||||
let permissionGranted = await isPermissionGranted()
|
||||
if (!permissionGranted) {
|
||||
const permission = await requestPermission()
|
||||
permissionGranted = permission === 'granted'
|
||||
}
|
||||
|
||||
if (permissionGranted) {
|
||||
sendNotification({ title, body })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user