@@ -7,7 +7,9 @@ import androidx.compose.runtime.DisposableEffect
77import androidx.compose.runtime.LaunchedEffect
88import androidx.compose.runtime.collectAsState
99import androidx.compose.runtime.getValue
10+ import androidx.compose.runtime.mutableStateOf
1011import androidx.compose.runtime.remember
12+ import androidx.compose.runtime.setValue
1113import androidx.compose.runtime.snapshotFlow
1214import androidx.compose.ui.Alignment
1315import androidx.compose.ui.graphics.painter.Painter
@@ -34,9 +36,12 @@ import com.jankinwu.fntv.client.ui.providable.LocalWebViewInitialized
3436import com.jankinwu.fntv.client.ui.providable.LocalWebViewRestartRequired
3537import com.jankinwu.fntv.client.ui.providable.LocalWindowHandle
3638import com.jankinwu.fntv.client.ui.providable.LocalWindowState
39+ import com.jankinwu.fntv.client.ui.screen.FnConnectWebViewScreen
40+ import com.jankinwu.fntv.client.ui.screen.FnConnectWindowRequest
3741import com.jankinwu.fntv.client.ui.screen.LoginScreen
3842import com.jankinwu.fntv.client.ui.screen.PlayerManager
3943import com.jankinwu.fntv.client.ui.screen.PlayerOverlay
44+ import com.jankinwu.fntv.client.ui.screen.upsertLoginHistory
4045import com.jankinwu.fntv.client.utils.ConsoleLogWriter
4146import com.jankinwu.fntv.client.utils.DesktopContext
4247import com.jankinwu.fntv.client.utils.ExecutableDirectoryDetector
@@ -102,6 +107,7 @@ fun main() {
102107 KoinApplication (application = {
103108 modules(viewModelModule, apiModule)
104109 }) {
110+ var fnConnectWindowRequest by remember { mutableStateOf<FnConnectWindowRequest ?>(null ) }
105111 Window (
106112 onCloseRequest = ::exitApplication,
107113 state = state,
@@ -209,7 +215,10 @@ fun main() {
209215 if (! isLoggedIn) {
210216 LoginScreen (
211217 navigator = navigator,
212- draggableArea = { content -> WindowDraggableArea (content = content) }
218+ draggableArea = { content -> WindowDraggableArea (content = content) },
219+ onOpenFnConnectWindow = { request ->
220+ fnConnectWindowRequest = request
221+ }
213222 )
214223 } else {
215224 App (
@@ -234,6 +243,60 @@ fun main() {
234243 }
235244 }
236245 }
246+
247+ val request = fnConnectWindowRequest
248+ if (request != null ) {
249+ val fnConnectWindowState = rememberWindowState(
250+ size = DpSize (980 .dp, 720 .dp),
251+ position = WindowPosition .Aligned (Alignment .Center )
252+ )
253+
254+ Window (
255+ onCloseRequest = { fnConnectWindowRequest = null },
256+ state = fnConnectWindowState,
257+ title = " FN Connect 登录" ,
258+ icon = icon
259+ ) {
260+ val desktopContext = remember(fnConnectWindowState) {
261+ val dataDir = logDir.parentFile.resolve(" data" ).apply { if (! exists()) mkdirs() }
262+ val cacheDir = logDir.parentFile.resolve(" cache" ).apply { if (! exists()) mkdirs() }
263+ DesktopContext (fnConnectWindowState, dataDir, cacheDir, logDir, ExtraWindowProperties ())
264+ }
265+
266+ CompositionLocalProvider (
267+ LocalContext provides desktopContext,
268+ LocalPlayerManager provides remember { PlayerManager () },
269+ LocalFrameWindowScope provides this @Window,
270+ LocalWindowState provides fnConnectWindowState,
271+ LocalWindowHandle provides window.windowHandle,
272+ LocalWebViewInitialized provides (webViewInitialized && ! webViewRestartRequired && webViewInitError == null ),
273+ LocalWebViewRestartRequired provides webViewRestartRequired,
274+ LocalWebViewInitError provides webViewInitError
275+ ) {
276+ AppTheme (
277+ displayMicaLayer = true ,
278+ state = fnConnectWindowState
279+ ) {
280+ FnConnectWebViewScreen (
281+ initialUrl = request.initialUrl,
282+ fnId = request.fnId,
283+ onBack = { fnConnectWindowRequest = null },
284+ onLoginSuccess = { history ->
285+ val preferencesManager = PreferencesManager .getInstance()
286+ val current = preferencesManager.loadLoginHistory()
287+ val updated = upsertLoginHistory(current, history)
288+ preferencesManager.saveLoginHistory(updated)
289+ fnConnectWindowRequest = null
290+ },
291+ autoLoginUsername = request.autoLoginUsername,
292+ autoLoginPassword = request.autoLoginPassword,
293+ allowAutoLogin = request.allowAutoLogin,
294+ draggableArea = { content -> WindowDraggableArea (content = content) }
295+ )
296+ }
297+ }
298+ }
299+ }
237300 }
238301}
239302}
0 commit comments