AppViewController.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // AppViewController.swift
  3. // Logseq
  4. //
  5. // Created by Charlie on 2025/5/30.
  6. //
  7. import Foundation
  8. import Capacitor
  9. import UIKit
  10. @objc public class AppViewController: CAPBridgeViewController {
  11. override public func capacitorDidLoad() {
  12. bridge?.registerPluginInstance(UILocalPlugin())
  13. bridge?.registerPluginInstance(NativeTopBarPlugin())
  14. bridge?.registerPluginInstance(LiquidTabsPlugin())
  15. bridge?.registerPluginInstance(NativeBottomSheetPlugin())
  16. bridge?.registerPluginInstance(NativeEditorToolbarPlugin())
  17. bridge?.registerPluginInstance(NativeSelectionActionBarPlugin())
  18. }
  19. public override func viewDidLoad() {
  20. super.viewDidLoad()
  21. // initial setup
  22. applyLogseqTheme()
  23. }
  24. // MARK: - Theme application (background + tint)
  25. private func applyLogseqTheme() {
  26. let bg = UIColor.logseqBackground
  27. let tint = UIColor.logseqTint
  28. // Background
  29. view.backgroundColor = bg
  30. if let webView = self.webView {
  31. webView.isOpaque = true
  32. webView.backgroundColor = bg
  33. webView.scrollView.backgroundColor = bg
  34. // Sometimes WKWebView uses an internal subview for its background
  35. webView.scrollView.subviews.first?.backgroundColor = bg
  36. }
  37. // Tint
  38. view.tintColor = tint
  39. webView?.tintColor = tint
  40. webView?.scrollView.tintColor = tint
  41. // Propagate to container UI if possible
  42. navigationController?.view.tintColor = tint
  43. navigationController?.navigationBar.tintColor = tint
  44. navigationController?.tabBarController?.tabBar.tintColor = tint
  45. // Global window tint (affects many UIKit + SwiftUI bits)
  46. if let window = view.window {
  47. window.tintColor = tint
  48. }
  49. }
  50. public override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
  51. super.traitCollectionDidChange(previousTraitCollection)
  52. guard let previousTraitCollection,
  53. traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) else {
  54. return
  55. }
  56. // Re-apply dynamic colors when light/dark changes
  57. applyLogseqTheme()
  58. }
  59. }