@@ -29,6 +29,7 @@ import { type FTInfo, startFileTrack, unmountFileTrack } from "@App/pkg/utils/fi
2929import { cleanupOldHandles , loadHandle , saveHandle } from "@App/pkg/utils/filehandle-db" ;
3030import { dayFormat } from "@App/pkg/utils/day_format" ;
3131import { intervalExecution , timeoutExecution } from "@App/pkg/utils/timer" ;
32+ import { useSearchParams } from "react-router-dom" ;
3233
3334type ScriptOrSubscribe = Script | Subscribe ;
3435
@@ -58,6 +59,8 @@ function App() {
5859 const [ isUpdate , setIsUpdate ] = useState < boolean > ( false ) ;
5960 const [ localFileHandle , setLocalFileHandle ] = useState < FileSystemFileHandle | null > ( null ) ;
6061 const { t } = useTranslation ( ) ;
62+ const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
63+ const [ loaded , setLoaded ] = useState < boolean > ( false ) ;
6164
6265 const installOrUpdateScript = async ( newScript : Script , code : string ) => {
6366 if ( newScript . ignoreVersion ) newScript . ignoreVersion = "" ;
@@ -84,10 +87,16 @@ function App() {
8487
8588 const initAsync = async ( ) => {
8689 try {
87- const locationUrl = new URL ( window . location . href ) ;
88- const uuid = locationUrl . searchParams . get ( "uuid " ) ;
90+ const uuid = searchParams . get ( "uuid" ) ;
91+ const fid = searchParams . get ( "file " ) ;
8992 let info : ScriptInfo | undefined ;
9093 let isKnownUpdate : boolean = false ;
94+
95+ // 如果没有 uuid 和 file,跳过初始化逻辑
96+ if ( ! uuid && ! fid ) {
97+ return ;
98+ }
99+
91100 if ( uuid ) {
92101 const cachedInfo = await scriptClient . getInstallInfo ( uuid ) ;
93102 if ( cachedInfo ?. [ 0 ] ) isKnownUpdate = true ;
@@ -97,7 +106,6 @@ function App() {
97106 }
98107 } else {
99108 // 检查是不是本地文件安装
100- const fid = locationUrl . searchParams . get ( "file" ) ;
101109 if ( ! fid ) {
102110 throw new Error ( "url param - local file id is not found" ) ;
103111 }
@@ -152,6 +160,7 @@ function App() {
152160 }
153161 diffCode = prepare . oldScriptCode ;
154162 }
163+ setLoaded ( true ) ;
155164 setScriptCode ( code ) ;
156165 setDiffCode ( diffCode ) ;
157166 setOldScriptVersion ( typeof oldVersion === "string" ? oldVersion : null ) ;
@@ -171,8 +180,8 @@ function App() {
171180 } ;
172181
173182 useEffect ( ( ) => {
174- initAsync ( ) ;
175- } , [ ] ) ;
183+ ! loaded && initAsync ( ) ;
184+ } , [ searchParams , loaded ] ) ;
176185
177186 const [ watchFile , setWatchFile ] = useState ( false ) ;
178187 const metadataLive = useMemo ( ( ) => ( scriptInfo ?. metadata || { } ) as SCMetadata , [ scriptInfo ] ) ;
@@ -464,6 +473,33 @@ function App() {
464473 } ;
465474 } , [ memoWatchFile ] ) ;
466475
476+ // 处理没有 uuid 和 file 的情况
477+ // const handleCreateNewScript = () => {
478+ // const newUuid = uuidv4();
479+ // setSearchParams({ uuid: newUuid }, { replace: true });
480+ // };
481+
482+ // 检查是否有 uuid 或 file
483+ const hasParams = useMemo ( ( ) => {
484+ return ! ! ( searchParams . get ( "uuid" ) || searchParams . get ( "file" ) ) ;
485+ } , [ searchParams ] ) ;
486+
487+ // 没有 uuid 和 file 时显示的页面
488+ if ( ! hasParams ) {
489+ return (
490+ < div className = "flex justify-center items-center h-screen" >
491+ < Space direction = "vertical" align = "center" >
492+ < Typography . Title heading = { 3 } > { t ( "no_script_selected" ) } </ Typography . Title >
493+ { /*
494+ <Button type="primary" onClick={handleCreateNewScript}>
495+ {t("create_new_script")}
496+ </Button>
497+ */ }
498+ </ Space >
499+ </ div >
500+ ) ;
501+ }
502+
467503 return (
468504 < div id = "install-app-container" >
469505 < Grid . Row className = "mb-2" gutter = { 8 } >
0 commit comments