From d0536b7799bcc1282607bdf54714043b96163fce Mon Sep 17 00:00:00 2001 From: spencerwooo Date: Thu, 11 Aug 2022 15:17:18 +0800 Subject: [PATCH] update at day change, close #16 --- PaimonMenuBar.xcodeproj/project.pbxproj | 4 ++-- PaimonMenuBar/GameRecordUpdater.swift | 12 ++++++++++++ PaimonMenuBar/SettingsView.swift | 2 +- PaimonMenuBar/zh-Hans.lproj/Localizable.strings | 4 ++-- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/PaimonMenuBar.xcodeproj/project.pbxproj b/PaimonMenuBar.xcodeproj/project.pbxproj index ba06f0a..5cc0f59 100644 --- a/PaimonMenuBar.xcodeproj/project.pbxproj +++ b/PaimonMenuBar.xcodeproj/project.pbxproj @@ -365,7 +365,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 121; + CURRENT_PROJECT_VERSION = 122; DEVELOPMENT_ASSET_PATHS = "\"PaimonMenuBar/Preview Content\""; DEVELOPMENT_TEAM = W2HGAU9MPP; ENABLE_HARDENED_RUNTIME = YES; @@ -397,7 +397,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 121; + CURRENT_PROJECT_VERSION = 122; DEVELOPMENT_ASSET_PATHS = "\"PaimonMenuBar/Preview Content\""; DEVELOPMENT_TEAM = W2HGAU9MPP; ENABLE_HARDENED_RUNTIME = YES; diff --git a/PaimonMenuBar/GameRecordUpdater.swift b/PaimonMenuBar/GameRecordUpdater.swift index 895a152..401a877 100644 --- a/PaimonMenuBar/GameRecordUpdater.swift +++ b/PaimonMenuBar/GameRecordUpdater.swift @@ -100,6 +100,17 @@ class GameRecordUpdater { } } + // MARK: - Record update at midnight to avoid today or tomorrow conflicts + + private func setupDayChangeUpdater() { + assert(Thread.isMainThread) + + NotificationCenter.default.addObserver(forName: .NSCalendarDayChanged, object: nil, queue: .main) { _ in + print("Day change (midnight) update is triggered") + self.tryFetchGameRecordAndRender() + } + } + // MARK: - Notification handler private func sendLocalNotification(context: LocalizedStringKey, completion: @escaping () -> Void) { @@ -132,6 +143,7 @@ class GameRecordUpdater { init() { startNetworkActivityUpdater() resetUpdateTimer() + setupDayChangeUpdater() Defaults.observe(.recordUpdateInterval) { _ in self.onRecordUpdateIntervalChanged() diff --git a/PaimonMenuBar/SettingsView.swift b/PaimonMenuBar/SettingsView.swift index d3398a5..84aa37b 100644 --- a/PaimonMenuBar/SettingsView.swift +++ b/PaimonMenuBar/SettingsView.swift @@ -116,7 +116,7 @@ struct ConfigurationSettingsView: View { var body: some View { VStack { - Text("Personal information") + Text("User") .font(.headline) .frame(maxWidth: .infinity, alignment: .leading) Form { diff --git a/PaimonMenuBar/zh-Hans.lproj/Localizable.strings b/PaimonMenuBar/zh-Hans.lproj/Localizable.strings index 464d7c3..f2626a5 100644 --- a/PaimonMenuBar/zh-Hans.lproj/Localizable.strings +++ b/PaimonMenuBar/zh-Hans.lproj/Localizable.strings @@ -26,7 +26,7 @@ "Paste your cookie from:" = "从这里粘贴你的 Cookie:"; -"Personal information" = "个人信息"; +"User" = "个人信息"; "Preferences" = "偏好设置"; @@ -112,4 +112,4 @@ "⚠️ Notification unauthorized." = "⚠️ 没有推送通知权限。"; -"This cookie is only stored locally." = "Cookie 仅保存于本地。"; +"This cookie is only stored locally." = "Cookie 仅保存于本地";