cc-pets 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CC_BRIDGE.md +5 -2
- package/CC_BRIDGE.zh-CN.md +4 -2
- package/CHANGELOG.md +85 -0
- package/CHANGELOG.zh-CN.md +85 -0
- package/CONTRIBUTING.md +28 -11
- package/CONTRIBUTING.zh-CN.md +23 -11
- package/README.md +127 -27
- package/README.zh-CN.md +104 -30
- package/Resources/zh-Hans.lproj/Localizable.strings +573 -17
- package/Sources/CCPets/{CCPetsAppDelegate+AgentEvents.m → App/CCPetsAppDelegate+AgentEvents.m} +15 -5
- package/Sources/CCPets/{CCPetsAppDelegate+AgentStatus.m → App/CCPetsAppDelegate+AgentStatus.m} +89 -31
- package/Sources/CCPets/{CCPetsAppDelegate+Bridge.m → App/CCPetsAppDelegate+Bridge.m} +35 -24
- package/Sources/CCPets/{CCPetsAppDelegate+Pets.m → App/CCPetsAppDelegate+Pets.m} +18 -4
- package/Sources/CCPets/{CCPetsAppDelegate+Private.h → App/CCPetsAppDelegate+Private.h} +90 -21
- package/Sources/CCPets/App/CCPetsAppDelegate+Profiles.m +238 -0
- package/Sources/CCPets/{CCPetsAppDelegate+Quota.m → App/CCPetsAppDelegate+Quota.m} +47 -32
- package/Sources/CCPets/App/CCPetsAppDelegate+Settings.m +269 -0
- package/Sources/CCPets/{CCPetsAppDelegate+Speech.m → App/CCPetsAppDelegate+Speech.m} +13 -7
- package/Sources/CCPets/{CCPetsAppDelegate+Update.m → App/CCPetsAppDelegate+Update.m} +71 -47
- package/Sources/CCPets/App/CCPetsAppDelegate+Workbench.m +139 -0
- package/Sources/CCPets/{CCPetsAppDelegate.h → App/CCPetsAppDelegate.h} +16 -2
- package/Sources/CCPets/{CCPetsAppDelegate.m → App/CCPetsAppDelegate.m} +110 -12
- package/Sources/CCPets/App/CCPetsOpenCommand.h +13 -0
- package/Sources/CCPets/App/CCPetsOpenCommand.m +99 -0
- package/Sources/CCPets/{main.m → App/main.m} +68 -1
- package/Sources/CCPets/{CCPetsBridge.h → Bridge/CCPetsBridge.h} +17 -4
- package/Sources/CCPets/{CCPetsBridge.m → Bridge/CCPetsBridge.m} +32 -17
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.h +10 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCLI.m +792 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.h +60 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeCore.m +558 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.h +24 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeSetup.m +501 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.h +103 -0
- package/Sources/CCPets/Bridge/CCPetsBridgeStore.m +779 -0
- package/Sources/CCPets/Integrations/CCPetsCLISupport.h +75 -0
- package/Sources/CCPets/Integrations/CCPetsCLISupport.m +342 -0
- package/Sources/CCPets/Integrations/CCPetsEvents.h +15 -0
- package/Sources/CCPets/{CCPetsEvents.m → Integrations/CCPetsEvents.m} +23 -0
- package/Sources/CCPets/Integrations/CCPetsIntegrations.h +51 -0
- package/Sources/CCPets/Integrations/CCPetsIntegrations.m +662 -0
- package/Sources/CCPets/Integrations/CCPetsProfiles.h +38 -0
- package/Sources/CCPets/Integrations/CCPetsProfiles.m +516 -0
- package/Sources/CCPets/{CCPetsTerminalFocus.m → Integrations/CCPetsTerminalFocus.m} +42 -12
- package/Sources/CCPets/Pet/CCPetsImageLoader.h +5 -0
- package/Sources/CCPets/{CCPetsImageLoader.m → Pet/CCPetsImageLoader.m} +10 -2
- package/Sources/CCPets/Pet/CCPetsPetSize.h +10 -0
- package/Sources/CCPets/Pet/CCPetsPetSize.m +21 -0
- package/Sources/CCPets/Pet/CCPetsPetStore.h +12 -0
- package/Sources/CCPets/Pet/CCPetsPetStore.m +476 -0
- package/Sources/CCPets/{CCPetsPhrases.h → Pet/CCPetsPhrases.h} +18 -2
- package/Sources/CCPets/{CCPetsPhrases.m → Pet/CCPetsPhrases.m} +53 -22
- package/Sources/CCPets/{CCPetsPhrasesEditor.m → Pet/CCPetsPhrasesEditor.m} +42 -2
- package/Sources/CCPets/Pet/PetView+Interaction.m +207 -0
- package/Sources/CCPets/Pet/PetView+Menu.m +598 -0
- package/Sources/CCPets/Pet/PetView+MicroBehavior.m +234 -0
- package/Sources/CCPets/Pet/PetView+Private.h +81 -0
- package/Sources/CCPets/{PetView.h → Pet/PetView.h} +3 -5
- package/Sources/CCPets/Pet/PetView.m +635 -0
- package/Sources/CCPets/Support/CCPetsDoctor.h +25 -0
- package/Sources/CCPets/Support/CCPetsDoctor.m +632 -0
- package/Sources/CCPets/Support/CCPetsJSON.h +27 -0
- package/Sources/CCPets/Support/CCPetsJSON.m +397 -0
- package/Sources/CCPets/{CCPetsL10n.h → Support/CCPetsL10n.h} +3 -1
- package/Sources/CCPets/{CCPetsL10n.m → Support/CCPetsL10n.m} +30 -1
- package/Sources/CCPets/Support/CCPetsPreferences.h +31 -0
- package/Sources/CCPets/Support/CCPetsPreferences.m +85 -0
- package/Sources/CCPets/UI/CCPetsDiagnosticsPage.h +25 -0
- package/Sources/CCPets/UI/CCPetsDiagnosticsPage.m +440 -0
- package/Sources/CCPets/UI/CCPetsFormBuilder.h +42 -0
- package/Sources/CCPets/UI/CCPetsFormBuilder.m +268 -0
- package/Sources/CCPets/{CCPetsGlassView.h → UI/CCPetsGlassView.h} +5 -1
- package/Sources/CCPets/{CCPetsGlassView.m → UI/CCPetsGlassView.m} +25 -7
- package/Sources/CCPets/UI/CCPetsMainWindow.h +55 -0
- package/Sources/CCPets/UI/CCPetsMainWindow.m +730 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.h +62 -0
- package/Sources/CCPets/UI/CCPetsSettingsPage.m +917 -0
- package/Sources/CCPets/UI/CCPetsUIStyle.h +132 -0
- package/Sources/CCPets/UI/CCPetsUIStyle.m +816 -0
- package/Sources/CCPets/UI/CCPetsUsageChartView.h +15 -0
- package/Sources/CCPets/UI/CCPetsUsageChartView.m +284 -0
- package/Sources/CCPets/UI/CCPetsUsagePage.h +32 -0
- package/Sources/CCPets/UI/CCPetsUsagePage.m +717 -0
- package/Sources/CCPets/UI/CCPetsUsageShared.h +53 -0
- package/Sources/CCPets/UI/CCPetsUsageStore.m +120 -0
- package/Sources/CCPets/UI/CCPetsUsageWidgets.h +30 -0
- package/Sources/CCPets/UI/CCPetsUsageWidgets.m +201 -0
- package/Sources/CCPets/UI/CCPetsWorkbench.h +40 -0
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.h +13 -0
- package/Sources/CCPets/UI/CCPetsWorkbenchPages.m +783 -0
- package/Sources/CCPets/{MenuChoiceRow.m → UI/MenuChoiceRow.m} +3 -0
- package/Sources/CCPets/UI/MenuPetSizeView.h +5 -0
- package/Sources/CCPets/UI/MenuPetSizeView.m +73 -0
- package/Sources/CCPets/{MenuToggleSwitch.m → UI/MenuToggleSwitch.m} +1 -0
- package/Sources/CCPets/{CCPetsCodexRateLimits.h → Usage/CCPetsCodexRateLimits.h} +1 -0
- package/Sources/CCPets/{CCPetsCodexRateLimits.m → Usage/CCPetsCodexRateLimits.m} +10 -3
- package/Sources/CCPets/{CCPetsQuotaHistory.h → Usage/CCPetsQuotaHistory.h} +3 -0
- package/Sources/CCPets/{CCPetsQuotaHistory.m → Usage/CCPetsQuotaHistory.m} +58 -0
- package/Sources/CCPets/Usage/CCPetsUsage+ClaudeReader.m +436 -0
- package/Sources/CCPets/Usage/CCPetsUsage+CodexReader.m +392 -0
- package/Sources/CCPets/Usage/CCPetsUsage+CodexSessions.m +484 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Internal.h +96 -0
- package/Sources/CCPets/Usage/CCPetsUsage+Models.m +285 -0
- package/Sources/CCPets/Usage/CCPetsUsage+TokenTotals.m +655 -0
- package/Sources/CCPets/Usage/CCPetsUsage.h +57 -0
- package/Sources/CCPets/Usage/CCPetsUsage.m +225 -0
- package/Sources/CCPets/Usage/CCPetsUsageMode.h +10 -0
- package/Sources/CCPets/Usage/CCPetsUsageMode.m +163 -0
- package/Sources/CCPets/{CCPetsUsageMonitor.h → Usage/CCPetsUsageMonitor.h} +3 -0
- package/Sources/CCPets/{CCPetsUsageMonitor.m → Usage/CCPetsUsageMonitor.m} +163 -6
- package/Sources/CCPets/Usage/QuotaDashboardView+Primitives.m +328 -0
- package/Sources/CCPets/Usage/QuotaDashboardView+Private.h +103 -0
- package/Sources/CCPets/Usage/QuotaDashboardView+Rendering.m +616 -0
- package/Sources/CCPets/{QuotaDashboardView.h → Usage/QuotaDashboardView.h} +17 -0
- package/Sources/CCPets/Usage/QuotaDashboardView.m +587 -0
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/THIRD_PARTY_NOTICES.zh-CN.md +1 -1
- package/bin/cc-pets +8 -6
- package/bin/claude-with-pet +10 -2
- package/bin/codex-with-pet +13 -5
- package/package.json +1 -1
- package/scripts/build.sh +7 -3
- package/scripts/i18n.zsh +9 -52
- package/scripts/install-app.sh +4 -0
- package/scripts/install-shell-integration.sh +17 -10
- package/scripts/uninstall-shell-integration.sh +6 -1
- package/Sources/CCPets/CCPetsAppDelegate+Settings.m +0 -226
- package/Sources/CCPets/CCPetsEvents.h +0 -10
- package/Sources/CCPets/CCPetsImageLoader.h +0 -4
- package/Sources/CCPets/CCPetsUsage.h +0 -36
- package/Sources/CCPets/CCPetsUsage.m +0 -2069
- package/Sources/CCPets/PetView.m +0 -1806
- package/Sources/CCPets/QuotaDashboardView.m +0 -1145
- package/scripts/bridge/cli.mjs +0 -237
- package/scripts/bridge/core.mjs +0 -228
- package/scripts/bridge/hook.mjs +0 -150
- package/scripts/bridge/install.mjs +0 -311
- package/scripts/bridge/mcp-server.mjs +0 -308
- package/scripts/bridge/options.mjs +0 -87
- package/scripts/bridge/process.mjs +0 -151
- package/scripts/bridge/reservations.mjs +0 -248
- package/scripts/bridge/store.mjs +0 -433
- package/scripts/bridge/watch.mjs +0 -69
- package/scripts/check-l10n.mjs +0 -168
- package/scripts/configure-updater.mjs +0 -43
- package/scripts/detect-cli.mjs +0 -68
- package/scripts/doctor.mjs +0 -470
- package/scripts/i18n.mjs +0 -122
- package/scripts/install-claude-hooks.mjs +0 -253
- package/scripts/install-codex-hooks.mjs +0 -78
- package/scripts/integration-markers.mjs +0 -51
- package/scripts/locales/zh-Hans.json +0 -366
- package/scripts/pet-store.mjs +0 -415
- package/scripts/uninstall-integrations.mjs +0 -205
- /package/Sources/CCPets/{CCPetsVersion.h → App/CCPetsVersion.h} +0 -0
- /package/Sources/CCPets/{CCPetsVersion.m → App/CCPetsVersion.m} +0 -0
- /package/Sources/CCPets/{CCPetsTerminalFocus.h → Integrations/CCPetsTerminalFocus.h} +0 -0
- /package/Sources/CCPets/{CCPetsPhrasesEditor.h → Pet/CCPetsPhrasesEditor.h} +0 -0
- /package/Sources/CCPets/{CCPetsPreviews.h → Pet/CCPetsPreviews.h} +0 -0
- /package/Sources/CCPets/{CCPetsPreviews.m → Pet/CCPetsPreviews.m} +0 -0
- /package/Sources/CCPets/Resources/{/351/273/230/350/256/244.webp" → ByteMochi.webp} +0 -0
- /package/Sources/CCPets/{CCPetsCleanup.h → Support/CCPetsCleanup.h} +0 -0
- /package/Sources/CCPets/{CCPetsCleanup.m → Support/CCPetsCleanup.m} +0 -0
- /package/Sources/CCPets/{CCPetsPaths.h → Support/CCPetsPaths.h} +0 -0
- /package/Sources/CCPets/{CCPetsPaths.m → Support/CCPetsPaths.m} +0 -0
- /package/Sources/CCPets/{CCPetsSystemMonitor.h → Support/CCPetsSystemMonitor.h} +0 -0
- /package/Sources/CCPets/{CCPetsSystemMonitor.m → Support/CCPetsSystemMonitor.m} +0 -0
- /package/Sources/CCPets/{CCPetsGlassMenu.h → UI/CCPetsGlassMenu.h} +0 -0
- /package/Sources/CCPets/{CCPetsGlassMenu.m → UI/CCPetsGlassMenu.m} +0 -0
- /package/Sources/CCPets/{MenuChoiceRow.h → UI/MenuChoiceRow.h} +0 -0
- /package/Sources/CCPets/{MenuHintView.h → UI/MenuHintView.h} +0 -0
- /package/Sources/CCPets/{MenuHintView.m → UI/MenuHintView.m} +0 -0
- /package/Sources/CCPets/{MenuToggleSwitch.h → UI/MenuToggleSwitch.h} +0 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
// 右键菜单里的各项设置开关。
|
|
2
|
+
//
|
|
3
|
+
// 每项分两层:菜单控件的 action(setXxx: / toggleXxx:)只从 sender 上取值、回写勾选状态;
|
|
4
|
+
// 真正写设置并让界面生效的是 updateXxx:,不认识任何菜单控件,主窗口设置页直接调它。
|
|
5
|
+
// 写 defaults 一律经过 CCPetsPreferences,两边才拿得到同一套钳制和变更广播。
|
|
6
|
+
#import "CCPetsAppDelegate+Private.h"
|
|
7
|
+
#import "CCPetsUsageMode.h"
|
|
8
|
+
#import "CCPetsWorkbench.h"
|
|
9
|
+
|
|
10
|
+
@implementation AppDelegate (Settings)
|
|
11
|
+
- (void)setPetSizeFromSlider:(NSSlider *)sender {
|
|
12
|
+
[self updatePetScale:sender.doubleValue];
|
|
13
|
+
sender.doubleValue = CCPetsPetScalePreference();
|
|
14
|
+
}
|
|
15
|
+
- (void)updatePetScale:(double)scale {
|
|
16
|
+
if (!CCPetsPrefSetObject(CCPetsPetScaleKey, @(scale))) return;
|
|
17
|
+
[self applyPetSizePreference];
|
|
18
|
+
}
|
|
19
|
+
- (void)applyPetSizePreference {
|
|
20
|
+
if (!self.petView || !self.panel) return;
|
|
21
|
+
CGFloat scale = CCPetsPetScalePreference();
|
|
22
|
+
NSRect oldPet = [self.panel convertRectToScreen:self.petView.frame];
|
|
23
|
+
NSSize petSize = NSMakeSize(140 * scale + 4, 150 * scale);
|
|
24
|
+
NSSize panelSize = NSMakeSize(MAX(230, petSize.width + 86), petSize.height + 20);
|
|
25
|
+
// 脚底中心的屏幕坐标保持不变;透明余量继续留给拖动滞后和呼吸动画。
|
|
26
|
+
NSRect panelFrame = NSMakeRect(NSMidX(oldPet) - panelSize.width / 2,
|
|
27
|
+
NSMinY(oldPet), panelSize.width, panelSize.height);
|
|
28
|
+
[self.panel setFrame:panelFrame display:NO];
|
|
29
|
+
self.petView.frame = NSMakeRect((panelSize.width - petSize.width) / 2,
|
|
30
|
+
0, petSize.width, petSize.height);
|
|
31
|
+
[self.petView displayIfNeeded];
|
|
32
|
+
[self.updateBadgeView setFrameOrigin:NSMakePoint(NSMaxX(self.petView.frame) - 30,
|
|
33
|
+
NSMaxY(self.petView.frame) - 28)];
|
|
34
|
+
// 只更新已创建的气泡;独立消息气泡仍在首次播报时按需创建。
|
|
35
|
+
[self resizeStatusCardToFitText];
|
|
36
|
+
[self resizeSpeechBubbleToFitText];
|
|
37
|
+
[self.statusPanel.contentView displayIfNeeded];
|
|
38
|
+
[self.speechPanel.contentView displayIfNeeded];
|
|
39
|
+
[self petWindowDidMove:nil];
|
|
40
|
+
}
|
|
41
|
+
- (void)applySystemMetricPreferences {
|
|
42
|
+
NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
|
|
43
|
+
self.quotaView.systemCPUEnabled = [defaults boolForKey:SystemCPUEnabledKey];
|
|
44
|
+
self.quotaView.systemTemperatureEnabled =
|
|
45
|
+
[defaults boolForKey:SystemTemperatureEnabledKey];
|
|
46
|
+
self.quotaView.systemMemoryEnabled = [defaults boolForKey:SystemMemoryEnabledKey];
|
|
47
|
+
self.quotaView.needsDisplay = YES;
|
|
48
|
+
}
|
|
49
|
+
- (void)applyUsageDisplayModePreferences {
|
|
50
|
+
NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
|
|
51
|
+
self.quotaView.codexShowsAPIUsage =
|
|
52
|
+
[[defaults stringForKey:CodexUsageDisplayModeKey] isEqualToString:@"api"];
|
|
53
|
+
self.quotaView.claudeShowsAPIUsage =
|
|
54
|
+
[[defaults stringForKey:ClaudeUsageDisplayModeKey] isEqualToString:@"api"];
|
|
55
|
+
self.quotaView.needsDisplay = YES;
|
|
56
|
+
}
|
|
57
|
+
- (void)setUsageDisplayModeFromControl:(NSButton *)sender {
|
|
58
|
+
if (sender.identifier.length > 0) {
|
|
59
|
+
NSDictionary *profile = CCPetsProfileWithID(sender.identifier);
|
|
60
|
+
if (!profile) { sender.enabled = NO; return; }
|
|
61
|
+
[self updateUsageDisplayMode:CCPetsProfileShowsAPIUsage(profile) ? @"subscription" : @"api"
|
|
62
|
+
forProfileID:sender.identifier];
|
|
63
|
+
sender.state = CCPetsProfileShowsAPIUsage(profile) ? NSControlStateValueOn : NSControlStateValueOff;
|
|
64
|
+
sender.enabled = CCPetsProfileCanSwitchUsageMode(profile);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
NSString *key = sender.tag == 1 ? CodexUsageDisplayModeKey
|
|
68
|
+
: (sender.tag == 2 ? ClaudeUsageDisplayModeKey : nil);
|
|
69
|
+
NSString *mode = sender.state == NSControlStateValueOn ? @"api" : @"subscription";
|
|
70
|
+
if (!key) return;
|
|
71
|
+
[self updateUsageDisplayMode:mode forKey:key];
|
|
72
|
+
}
|
|
73
|
+
- (void)updateUsageDisplayMode:(NSString *)mode forKey:(NSString *)key {
|
|
74
|
+
if (![@[CodexUsageDisplayModeKey, ClaudeUsageDisplayModeKey] containsObject:key] ||
|
|
75
|
+
![@[@"api", @"subscription"] containsObject:mode]) return;
|
|
76
|
+
CCPetsPrefSetObject(key, mode);
|
|
77
|
+
[self applyUsageDisplayModePreferences];
|
|
78
|
+
// 展示模式决定了会话要回溯多远(订阅 8 天 / API 到上月月初),切换之后必须重新聚合,
|
|
79
|
+
// 否则刚打开 API 视图时手里只有一段按 8 天窗口扫出来的数据。
|
|
80
|
+
[self refreshUsage:nil];
|
|
81
|
+
[NSNotificationCenter.defaultCenter postNotificationName:CCPetsWorkbenchQuotasDidChangeNotification object:nil];
|
|
82
|
+
}
|
|
83
|
+
- (void)updateUsageDisplayMode:(NSString *)mode forProfileID:(NSString *)profileID {
|
|
84
|
+
NSDictionary *profile = CCPetsProfileWithID(profileID);
|
|
85
|
+
if (!profile || !CCPetsProfileCanSwitchUsageMode(profile) ||
|
|
86
|
+
![@[@"api", @"subscription"] containsObject:mode]) return;
|
|
87
|
+
CCPetsPrefSetObject(CCPetsUsageModePreferenceKey(profile), mode);
|
|
88
|
+
self.quotaView.needsDisplay = YES;
|
|
89
|
+
[self refreshUsage:nil];
|
|
90
|
+
[NSNotificationCenter.defaultCenter postNotificationName:CCPetsWorkbenchQuotasDidChangeNotification object:nil];
|
|
91
|
+
}
|
|
92
|
+
- (void)updateSystemMetric:(NSString *)key enabled:(BOOL)enabled {
|
|
93
|
+
if (![@[SystemCPUEnabledKey, SystemTemperatureEnabledKey, SystemMemoryEnabledKey]
|
|
94
|
+
containsObject:key]) return;
|
|
95
|
+
CCPetsPrefSetBool(key, enabled);
|
|
96
|
+
[self applySystemMetricPreferences];
|
|
97
|
+
[self updateSystemMetricsTimer];
|
|
98
|
+
}
|
|
99
|
+
// 开关打开时立刻导入一次,不用等下次启动——用户点开关就是想现在看到那些素材。
|
|
100
|
+
- (void)updateImportCodexPets:(BOOL)enabled {
|
|
101
|
+
CCPetsPrefSetBool(ImportCodexPetsKey, enabled);
|
|
102
|
+
if (!enabled) return;
|
|
103
|
+
NSUInteger imported = ImportCodexPets();
|
|
104
|
+
if (imported == 0) return;
|
|
105
|
+
[self invalidatePetOptionsCache];
|
|
106
|
+
[self showImportedCodexPetsAlert:imported];
|
|
107
|
+
}
|
|
108
|
+
- (void)showImportedCodexPetsAlert:(NSUInteger)imported {
|
|
109
|
+
[NSApp activateIgnoringOtherApps:YES];
|
|
110
|
+
NSAlert *alert = [NSAlert new];
|
|
111
|
+
alert.messageText = L(@"Codex Pets Imported");
|
|
112
|
+
[alert addButtonWithTitle:L(@"OK")];
|
|
113
|
+
[alert runModal];
|
|
114
|
+
}
|
|
115
|
+
// sender 是菜单里的 MenuChoiceRowView,勾选状态由它自己更新。
|
|
116
|
+
- (void)setPanelTheme:(MenuChoiceRowView *)sender {
|
|
117
|
+
[self updatePanelTheme:sender.representedObject];
|
|
118
|
+
}
|
|
119
|
+
- (void)updatePanelTheme:(NSString *)theme {
|
|
120
|
+
if (![@[@"classic", @"liquid"] containsObject:theme]) return;
|
|
121
|
+
CCPetsPrefSetObject(CCPetsPanelThemeKey, theme);
|
|
122
|
+
[self.statusGlass applyTheme];
|
|
123
|
+
[self.speechGlass applyTheme];
|
|
124
|
+
[self.quotaGlass applyTheme];
|
|
125
|
+
[self.updateBadgeGlass applyTheme];
|
|
126
|
+
self.statusShadowView.hidden = self.statusGlass.usesLiquidGlass;
|
|
127
|
+
self.quotaView.usesLiquidGlass = self.quotaGlass.usesLiquidGlass;
|
|
128
|
+
self.quotaView.cardScrimAlpha = CCPetsGlassCardScrimAlpha();
|
|
129
|
+
self.quotaView.needsDisplay = YES;
|
|
130
|
+
[self applyBubbleTextStyle];
|
|
131
|
+
// quotaView 换了父视图,mouseExited 不一定会送达;切主题是在宠物右键菜单里点的,
|
|
132
|
+
// 鼠标此刻不在面板上,直接复位,免得面板一直当作"悬停中"不收起。
|
|
133
|
+
self.dashboardHovering = NO;
|
|
134
|
+
}
|
|
135
|
+
// 状态卡和说话气泡原来是浅色磨砂配深色字;换成原生清透玻璃后背景是任意壁纸加一层
|
|
136
|
+
// 压暗,深色字会看不见,改成白字加贴字形的投影,和额度面板一致。
|
|
137
|
+
- (void)applyBubbleTextStyle {
|
|
138
|
+
NSShadow *shadow = [NSShadow new];
|
|
139
|
+
shadow.shadowColor = [NSColor colorWithWhite:0 alpha:0.45];
|
|
140
|
+
shadow.shadowBlurRadius = 2;
|
|
141
|
+
shadow.shadowOffset = NSMakeSize(0, -0.5);
|
|
142
|
+
BOOL statusLiquid = self.statusGlass.usesLiquidGlass;
|
|
143
|
+
self.statusTitleLabel.textColor = statusLiquid ? [NSColor colorWithWhite:1 alpha:0.78]
|
|
144
|
+
: [NSColor colorWithWhite:0.42 alpha:0.90];
|
|
145
|
+
self.statusDetailLabel.textColor = statusLiquid ? [NSColor colorWithWhite:1 alpha:0.97]
|
|
146
|
+
: [NSColor colorWithWhite:0.12 alpha:0.96];
|
|
147
|
+
self.statusTitleLabel.shadow = statusLiquid ? shadow : nil;
|
|
148
|
+
self.statusDetailLabel.shadow = statusLiquid ? shadow : nil;
|
|
149
|
+
BOOL speechLiquid = self.speechGlass.usesLiquidGlass;
|
|
150
|
+
self.speechLabel.textColor = speechLiquid ? [NSColor colorWithWhite:1 alpha:0.97]
|
|
151
|
+
: [NSColor colorWithWhite:0.10 alpha:0.96];
|
|
152
|
+
self.speechLabel.shadow = speechLiquid ? shadow : nil;
|
|
153
|
+
[self applyUpdateBadgeStyle];
|
|
154
|
+
}
|
|
155
|
+
- (void)setGlassDimLevel:(MenuChoiceRowView *)sender {
|
|
156
|
+
[self updateGlassDimLevel:sender.representedObject];
|
|
157
|
+
}
|
|
158
|
+
- (void)updateGlassDimLevel:(NSNumber *)level {
|
|
159
|
+
// 主窗口的滑块是连续值,菜单是四档;两边都走这里,统一取整并夹在 0–45。
|
|
160
|
+
if (![level isKindOfClass:NSNumber.class] || isnan(level.doubleValue)) return;
|
|
161
|
+
NSInteger value = MAX((NSInteger)0, MIN(CCPetsGlassDimMaximum, (NSInteger)lround(level.doubleValue)));
|
|
162
|
+
if ([[NSUserDefaults.standardUserDefaults objectForKey:CCPetsGlassDimKey] isEqual:@(value)]) return;
|
|
163
|
+
CCPetsPrefSetObject(CCPetsGlassDimKey, @(value));
|
|
164
|
+
[self.quotaGlass applyDimLevel];
|
|
165
|
+
[self.statusGlass applyDimLevel];
|
|
166
|
+
[self.speechGlass applyDimLevel];
|
|
167
|
+
[self.updateBadgeGlass applyDimLevel];
|
|
168
|
+
self.quotaView.cardScrimAlpha = CCPetsGlassCardScrimAlpha();
|
|
169
|
+
self.quotaView.needsDisplay = YES;
|
|
170
|
+
}
|
|
171
|
+
- (void)updateSpeechEnabled:(BOOL)enabled {
|
|
172
|
+
CCPetsPrefSetBool(PetSpeechEnabledKey, enabled);
|
|
173
|
+
// 更新提示不算碎碎念,关掉碎碎念时不收它。
|
|
174
|
+
if (!enabled && !self.updateBubbleVisible) [self hideSpeechBubble];
|
|
175
|
+
}
|
|
176
|
+
- (void)updatePetInteractionEnabled:(BOOL)enabled {
|
|
177
|
+
CCPetsPrefSetBool(PetInteractionEnabledKey, enabled);
|
|
178
|
+
}
|
|
179
|
+
// 阈值和间隔都是点击时现读的,写进去即生效;范围钳制在 CCPetsPrefNormalizedValue。
|
|
180
|
+
- (void)updatePetInteractionValue:(NSNumber *)value forKey:(NSString *)key {
|
|
181
|
+
if (![@[PetInteractionHeartThresholdKey, PetInteractionAnnoyedThresholdKey,
|
|
182
|
+
PetInteractionIntervalKey] containsObject:key]) return;
|
|
183
|
+
CCPetsPrefSetObject(key, value);
|
|
184
|
+
}
|
|
185
|
+
// 频率档位。改完立刻生效——四道闸都是现读的,不缓存。
|
|
186
|
+
// 顺手把冷却清掉,否则刚调高档位还要等完上一档的冷却才见效,会让人以为没生效。
|
|
187
|
+
- (void)updateSpeechFrequency:(NSString *)value {
|
|
188
|
+
if (![@[PetSpeechFrequencyLow, PetSpeechFrequencyNormal, PetSpeechFrequencyHigh,
|
|
189
|
+
PetSpeechFrequencyChatty] containsObject:value]) value = PetSpeechFrequencyNormal;
|
|
190
|
+
CCPetsPrefSetObject(PetSpeechFrequencyKey, value);
|
|
191
|
+
self.speechCooldownUntil = 0;
|
|
192
|
+
self.lastIdleSpeechCheck = 0;
|
|
193
|
+
}
|
|
194
|
+
- (void)updatePhrasesSource:(NSString *)source {
|
|
195
|
+
if (![@[PetPhrasesSourcePet, PetPhrasesSourceDefault] containsObject:source] ||
|
|
196
|
+
[source isEqualToString:PetPhrasesSource()]) return;
|
|
197
|
+
PetPhrasesSetSource(source);
|
|
198
|
+
CCPetsPrefPostChange(PetPhrasesSourceKey);
|
|
199
|
+
NSString *tag = self.lastPetVoiceTag;
|
|
200
|
+
self.lastPetVoiceTag = nil;
|
|
201
|
+
self.lastPetVoiceText = nil;
|
|
202
|
+
// 收起旧来源的碎碎念,状态卡副行也立即换成新来源。
|
|
203
|
+
if (!self.updateBubbleVisible) [self hideSpeechBubble];
|
|
204
|
+
if (self.hasAgentStatus && self.lastStatusState.length > 0) {
|
|
205
|
+
[NSObject cancelPreviousPerformRequestsWithTarget:self
|
|
206
|
+
selector:@selector(restoreStatusDetail) object:nil];
|
|
207
|
+
// 保留当前工具对应的小节,不把执行命令、编辑文件等状态退成通用工具态。
|
|
208
|
+
tag = tag ?: [self petVoiceTagForState:self.lastStatusState tool:@""];
|
|
209
|
+
NSString *text = PetPhraseForTag(tag, [self speechSlots]);
|
|
210
|
+
self.lastPetVoiceTag = tag;
|
|
211
|
+
self.lastPetVoiceText = text;
|
|
212
|
+
self.statusDetailLabel.stringValue = text ?: @"";
|
|
213
|
+
[self resizeStatusCardToFitText];
|
|
214
|
+
[self positionAgentStatus];
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// 台词交给内置编辑器,不再 openURL: 丢给"文本编辑"。
|
|
219
|
+
//
|
|
220
|
+
// 换掉的理由是反馈:系统编辑器保存完什么都不会说,小节名拼错、句子超 30 字、槽位
|
|
221
|
+
// 写错名字全是静默失效,用户只知道"改了没用"。内置编辑器保存时校验并当场报出来,
|
|
222
|
+
// 还能"试说一句"直接听效果。
|
|
223
|
+
- (void)editPhrasesFile:(id)sender {
|
|
224
|
+
// 编辑器只管文本,不认识气泡;把"说出来"这一步作为回调注入。
|
|
225
|
+
__weak typeof(self) weakSelf = self;
|
|
226
|
+
[PetPhrasesEditorController setSpeakHandler:^(NSString *text) {
|
|
227
|
+
[weakSelf presentSpeechText:text];
|
|
228
|
+
}];
|
|
229
|
+
[PetPhrasesEditorController present];
|
|
230
|
+
}
|
|
231
|
+
// 系统通知四项和 CC Bridge 送达通知共用:打开前先向系统申请通知权限,没拿到就保持关闭并说明
|
|
232
|
+
// 原因。completion 在主线程回调,参数是最终是否开启,调用方据此回写自己的开关。
|
|
233
|
+
- (void)updateNotification:(NSString *)key enabled:(BOOL)enabled
|
|
234
|
+
completion:(void (^)(BOOL enabled))completion {
|
|
235
|
+
if (![@[NotificationCompletionKey, NotificationFailureKey, NotificationApprovalKey,
|
|
236
|
+
NotificationStallKey, BridgeNotificationKey] containsObject:key]) return;
|
|
237
|
+
if (!enabled) {
|
|
238
|
+
CCPetsPrefSetBool(key, NO);
|
|
239
|
+
if (completion) completion(NO);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
[UNUserNotificationCenter.currentNotificationCenter
|
|
243
|
+
requestAuthorizationWithOptions:UNAuthorizationOptionAlert | UNAuthorizationOptionSound
|
|
244
|
+
completionHandler:^(BOOL granted, NSError *error) {
|
|
245
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
246
|
+
if (granted) CCPetsPrefSetBool(key, YES);
|
|
247
|
+
if (completion) completion(granted);
|
|
248
|
+
if (granted) return;
|
|
249
|
+
NSString *message = error.localizedDescription ?:
|
|
250
|
+
L(@"Allow notifications in System Settings → Notifications → CC Pets, then try again.");
|
|
251
|
+
[self showAlertWithTitle:L(@"Can't Enable Notifications") message:message];
|
|
252
|
+
});
|
|
253
|
+
}];
|
|
254
|
+
}
|
|
255
|
+
- (void)languageDidChange:(NSNotification *)notification {
|
|
256
|
+
PetPhrasesAdoptLanguageDefaults();
|
|
257
|
+
NSApp.mainMenu = nil;
|
|
258
|
+
[self installMainMenu];
|
|
259
|
+
self.quotaView.needsDisplay = YES;
|
|
260
|
+
// 状态卡标题和副行都是按状态现算的,按最后的状态重排一遍。工具名没留,
|
|
261
|
+
// 工具态会暂时退成"正在使用工具",下一条事件就会补回来。
|
|
262
|
+
if (self.hasAgentStatus && self.lastStatusState.length > 0) {
|
|
263
|
+
[self applyStatusPresentationForState:self.lastStatusState
|
|
264
|
+
provider:self.lastStatusProvider ?: @"Agent" tool:@""];
|
|
265
|
+
}
|
|
266
|
+
// 正在显示的碎碎念是旧语言的,收起即可,下一句自然是新语言。更新提示由更新逻辑自己重排。
|
|
267
|
+
if (!self.updateBubbleVisible) [self hideSpeechBubble];
|
|
268
|
+
}
|
|
269
|
+
@end
|
|
@@ -6,10 +6,8 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
6
6
|
|
|
7
7
|
@implementation AppDelegate (Speech)
|
|
8
8
|
- (BOOL)speechEnabled {
|
|
9
|
-
NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
|
|
10
9
|
// 缺省开启;用户可在右键菜单里关掉。
|
|
11
|
-
|
|
12
|
-
return value == nil ? YES : [value boolValue];
|
|
10
|
+
return CCPetsPrefBool(PetSpeechEnabledKey);
|
|
13
11
|
}
|
|
14
12
|
// 当前档位。现读,右键菜单里改完立刻生效不用重启。
|
|
15
13
|
- (PetSpeechRate)speechRate {
|
|
@@ -147,6 +145,8 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
147
145
|
self.speechPanel.level = NSFloatingWindowLevel;
|
|
148
146
|
self.speechPanel.collectionBehavior = NSWindowCollectionBehaviorCanJoinAllSpaces |
|
|
149
147
|
NSWindowCollectionBehaviorFullScreenAuxiliary;
|
|
148
|
+
// 和桌宠、状态卡一样不随 App 失焦隐藏。主窗口打开期间 App 是 Regular,会频繁失焦。
|
|
149
|
+
self.speechPanel.hidesOnDeactivate = NO;
|
|
150
150
|
// 气泡不抢焦点、不接受点击:它是纯播报,挡住宠物就本末倒置了。
|
|
151
151
|
self.speechPanel.ignoresMouseEvents = YES;
|
|
152
152
|
|
|
@@ -189,9 +189,10 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
189
189
|
NSSize size = self.speechPanel.frame.size;
|
|
190
190
|
CGFloat x = NSMidX(petFrame) - size.width / 2.0;
|
|
191
191
|
// 头顶放不下就翻到脚下,尾巴跟着改朝向长在顶边。
|
|
192
|
-
CGFloat
|
|
192
|
+
CGFloat inset = 6 * CCPetsBubbleScalePreference();
|
|
193
|
+
CGFloat aboveY = NSMaxY(petFrame) - inset;
|
|
193
194
|
BOOL fitsAbove = aboveY + size.height <= NSMaxY(visible) - 10;
|
|
194
|
-
CGFloat y = fitsAbove ? aboveY : NSMinY(petFrame) - size.height +
|
|
195
|
+
CGFloat y = fitsAbove ? aboveY : NSMinY(petFrame) - size.height + inset;
|
|
195
196
|
x = fmax(NSMinX(visible) + 10, fmin(x, NSMaxX(visible) - size.width - 10));
|
|
196
197
|
y = fmax(NSMinY(visible) + 10, fmin(y, NSMaxY(visible) - size.height - 10));
|
|
197
198
|
[self.speechPanel setFrameOrigin:NSMakePoint(x, y)];
|
|
@@ -209,6 +210,10 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
209
210
|
|
|
210
211
|
[self presentSpeechText:text];
|
|
211
212
|
}
|
|
213
|
+
// 设置页"试说一句"和预览台用:只取词,不记预算、不进冷却,说不说由调用方决定。
|
|
214
|
+
- (NSString *)sampleSpeechLine {
|
|
215
|
+
return PetPhraseForTag(PetPhraseTagIdle, [self speechSlots]);
|
|
216
|
+
}
|
|
212
217
|
// 话往哪儿显示只在这一处决定:有状态卡就并进它的副行,没有才起独立气泡。
|
|
213
218
|
// 调试触发也必须走这里——否则看到的是现实中不会出现的画面(两个泡叠着)。
|
|
214
219
|
- (void)presentSpeechText:(NSString *)text {
|
|
@@ -379,14 +384,15 @@ NSString *const PetSpeechFrequencyKey = @"CCPetsSpeechFrequency";
|
|
|
379
384
|
}
|
|
380
385
|
// 独立气泡:左右各 16 内边距,没有图标。
|
|
381
386
|
- (void)resizeSpeechBubbleToFitText {
|
|
387
|
+
if (!self.speechPanel) return;
|
|
382
388
|
const CGFloat padding = 16;
|
|
383
389
|
CGFloat width = padding * 2 + PetMeasuredLabelWidth(self.speechLabel);
|
|
384
390
|
width = fmax(96.0, fmin(width, 300.0));
|
|
385
391
|
NSSize panelSize = NSMakeSize(width + 12, PetSpeechBodyHeight + 12);
|
|
386
|
-
|
|
387
|
-
self.speechPanel.contentView.frame = NSMakeRect(0, 0, panelSize.width, panelSize.height);
|
|
392
|
+
PetResizeBubblePanel(self.speechPanel, panelSize);
|
|
388
393
|
self.speechGlass.frame = NSMakeRect(6, 6, width, PetSpeechBodyHeight);
|
|
389
394
|
self.speechGlass.cornerRadius = PetSpeechBodyHeight / 2.0;
|
|
390
395
|
self.speechLabel.frame = NSMakeRect(padding, 10, width - padding * 2, 18);
|
|
396
|
+
self.speechClickButton.frame = NSMakeRect(0, 0, panelSize.width, panelSize.height);
|
|
391
397
|
}
|
|
392
398
|
@end
|
|
@@ -201,10 +201,10 @@ static void TrimUpdateLog(NSString *path) {
|
|
|
201
201
|
[NSURL URLWithString:[@"https://github.com/" stringByAppendingString:CCPetsRepositorySlug]]];
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
|
-
// 版本号以 npm Registry 为准(自动更新装的就是它),更新说明取同版本 tag
|
|
205
|
-
//
|
|
206
|
-
- (void)fetchLatestReleaseWithCompletion:(void (^)(NSString *version,
|
|
207
|
-
|
|
204
|
+
// 版本号以 npm Registry 为准(自动更新装的就是它),更新说明取同版本 tag 里的
|
|
205
|
+
// release notes 文件。说明没写、或请求全部失败都只是没有说明,不影响提示更新本身。
|
|
206
|
+
- (void)fetchLatestReleaseWithCompletion:(void (^)(NSString *version, NSString *notes,
|
|
207
|
+
NSString *errorMessage))completion {
|
|
208
208
|
NSURL *url = [NSURL URLWithString:@"https://registry.npmjs.org/cc-pets/latest"];
|
|
209
209
|
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
|
|
210
210
|
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:15];
|
|
@@ -221,35 +221,59 @@ static void TrimUpdateLog(NSString *path) {
|
|
|
221
221
|
NSComparisonResult comparison = CompareStableVersions(@CC_PETS_VERSION, latestVersion, &valid);
|
|
222
222
|
if (error || httpResponse.statusCode != 200 || !valid) {
|
|
223
223
|
NSString *message = error.localizedDescription ?: L(@"The npm registry returned invalid version info. Please try again later.");
|
|
224
|
-
dispatch_async(dispatch_get_main_queue(), ^{ completion(nil, nil,
|
|
224
|
+
dispatch_async(dispatch_get_main_queue(), ^{ completion(nil, nil, message); });
|
|
225
225
|
return;
|
|
226
226
|
}
|
|
227
227
|
if (comparison != NSOrderedAscending) {
|
|
228
|
-
dispatch_async(dispatch_get_main_queue(), ^{ completion(latestVersion, nil,
|
|
228
|
+
dispatch_async(dispatch_get_main_queue(), ^{ completion(latestVersion, nil, nil); });
|
|
229
229
|
return;
|
|
230
230
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
NSMutableURLRequest *releaseRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:releaseURL]
|
|
234
|
-
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10];
|
|
235
|
-
[releaseRequest setValue:@"application/vnd.github+json" forHTTPHeaderField:@"Accept"];
|
|
236
|
-
[releaseRequest setValue:@"cc-pets/" CC_PETS_VERSION forHTTPHeaderField:@"User-Agent"];
|
|
237
|
-
NSURLSessionDataTask *releaseTask = [NSURLSession.sharedSession dataTaskWithRequest:releaseRequest
|
|
238
|
-
completionHandler:^(NSData *releaseData, NSURLResponse *releaseResponse, NSError *releaseError) {
|
|
239
|
-
NSInteger status = [releaseResponse isKindOfClass:NSHTTPURLResponse.class]
|
|
240
|
-
? ((NSHTTPURLResponse *)releaseResponse).statusCode : 0;
|
|
241
|
-
NSDictionary *release = !releaseError && status == 200 && releaseData
|
|
242
|
-
? [NSJSONSerialization JSONObjectWithData:releaseData options:0 error:nil] : nil;
|
|
243
|
-
NSString *body = [release isKindOfClass:NSDictionary.class] &&
|
|
244
|
-
[release[@"body"] isKindOfClass:NSString.class] ? release[@"body"] : nil;
|
|
245
|
-
BOOL truncated = NO;
|
|
246
|
-
NSArray<NSString *> *highlights = ReleaseNoteHighlightsForLanguage(body,
|
|
247
|
-
CCPetsCurrentLanguage(), UpdateHighlightLimit, UpdateHighlightMaxLength, &truncated);
|
|
248
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
|
249
|
-
completion(latestVersion, highlights, truncated, nil);
|
|
250
|
-
});
|
|
231
|
+
[self fetchReleaseNotesForVersion:latestVersion sourceIndex:0 completion:^(NSString *body) {
|
|
232
|
+
dispatch_async(dispatch_get_main_queue(), ^{ completion(latestVersion, body, nil); });
|
|
251
233
|
}];
|
|
252
|
-
|
|
234
|
+
}];
|
|
235
|
+
[task resume];
|
|
236
|
+
}
|
|
237
|
+
// 更新说明按顺序尝试:tag 里的 docs/release-notes-vX.Y.Z.md(raw.githubusercontent.com,
|
|
238
|
+
// 再退到 jsDelivr),最后才是 GitHub Release API。未认证的 API 按出口 IP 每小时只给 60 次,
|
|
239
|
+
// 走共享代理时很容易被别人用光,所以只当兜底。全部失败时 body 为 nil。
|
|
240
|
+
- (void)fetchReleaseNotesForVersion:(NSString *)version sourceIndex:(NSUInteger)index
|
|
241
|
+
completion:(void (^)(NSString *body))completion {
|
|
242
|
+
NSString *notesPath = [NSString stringWithFormat:@"v%@/docs/release-notes-v%@.md", version, version];
|
|
243
|
+
NSArray<NSString *> *sources = @[
|
|
244
|
+
[NSString stringWithFormat:@"https://raw.githubusercontent.com/%@/%@", CCPetsRepositorySlug, notesPath],
|
|
245
|
+
[NSString stringWithFormat:@"https://cdn.jsdelivr.net/gh/%@@%@", CCPetsRepositorySlug, notesPath],
|
|
246
|
+
[NSString stringWithFormat:@"https://api.github.com/repos/%@/releases/tags/v%@",
|
|
247
|
+
CCPetsRepositorySlug, version],
|
|
248
|
+
];
|
|
249
|
+
if (index >= sources.count) {
|
|
250
|
+
completion(nil);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
BOOL fromAPI = index == sources.count - 1;
|
|
254
|
+
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:sources[index]]
|
|
255
|
+
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10];
|
|
256
|
+
if (fromAPI) [request setValue:@"application/vnd.github+json" forHTTPHeaderField:@"Accept"];
|
|
257
|
+
[request setValue:@"cc-pets/" CC_PETS_VERSION forHTTPHeaderField:@"User-Agent"];
|
|
258
|
+
NSURLSessionDataTask *task = [NSURLSession.sharedSession dataTaskWithRequest:request
|
|
259
|
+
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
|
|
260
|
+
NSInteger status = [response isKindOfClass:NSHTTPURLResponse.class]
|
|
261
|
+
? ((NSHTTPURLResponse *)response).statusCode : 0;
|
|
262
|
+
NSString *body = nil;
|
|
263
|
+
if (!error && status == 200 && data) {
|
|
264
|
+
if (fromAPI) {
|
|
265
|
+
NSDictionary *release = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
|
|
266
|
+
body = [release isKindOfClass:NSDictionary.class] &&
|
|
267
|
+
[release[@"body"] isKindOfClass:NSString.class] ? release[@"body"] : nil;
|
|
268
|
+
} else {
|
|
269
|
+
body = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (body.length > 0) {
|
|
273
|
+
completion(body);
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
[self fetchReleaseNotesForVersion:version sourceIndex:index + 1 completion:completion];
|
|
253
277
|
}];
|
|
254
278
|
[task resume];
|
|
255
279
|
}
|
|
@@ -257,8 +281,7 @@ static void TrimUpdateLog(NSString *path) {
|
|
|
257
281
|
if (self.checkingForUpdate || self.updating) return;
|
|
258
282
|
self.checkingForUpdate = YES;
|
|
259
283
|
__weak typeof(self) weakSelf = self;
|
|
260
|
-
[self fetchLatestReleaseWithCompletion:^(NSString *version,
|
|
261
|
-
BOOL truncated, NSString *errorMessage) {
|
|
284
|
+
[self fetchLatestReleaseWithCompletion:^(NSString *version, NSString *notes, NSString *errorMessage) {
|
|
262
285
|
typeof(self) strongSelf = weakSelf;
|
|
263
286
|
if (!strongSelf) return;
|
|
264
287
|
strongSelf.checkingForUpdate = NO;
|
|
@@ -273,7 +296,7 @@ static void TrimUpdateLog(NSString *path) {
|
|
|
273
296
|
message:[NSString stringWithFormat:L(@"Version %@"), @CC_PETS_VERSION]];
|
|
274
297
|
return;
|
|
275
298
|
}
|
|
276
|
-
[strongSelf rememberPendingUpdate:version
|
|
299
|
+
[strongSelf rememberPendingUpdate:version notes:notes];
|
|
277
300
|
[strongSelf showUpdateDialog];
|
|
278
301
|
}];
|
|
279
302
|
}
|
|
@@ -290,8 +313,7 @@ static void TrimUpdateLog(NSString *path) {
|
|
|
290
313
|
self.lastSilentUpdateCheckAt = now;
|
|
291
314
|
self.checkingForUpdate = YES;
|
|
292
315
|
__weak typeof(self) weakSelf = self;
|
|
293
|
-
[self fetchLatestReleaseWithCompletion:^(NSString *version,
|
|
294
|
-
BOOL truncated, NSString *errorMessage) {
|
|
316
|
+
[self fetchLatestReleaseWithCompletion:^(NSString *version, NSString *notes, NSString *errorMessage) {
|
|
295
317
|
typeof(self) strongSelf = weakSelf;
|
|
296
318
|
if (!strongSelf) return;
|
|
297
319
|
strongSelf.checkingForUpdate = NO;
|
|
@@ -301,17 +323,16 @@ static void TrimUpdateLog(NSString *path) {
|
|
|
301
323
|
[strongSelf clearPendingUpdate];
|
|
302
324
|
return;
|
|
303
325
|
}
|
|
304
|
-
[strongSelf rememberPendingUpdate:version
|
|
326
|
+
[strongSelf rememberPendingUpdate:version notes:notes];
|
|
305
327
|
[strongSelf showUpdateBubble];
|
|
306
328
|
}];
|
|
307
329
|
}
|
|
308
|
-
|
|
309
|
-
|
|
330
|
+
// 存的是说明原文,弹窗时再按当时的界面语言解析:切换语言后不用重新联网,要点也跟着换。
|
|
331
|
+
- (void)rememberPendingUpdate:(NSString *)version notes:(NSString *)notes {
|
|
310
332
|
// 「稍后」只针对当时那个版本;又出了更新的版本就重新提醒。
|
|
311
333
|
if (![version isEqualToString:self.pendingUpdateVersion]) self.updateReminderSnoozed = NO;
|
|
312
334
|
self.pendingUpdateVersion = version;
|
|
313
|
-
self.
|
|
314
|
-
self.pendingUpdateHighlightsTruncated = truncated;
|
|
335
|
+
self.pendingUpdateNotes = notes;
|
|
315
336
|
[self refreshUpdateBadge];
|
|
316
337
|
}
|
|
317
338
|
- (void)refreshUpdateBadge {
|
|
@@ -322,19 +343,19 @@ static void TrimUpdateLog(NSString *path) {
|
|
|
322
343
|
}
|
|
323
344
|
- (void)clearPendingUpdate {
|
|
324
345
|
self.pendingUpdateVersion = nil;
|
|
325
|
-
self.
|
|
326
|
-
self.pendingUpdateHighlightsTruncated = NO;
|
|
346
|
+
self.pendingUpdateNotes = nil;
|
|
327
347
|
[self refreshUpdateBadge];
|
|
328
348
|
if (self.updateBubbleVisible) [self hideSpeechBubble];
|
|
329
349
|
}
|
|
330
350
|
// 更新要点放进 accessoryView 而不是 informativeText:后者是一整段纯文本,列表项折行后
|
|
331
351
|
// 第二行会顶到「•」下面,几条长说明挤成一坨。这里用悬挂缩进让折行对齐到文字起点。
|
|
332
|
-
- (NSView *)updateHighlightsAccessoryView {
|
|
333
|
-
if (
|
|
352
|
+
- (NSView *)updateHighlightsAccessoryView:(NSArray<NSString *> *)highlights truncated:(BOOL)truncated {
|
|
353
|
+
if (highlights.count == 0) return nil;
|
|
334
354
|
const CGFloat width = 300;
|
|
335
355
|
NSFont *bodyFont = [NSFont systemFontOfSize:12];
|
|
336
356
|
NSString *bullet = @"•\t";
|
|
337
|
-
|
|
357
|
+
// 只量「•」本身:连 \t 一起量会按默认 28pt 制表位展开,符号和文字之间空出一大截。
|
|
358
|
+
CGFloat indent = ceil([@"•" sizeWithAttributes:@{NSFontAttributeName: bodyFont}].width) + 6;
|
|
338
359
|
NSMutableParagraphStyle *itemStyle = [NSMutableParagraphStyle new];
|
|
339
360
|
itemStyle.tabStops = @[[[NSTextTab alloc] initWithTextAlignment:NSTextAlignmentLeft
|
|
340
361
|
location:indent options:@{}]];
|
|
@@ -351,14 +372,14 @@ static void TrimUpdateLog(NSString *path) {
|
|
|
351
372
|
NSDictionary *itemAttributes = @{NSFontAttributeName: bodyFont,
|
|
352
373
|
NSForegroundColorAttributeName: NSColor.secondaryLabelColor,
|
|
353
374
|
NSParagraphStyleAttributeName: itemStyle};
|
|
354
|
-
[
|
|
375
|
+
[highlights enumerateObjectsUsingBlock:^(NSString *item, NSUInteger index, BOOL *stop) {
|
|
355
376
|
NSString *line = [NSString stringWithFormat:@"%@%@%@", bullet, item,
|
|
356
|
-
index + 1 <
|
|
377
|
+
index + 1 < highlights.count || truncated
|
|
357
378
|
? @"\n" : @""];
|
|
358
379
|
[text appendAttributedString:[[NSAttributedString alloc] initWithString:line
|
|
359
380
|
attributes:itemAttributes]];
|
|
360
381
|
}];
|
|
361
|
-
if (
|
|
382
|
+
if (truncated) {
|
|
362
383
|
[text appendAttributedString:[[NSAttributedString alloc] initWithString:L(@"More changes in the full GitHub release notes")
|
|
363
384
|
attributes:@{NSFontAttributeName: [NSFont systemFontOfSize:11],
|
|
364
385
|
NSForegroundColorAttributeName: NSColor.tertiaryLabelColor,
|
|
@@ -379,10 +400,13 @@ static void TrimUpdateLog(NSString *path) {
|
|
|
379
400
|
NSAlert *alert = [NSAlert new];
|
|
380
401
|
alert.messageText = [NSString stringWithFormat:L(@"CC Pets %@ Is Available"), version];
|
|
381
402
|
alert.informativeText = [NSString stringWithFormat:L(@"Current version %@"), @CC_PETS_VERSION];
|
|
382
|
-
|
|
403
|
+
BOOL truncated = NO;
|
|
404
|
+
NSArray<NSString *> *highlights = ReleaseNoteHighlightsForLanguage(self.pendingUpdateNotes,
|
|
405
|
+
CCPetsCurrentLanguage(), UpdateHighlightLimit, UpdateHighlightMaxLength, &truncated);
|
|
406
|
+
alert.accessoryView = [self updateHighlightsAccessoryView:highlights truncated:truncated];
|
|
383
407
|
[alert addButtonWithTitle:L(@"Update Now")];
|
|
384
408
|
[alert addButtonWithTitle:L(@"Later")];
|
|
385
|
-
if (
|
|
409
|
+
if (highlights.count > 0) [alert addButtonWithTitle:L(@"Release Notes")];
|
|
386
410
|
NSModalResponse response = [alert runModal];
|
|
387
411
|
if (response == NSAlertFirstButtonReturn) {
|
|
388
412
|
[self startUpdateToVersion:version];
|