설정에서 시스템/한국어/영어/일본어 선택을 지원한다. 선택 시 Accept-Language 헤더와 UI locale을 즉시 반영한다. 언어 변경 후 스플래시를 거쳐 메인으로 소프트 재시작한다.
87 lines
2.2 KiB
Swift
87 lines
2.2 KiB
Swift
//
|
|
// AppState.swift
|
|
// SodaLive
|
|
//
|
|
// Created by klaus on 2023/08/09.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
class AppState: ObservableObject {
|
|
static let shared = AppState()
|
|
|
|
private var appStepBackStack = [AppStep]()
|
|
|
|
@Published var alreadyUpdatedMarketingInfo = false
|
|
@Published private(set) var appStep: AppStep = .splash
|
|
|
|
@Published var isShowPlayer = false {
|
|
didSet {
|
|
if isShowPlayer {
|
|
ContentPlayManager.shared.stopAudio()
|
|
ContentPlayerPlayManager.shared.resetPlayer()
|
|
}
|
|
}
|
|
}
|
|
|
|
@Published var isShowNotificationSettingsDialog = false
|
|
|
|
@Published var pushRoomId = 0
|
|
@Published var pushChannelId = 0
|
|
@Published var pushMessageId = 0
|
|
@Published var pushAudioContentId = 0
|
|
@Published var pushSeriesId = 0
|
|
@Published var roomId = 0 {
|
|
didSet {
|
|
if roomId <= 0 {
|
|
isShowPlayer = false
|
|
}
|
|
}
|
|
}
|
|
|
|
@Published var eventPopup: EventItem? = nil
|
|
@Published var purchasedContentId = 0
|
|
@Published var purchasedContentOrderType = OrderType.KEEP
|
|
|
|
@Published var isRestartApp = false
|
|
@Published var startTab: HomeViewModel.CurrentTab = .home
|
|
|
|
@Published var marketingUtmSource = ""
|
|
@Published var marketingUtmMedium = ""
|
|
@Published var marketingUtmCampaign = ""
|
|
|
|
@Published var isShowErrorPopup = false
|
|
@Published var errorMessage = ""
|
|
|
|
func setAppStep(step: AppStep) {
|
|
switch step {
|
|
case .splash, .main:
|
|
appStepBackStack.removeAll()
|
|
|
|
default:
|
|
appStepBackStack.append(appStep)
|
|
}
|
|
|
|
DispatchQueue.main.async {
|
|
self.appStep = step
|
|
}
|
|
}
|
|
|
|
func back() {
|
|
if let step = appStepBackStack.popLast() {
|
|
self.appStep = step
|
|
} else {
|
|
self.appStep = .main
|
|
}
|
|
}
|
|
|
|
// 언어 적용 직후 앱을 소프트 재시작(스플래시 -> 메인)하여 전역 UI를 새로고침
|
|
func softRestart() {
|
|
isRestartApp = true
|
|
setAppStep(step: .splash)
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
|
self.setAppStep(step: .main)
|
|
}
|
|
}
|
|
}
|