AppDelegate.swift 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // AppDelegate.swift
  3. // TSLiveWallpaper
  4. //
  5. // Created by 100Years on 2024/12/19.i
  6. //
  7. import StoreKit
  8. import TSVideoKit
  9. import UIKit
  10. import Kingfisher
  11. @main
  12. class AppDelegate: UIResponder, UIApplicationDelegate {
  13. var window: UIWindow?
  14. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  15. window = UIWindow(frame: UIScreen.main.bounds)
  16. window?.backgroundColor = UIColor.black
  17. window?.makeKeyAndVisible()
  18. goToLoadVC()
  19. initBaseDatas()
  20. initPlatform()
  21. downloadNotifaction()
  22. return true
  23. }
  24. func goToTab() {
  25. window?.rootViewController = TSTabBarController()
  26. }
  27. func goToLoadVC() {
  28. _ = TSImageDataCenter.shared
  29. window?.rootViewController = TSLaunchVC()
  30. }
  31. func initBaseDatas() {
  32. var config = TSConfiguration.default
  33. config.configurePath = "http://p.100yearslater.com/live/config"
  34. TSVideoOperator.shared.loadWithConfiguration(config: config, needJs: false)
  35. if let videoId = UserDefaults.standard.string(forKey: "lastedVideoId"),
  36. !videoId.isEmpty,
  37. let lastVideo = TSVideoOperator.shared.dataManager.fetchVideo(videoId: videoId) {
  38. TSVideoOperator.shared.playerViewModel.currentVideo = lastVideo
  39. TSVideoOperator.shared.playerViewModel.currentVideos = TSVideoOperator.shared.dataManager.fetchCachedVideos()
  40. PlayerManager.shared.miniBar.updateVideoInfo(video: lastVideo, state: .pause)
  41. }
  42. if let loopMode = UserDefaults.standard.string(forKey: "lastedPlayMode") {
  43. let mMode = LoopMode(rawValue: loopMode) ?? .cyclic
  44. TSVideoOperator.shared.playerViewModel.loopMode = mMode
  45. }
  46. }
  47. @objc func recordData() {
  48. if UserDefaults.standard.value(forKey: "CachedTag") == nil {
  49. UserDefaults.standard.setValue("1", forKey: "CachedTag")
  50. SKStoreReviewController.requestReview()
  51. }
  52. }
  53. func downloadNotifaction() {
  54. NotificationCenter.default.addObserver(self, selector: #selector(recordData), name: kGroupDownloadFinishNotifactionName, object: nil)
  55. }
  56. func applicationDidBecomeActive(_ application: UIApplication) {
  57. }
  58. func applicationWillTerminate(_ application: UIApplication) {
  59. UserDefaults.standard.setValue(PlayerManager.shared.currentVideo?.videoId ?? "", forKey: "lastedVideoId")
  60. UserDefaults.standard.setValue(PlayerManager.shared.currentLoopMode.rawValue, forKey: "lastedPlayMode")
  61. }
  62. func applicationWillEnterForeground(_ application: UIApplication) {
  63. }
  64. }
  65. extension AppDelegate {
  66. func initPlatform() {
  67. dePrint("TSRMShared.aiListDB.listModels.count=\(TSRMShared.aiListDB.listModels.count)")
  68. TSColorConfigShared.naviMianTextColor = .white
  69. let cache = ImageCache(name: "permanent_image_cache")
  70. cache.diskStorage.config.expiration = .never // 永不过期
  71. cache.diskStorage.config.sizeLimit = 0 // 无大小限制
  72. KingfisherManager.shared.cache = cache
  73. }
  74. }