@@ -13,33 +13,49 @@ import WebKit
1313class SceneDelegate : UIResponder , UIWindowSceneDelegate {
1414
1515 @Injected ( \. settingsService) private var settingsService
16+ @Injected ( \. cookiesService) private var cookiesService
1617
1718 var window : UIWindow ?
1819
19- var webView : WKWebView !
20+ var webView : WKWebView = {
21+ let config = WKWebViewConfiguration ( )
22+ let webView = WKWebView ( frame: . zero, configuration: config)
23+ webView. tag = 666
24+ return webView
25+ } ( )
2026
2127 func scene( _ scene: UIScene , willConnectTo session: UISceneSession , options connectionOptions: UIScene . ConnectionOptions ) {
2228 guard let windowScene = ( scene as? UIWindowScene ) else { return }
2329 self . window = UIWindow ( windowScene: windowScene)
2430
2531 window? . rootViewController = UIViewController ( )
32+ window? . addSubview ( webView)
2633 window? . makeKeyAndVisible ( )
2734
2835 overrideApplicationThemeStyle ( with: settingsService. getAppTheme ( ) )
29- configureWKWebView ( )
30-
31- if let url = connectionOptions. urlContexts. first? . url {
36+ cookiesService. syncCookies ( )
37+ handleNavigation ( to: connectionOptions. urlContexts. first? . url)
38+ }
39+ }
40+
41+ extension SceneDelegate {
42+
43+ // MARK: - Navigation
44+
45+ private func handleNavigation( to url: URL ? ) {
46+ if let url {
3247 // Cold start deeplink
3348 handleDeeplinkUrl ( url)
3449 } else {
50+ // Handle 'try?' later (todo)
51+ // handleDeeplinkUrl(URL(string: "forpda://article/2023/10/21/419630/")!)
3552 try ? DefaultRouter ( ) . navigate ( to: RouteMap . newsScreen, with: nil )
3653 }
3754 }
3855
3956 private func handleDeeplinkUrl( _ url: URL ) {
4057 if url. absoluteString == " forpda://article// " {
41- // Если share в браузере не сработал, то открываем новости
42- // todo обработать нормально
58+ // If share didn't work in browser, fallback to news (also bug with share inside app) (todo)
4359 try ? DefaultRouter ( ) . navigate ( to: RouteMap . newsScreen, with: nil )
4460 } else {
4561 settingsService. setIsDeeplinking ( to: true )
@@ -50,36 +66,15 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
5066 }
5167 }
5268
53- private func configureWKWebView( ) {
54- let config = WKWebViewConfiguration ( )
55- webView = WKWebView ( frame: . zero, configuration: config)
56- webView. tag = 666
57- window? . addSubview ( webView)
58-
59- for cookie in HTTPCookieStorage . shared. cookies ?? [ ] {
60- WKWebsiteDataStore . default ( ) . httpCookieStore. setCookie ( cookie)
61- }
62- }
63-
6469 // Opens on existing scene
6570 func scene( _ scene: UIScene , openURLContexts URLContexts: Set < UIOpenURLContext > ) {
6671 if let url = URLContexts . first? . url {
6772 handleDeeplinkUrl ( url)
6873 }
6974 }
7075
71- func sceneDidDisconnect( _ scene: UIScene ) { }
72-
73- func sceneDidBecomeActive( _ scene: UIScene ) { }
74-
75- func sceneWillResignActive( _ scene: UIScene ) { }
76-
77- func sceneWillEnterForeground( _ scene: UIScene ) { }
78-
79- func sceneDidEnterBackground( _ scene: UIScene ) { }
80- }
81-
82- extension SceneDelegate {
76+ // MARK: - Themes
77+
8378 func overrideApplicationThemeStyle( with theme: AppTheme ) {
8479 window? . overrideUserInterfaceStyle = UIUserInterfaceStyle ( rawValue: theme. ordinal ( ) ) !
8580 }
0 commit comments