improve: better popup blocker detection and type safety

- Add immediate popup blocker detection with user-friendly error message
- Improve type safety by removing any types
- Simplify logic flow in useAsyncWindowOpen hook

Addresses code review suggestions
This commit is contained in:
yyh 2025-12-10 12:19:25 +08:00
parent e95b7b57c9
commit bac0513b8b
No known key found for this signature in database
3 changed files with 18 additions and 8 deletions

View File

@ -223,8 +223,8 @@ const AppPublisher = ({
openAsync(
async () => {
const { installed_apps }: any = await fetchInstalledAppList(appDetail.id) || {}
if (installed_apps?.length > 0)
const { installed_apps }: { installed_apps?: { id: string }[] } = await fetchInstalledAppList(appDetail.id) || {}
if (installed_apps && installed_apps.length > 0)
return `${basePath}/explore/installed/${installed_apps[0].id}`
throw new Error('No app found in Explore')
},

View File

@ -252,8 +252,8 @@ const AppCard = ({ app, onRefresh }: AppCardProps) => {
openAsync(
async () => {
const { installed_apps }: any = await fetchInstalledAppList(app.id) || {}
if (installed_apps?.length > 0)
const { installed_apps }: { installed_apps?: { id: string }[] } = await fetchInstalledAppList(app.id) || {}
if (installed_apps && installed_apps.length > 0)
return `${basePath}/explore/installed/${installed_apps[0].id}`
throw new Error('No app found in Explore')
},

View File

@ -24,10 +24,20 @@ export const useAsyncWindowOpen = () => {
const newWindow = window.open('', '_blank', windowFeatures)
if (!newWindow) {
const error = new Error('Popup blocked by browser')
onError?.(error)
Toast.notify({
type: 'error',
message: 'Popup blocked. Please allow popups for this site.',
})
return
}
try {
const url = await fetchUrl()
if (url && newWindow) {
if (url) {
newWindow.location.href = url
onSuccess?.(url)
@ -39,8 +49,8 @@ export const useAsyncWindowOpen = () => {
}
}
else {
newWindow?.close()
const error = new Error('Invalid URL or window was closed')
newWindow.close()
const error = new Error('Invalid URL received')
onError?.(error)
Toast.notify({
type: 'error',
@ -49,7 +59,7 @@ export const useAsyncWindowOpen = () => {
}
}
catch (error) {
newWindow?.close()
newWindow.close()
onError?.(error)
Toast.notify({
type: 'error',