1 |
efrain |
1 |
//
|
|
|
2 |
// twogetskillsApp.swift
|
|
|
3 |
// twogetskills
|
|
|
4 |
//
|
|
|
5 |
// Created by Efrain Yanez Recanatini on 1/12/22.
|
|
|
6 |
//
|
|
|
7 |
|
|
|
8 |
import SwiftUI
|
|
|
9 |
import BackgroundTasks
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
@main
|
|
|
13 |
struct TwoGetSkillsApp: App {
|
|
|
14 |
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
|
|
|
15 |
@Environment(\.scenePhase) var scenePhase
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
@ObservedObject var syncForeground = SyncForegroundObservableObject()
|
|
|
19 |
private let syncAdapter = SyncAdapter()
|
21 |
efrain |
20 |
private var appData = Environment(\.appData).wrappedValue
|
1 |
efrain |
21 |
|
|
|
22 |
init() {
|
|
|
23 |
let coloredAppearance = UINavigationBarAppearance()
|
|
|
24 |
coloredAppearance.configureWithOpaqueBackground()
|
|
|
25 |
coloredAppearance.backgroundColor = UIColor(Color("color_app_bar_backgroud"))
|
|
|
26 |
coloredAppearance.titleTextAttributes = [.foregroundColor: Color("color_app_bar_foreground")]
|
|
|
27 |
coloredAppearance.largeTitleTextAttributes = [.foregroundColor: Color("color_app_bar_foreground")]
|
|
|
28 |
coloredAppearance.backButtonAppearance.normal.titleTextAttributes = [.foregroundColor: Color("color_app_bar_foreground")]
|
|
|
29 |
|
|
|
30 |
UINavigationBar.appearance().standardAppearance = coloredAppearance
|
|
|
31 |
UINavigationBar.appearance().compactAppearance = coloredAppearance
|
|
|
32 |
UINavigationBar.appearance().scrollEdgeAppearance = coloredAppearance
|
|
|
33 |
|
|
|
34 |
UINavigationBar.appearance().tintColor = UIColor(Color("color_app_bar_foreground"))
|
|
|
35 |
|
|
|
36 |
UIPageControl.appearance().currentPageIndicatorTintColor = .systemBlue
|
|
|
37 |
UIPageControl.appearance().pageIndicatorTintColor = .systemGray2
|
21 |
efrain |
38 |
|
1 |
efrain |
39 |
}
|
|
|
40 |
|
|
|
41 |
var body: some Scene {
|
|
|
42 |
|
|
|
43 |
WindowGroup {
|
|
|
44 |
MainView()
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
.onChange(of: scenePhase) { newScenePhase in
|
|
|
48 |
switch newScenePhase {
|
|
|
49 |
case .active:
|
|
|
50 |
print("App is active")
|
|
|
51 |
syncForeground.timer.invalidate()
|
|
|
52 |
syncForeground.timer = Timer.scheduledTimer(timeInterval: 30.0, target: syncAdapter, selector: #selector(syncAdapter.updateTimerForeground), userInfo: nil, repeats: true)
|
|
|
53 |
break
|
|
|
54 |
|
|
|
55 |
case .inactive:
|
|
|
56 |
print("App is inactive")
|
|
|
57 |
syncForeground.timer.invalidate()
|
|
|
58 |
break
|
|
|
59 |
|
|
|
60 |
case .background:
|
|
|
61 |
print("App is in background")
|
|
|
62 |
syncForeground.timer.invalidate()
|
|
|
63 |
break
|
|
|
64 |
|
|
|
65 |
@unknown default:
|
|
|
66 |
print("Oh - interesting: I received an unexpected new value.")
|
|
|
67 |
syncForeground.timer.invalidate()
|
|
|
68 |
break
|
|
|
69 |
}
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
|
12 |
efrain |
73 |
|
1 |
efrain |
74 |
}
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
class SyncForegroundObservableObject: ObservableObject
|
|
|
78 |
{
|
|
|
79 |
@Published var timer : Timer = Timer()
|
|
|
80 |
}
|