From 4c090d4295e3527bc5ea5572aebbba746f1ebe30 Mon Sep 17 00:00:00 2001 From: Lain Iwakura Date: Thu, 7 Aug 2025 22:43:06 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=82=20=D0=B2=D0=BE=D1=80?= =?UTF-8?q?=D0=BA=D0=B8=D0=BD=D0=B3=20=D0=B1=D0=B8=D0=BB=D0=B4=20=D1=81=20?= =?UTF-8?q?=D0=BD=D0=B5=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=BC=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=B0=D1=82=D1=87=D0=B0=D0=BC=D0=B8=20=D0=B8=D0=B1=D0=BE?= =?UTF-8?q?=20=D0=BC=D0=BE=D0=B3=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MobileMkch/APIClient.swift | 12 +++++++++++- MobileMkch/BackgroundTaskManager.swift | 7 +++++-- MobileMkch/BoardsView.swift | 3 +++ MobileMkch/Models.swift | 13 +++++++------ MobileMkch/ThreadDetailView.swift | 3 +++ MobileMkch/ThreadsView.swift | 3 +++ 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/MobileMkch/APIClient.swift b/MobileMkch/APIClient.swift index 5adea03..baeedb7 100644 --- a/MobileMkch/APIClient.swift +++ b/MobileMkch/APIClient.swift @@ -3,7 +3,17 @@ import Foundation class APIClient: ObservableObject { private let baseURL = "https://mkch.pooziqo.xyz" private let apiURL = "https://mkch.pooziqo.xyz/api" - private let session = URLSession.shared + private lazy var session: URLSession = { + let config = URLSessionConfiguration.default + config.timeoutIntervalForRequest = 20 + config.timeoutIntervalForResource = 40 + config.httpAdditionalHeaders = [ + "Accept": "application/json", + "Accept-Language": Locale.preferredLanguages.first ?? "ru-RU", + "User-Agent": self.userAgent + ] + return URLSession(configuration: config) + }() private var authKey: String = "" private var passcode: String = "" private let userAgent = "MobileMkch/2.1.0-ios-alpha" diff --git a/MobileMkch/BackgroundTaskManager.swift b/MobileMkch/BackgroundTaskManager.swift index f09835e..da9058d 100644 --- a/MobileMkch/BackgroundTaskManager.swift +++ b/MobileMkch/BackgroundTaskManager.swift @@ -6,9 +6,12 @@ class BackgroundTaskManager { static let shared = BackgroundTaskManager() private var backgroundTaskIdentifier: String { - if let savedIdentifier = UserDefaults.standard.string(forKey: "BackgroundTaskIdentifier") { - return savedIdentifier + // Используем идентификатор из Info.plist (BGTaskSchedulerPermittedIdentifiers) + if let identifiers = Bundle.main.object(forInfoDictionaryKey: "BGTaskSchedulerPermittedIdentifiers") as? [String], + let first = identifiers.first { + return first } + // Фоллбек на значение по умолчанию return "com.mkch.MobileMkch.backgroundrefresh" } private let notificationManager = NotificationManager.shared diff --git a/MobileMkch/BoardsView.swift b/MobileMkch/BoardsView.swift index 156b8b5..49f0349 100644 --- a/MobileMkch/BoardsView.swift +++ b/MobileMkch/BoardsView.swift @@ -44,6 +44,9 @@ struct BoardsView: View { } .navigationTitle("Доски mkch") .navigationBarTitleDisplayMode(.large) + .refreshable { + loadBoards() + } .onAppear { if boards.isEmpty { loadBoards() diff --git a/MobileMkch/Models.swift b/MobileMkch/Models.swift index 00f749c..947d393 100644 --- a/MobileMkch/Models.swift +++ b/MobileMkch/Models.swift @@ -1,5 +1,9 @@ import Foundation +private enum DateFormatterCache { + static let iso8601 = ISO8601DateFormatter() +} + struct Board: Codable, Identifiable { let code: String let description: String @@ -18,8 +22,7 @@ struct Thread: Codable, Identifiable { let files: [String] var creationDate: Date { - let formatter = ISO8601DateFormatter() - return formatter.date(from: creation) ?? Date() + return DateFormatterCache.iso8601.date(from: creation) ?? Date() } var ratingValue: Int { @@ -40,8 +43,7 @@ struct ThreadDetail: Codable, Identifiable { let files: [String] var creationDate: Date { - let formatter = ISO8601DateFormatter() - return formatter.date(from: creation) ?? Date() + return DateFormatterCache.iso8601.date(from: creation) ?? Date() } } @@ -52,8 +54,7 @@ struct Comment: Codable, Identifiable { let files: [String] var creationDate: Date { - let formatter = ISO8601DateFormatter() - return formatter.date(from: creation) ?? Date() + return DateFormatterCache.iso8601.date(from: creation) ?? Date() } var formattedText: String { diff --git a/MobileMkch/ThreadDetailView.swift b/MobileMkch/ThreadDetailView.swift index 156bad0..3a7f9cb 100644 --- a/MobileMkch/ThreadDetailView.swift +++ b/MobileMkch/ThreadDetailView.swift @@ -71,6 +71,9 @@ struct ThreadDetailView: View { } .padding() } + .refreshable { + loadThreadDetail() + } .navigationTitle("#\(thread.id)") .navigationBarTitleDisplayMode(.inline) .toolbar { diff --git a/MobileMkch/ThreadsView.swift b/MobileMkch/ThreadsView.swift index 096de8c..963a528 100644 --- a/MobileMkch/ThreadsView.swift +++ b/MobileMkch/ThreadsView.swift @@ -53,6 +53,9 @@ struct ThreadsView: View { } } } + .refreshable { + loadThreads() + } if settings.enablePagination && totalPages > 1 { HStack {