This commit is contained in:
cheykrym 2025-12-18 07:39:41 +03:00
parent cb0a8f249e
commit 4442dfc821
4 changed files with 127 additions and 115 deletions

View File

@ -10,7 +10,7 @@ import Combine
import SwiftUI import SwiftUI
class LoginViewModel: ObservableObject { class LoginViewModel: ObservableObject {
@AppStorage("appIsBlocked") private var isAppBlocked: Bool = false // @AppStorage("appIsBlocked") private var isAppBlocked: Bool = false
@Published var username: String = "" @Published var username: String = ""
@Published var userId: String = "" @Published var userId: String = ""
@ -137,8 +137,7 @@ class LoginViewModel: ObservableObject {
self?.socketService.disconnect() self?.socketService.disconnect()
} }
self?.isLoading = false self?.isLoading = false
if self?.isAppBlocked == false{ self?.isInitialLoading = false
self?.isInitialLoading = false}
} }
} }
} }

View File

@ -1,50 +0,0 @@
import SwiftUI
struct ForceUpdateView: View {
let title: String
let message: String
let onUpdate: () -> Void
var body: some View {
ZStack {
Color.black.opacity(0.6)
.ignoresSafeArea()
VStack(spacing: 16) {
Text(title)
.font(.title3.weight(.semibold))
.multilineTextAlignment(.center)
.foregroundColor(.primary)
Text(message)
.font(.body)
.multilineTextAlignment(.center)
.foregroundColor(.primary)
Button(action: onUpdate) {
Text(NSLocalizedString("Обновить приложение", comment: ""))
.font(.headline)
.frame(maxWidth: .infinity)
.padding()
.background(Color.accentColor)
.foregroundColor(.white)
.cornerRadius(12)
}
}
.padding(24)
.background(.ultraThinMaterial)
.cornerRadius(20)
.padding(32)
}
.zIndex(2)
.accessibilityElement(children: .contain)
}
}
struct ForceUpdateView_Previews: PreviewProvider {
static var previews: some View {
ForceUpdateView(title: "Требуется обновление",
message: "Эта версия приложения устарела и больше не поддерживается.",
onUpdate: {})
}
}

View File

@ -0,0 +1,62 @@
import SwiftUI
struct NeedUpdateView: View {
let title: String
let message: String
let onUpdate: () -> Void
var body: some View {
ZStack {
LinearGradient(
colors: [Color(.systemBackground), Color(.systemGray6)],
startPoint: .top,
endPoint: .bottom
)
.ignoresSafeArea()
VStack(spacing: 24) {
Spacer()
Image(systemName: "exclamationmark.triangle.fill")
.font(.system(size: 56, weight: .bold))
.foregroundColor(.orange)
.accessibilityHidden(true)
VStack(spacing: 12) {
Text(title)
.font(.title2.weight(.semibold))
.multilineTextAlignment(.center)
Text(message)
.font(.body)
.multilineTextAlignment(.center)
.foregroundColor(.secondary)
}
Button(action: onUpdate) {
Text(NSLocalizedString("Обновить приложение", comment: ""))
.font(.headline)
.frame(maxWidth: .infinity)
.padding()
.background(Color.accentColor)
.foregroundColor(.white)
.cornerRadius(14)
}
Spacer()
}
.padding(32)
.frame(maxWidth: 480)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.accessibilityElement(children: .contain)
}
}
struct NeedUpdateView_Previews: PreviewProvider {
static var previews: some View {
NeedUpdateView(title: "Требуется обновление",
message: "Эта версия приложения устарела и больше не поддерживается.",
onUpdate: {})
}
}

View File

@ -21,43 +21,72 @@ struct yobbleApp: App {
var body: some Scene { var body: some Scene {
WindowGroup { WindowGroup {
ZStack(alignment: .top) { Group {
Group { if let notice = updateChecker.needUpdateNotice {
if viewModel.isInitialLoading { NeedUpdateView(
SplashScreenView() title: notice.title,
} else if viewModel.isLoggedIn { message: notice.message,
MainView(viewModel: viewModel) onUpdate: { updateChecker.openAppStore() }
} else {
LoginView(viewModel: viewModel)
}
}
if let banner = messageCenter.banner {
NewMessageBannerView(
banner: banner,
onOpen: { messageCenter.openCurrentChat() },
onDismiss: { messageCenter.dismissBanner() }
) )
.padding(.horizontal, 16) } else {
.padding(.top, 12) ZStack(alignment: .top) {
.transition(.move(edge: .top).combined(with: .opacity)) Group {
.zIndex(1) if viewModel.isInitialLoading {
} SplashScreenView()
} } else if viewModel.isLoggedIn {
.animation(.spring(response: 0.35, dampingFraction: 0.8), value: messageCenter.banner != nil) MainView(viewModel: viewModel)
.sheet(item: AppConfig.PRESENT_CHAT_AS_SHEET ? $messageCenter.presentedChat : .constant(nil)) { chatItem in } else {
NavigationView { LoginView(viewModel: viewModel)
PrivateChatView(
chat: chatItem,
currentUserId: messageCenter.currentUserId
)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button(NSLocalizedString("Закрыть", comment: "")) {
messageCenter.presentedChat = nil
}
} }
} }
if let banner = messageCenter.banner {
NewMessageBannerView(
banner: banner,
onOpen: { messageCenter.openCurrentChat() },
onDismiss: { messageCenter.dismissBanner() }
)
.padding(.horizontal, 16)
.padding(.top, 12)
.transition(.move(edge: .top).combined(with: .opacity))
.zIndex(1)
}
}
.animation(.spring(response: 0.35, dampingFraction: 0.8), value: messageCenter.banner != nil)
.sheet(item: AppConfig.PRESENT_CHAT_AS_SHEET ? $messageCenter.presentedChat : .constant(nil)) { chatItem in
NavigationView {
PrivateChatView(
chat: chatItem,
currentUserId: messageCenter.currentUserId
)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button(NSLocalizedString("Закрыть", comment: "")) {
messageCenter.presentedChat = nil
}
}
}
}
}
.alert(item: Binding(
get: { updateChecker.softUpdateNotice },
set: { newValue in
if newValue == nil {
updateChecker.dismissSoftUpdateIfNeeded()
}
}
)) { notice in
Alert(
title: Text(notice.title),
message: Text(notice.message),
primaryButton: .default(Text(NSLocalizedString("Обновить", comment: ""))) {
updateChecker.openAppStore()
},
secondaryButton: .cancel(Text(NSLocalizedString("Позже", comment: ""))) {
updateChecker.dismissSoftUpdateIfNeeded()
}
)
}
} }
} }
.environmentObject(messageCenter) .environmentObject(messageCenter)
@ -71,34 +100,6 @@ struct yobbleApp: App {
.onChange(of: viewModel.userId) { newValue in .onChange(of: viewModel.userId) { newValue in
messageCenter.currentUserId = newValue.isEmpty ? nil : newValue messageCenter.currentUserId = newValue.isEmpty ? nil : newValue
} }
.alert(item: Binding(
get: { updateChecker.softUpdateNotice },
set: { newValue in
if newValue == nil {
updateChecker.dismissSoftUpdateIfNeeded()
}
}
)) { notice in
Alert(
title: Text(notice.title),
message: Text(notice.message),
primaryButton: .default(Text(NSLocalizedString("Обновить", comment: ""))) {
updateChecker.openAppStore()
},
secondaryButton: .cancel(Text(NSLocalizedString("Позже", comment: ""))) {
updateChecker.dismissSoftUpdateIfNeeded()
}
)
}
.overlay(alignment: .center) {
if let notice = updateChecker.needUpdateNotice {
ForceUpdateView(
title: notice.title,
message: notice.message,
onUpdate: { updateChecker.openAppStore() }
)
}
}
} }
} }
} }