From 4442dfc82120bc5c8c44e70a6dcc1765f1fbbbeb Mon Sep 17 00:00:00 2001 From: cheykrym Date: Thu, 18 Dec 2025 07:39:41 +0300 Subject: [PATCH] fix --- yobble/ViewModels/LoginViewModel.swift | 5 +- yobble/Views/ForceUpdateView.swift | 50 ---------- yobble/Views/NeedUpdateView.swift | 62 ++++++++++++ yobble/yobbleApp.swift | 125 +++++++++++++------------ 4 files changed, 127 insertions(+), 115 deletions(-) delete mode 100644 yobble/Views/ForceUpdateView.swift create mode 100644 yobble/Views/NeedUpdateView.swift diff --git a/yobble/ViewModels/LoginViewModel.swift b/yobble/ViewModels/LoginViewModel.swift index 7316f27..e2b3c12 100644 --- a/yobble/ViewModels/LoginViewModel.swift +++ b/yobble/ViewModels/LoginViewModel.swift @@ -10,7 +10,7 @@ import Combine import SwiftUI class LoginViewModel: ObservableObject { - @AppStorage("appIsBlocked") private var isAppBlocked: Bool = false +// @AppStorage("appIsBlocked") private var isAppBlocked: Bool = false @Published var username: String = "" @Published var userId: String = "" @@ -137,8 +137,7 @@ class LoginViewModel: ObservableObject { self?.socketService.disconnect() } self?.isLoading = false - if self?.isAppBlocked == false{ - self?.isInitialLoading = false} + self?.isInitialLoading = false } } } diff --git a/yobble/Views/ForceUpdateView.swift b/yobble/Views/ForceUpdateView.swift deleted file mode 100644 index 1cbe4e0..0000000 --- a/yobble/Views/ForceUpdateView.swift +++ /dev/null @@ -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: {}) - } -} diff --git a/yobble/Views/NeedUpdateView.swift b/yobble/Views/NeedUpdateView.swift new file mode 100644 index 0000000..7c64b39 --- /dev/null +++ b/yobble/Views/NeedUpdateView.swift @@ -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: {}) + } +} diff --git a/yobble/yobbleApp.swift b/yobble/yobbleApp.swift index 00c7d49..3eba1a0 100644 --- a/yobble/yobbleApp.swift +++ b/yobble/yobbleApp.swift @@ -21,43 +21,72 @@ struct yobbleApp: App { var body: some Scene { WindowGroup { - ZStack(alignment: .top) { - Group { - if viewModel.isInitialLoading { - SplashScreenView() - } else if viewModel.isLoggedIn { - MainView(viewModel: viewModel) - } else { - LoginView(viewModel: viewModel) - } - } - - if let banner = messageCenter.banner { - NewMessageBannerView( - banner: banner, - onOpen: { messageCenter.openCurrentChat() }, - onDismiss: { messageCenter.dismissBanner() } + Group { + if let notice = updateChecker.needUpdateNotice { + NeedUpdateView( + title: notice.title, + message: notice.message, + onUpdate: { updateChecker.openAppStore() } ) - .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 - } + } else { + ZStack(alignment: .top) { + Group { + if viewModel.isInitialLoading { + SplashScreenView() + } else if viewModel.isLoggedIn { + MainView(viewModel: viewModel) + } else { + LoginView(viewModel: viewModel) } } + + 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) @@ -71,34 +100,6 @@ struct yobbleApp: App { .onChange(of: viewModel.userId) { newValue in 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() } - ) - } - } } } }