WIP: integrate isolated beta update and diagnostic client; Release build passes, end-to-end validation pending

这个提交包含在:
mac 于 2026-11-02 17:28:52 +08:00 提交
1 父节点 f453508be6
当前提交 15d644c7e7
14 个文件已更改
+726 -18

没有与搜索条件相匹配的文件

+99 -7
查看文件
@@ -1,4 +1,6 @@
#import "AppDelegate.h"
#import "DYBetaUpdater.h"
#import "../Shared/DYBetaDiagnostics.h"
static NSString *const DYPluginID = @"com.dayu.color.XPC";
static NSString *const DYReleaseAddress = @"https://dayu.media";
@@ -116,6 +118,13 @@ typedef NS_ENUM(NSInteger,DYRegistrationState) { DYChecking, DYRegistering, DYRe
@property NSInteger secondsRemaining;
@property(retain) NSTimer *exitTimer;
@property(retain) NSMutableDictionary *diagnostics;
@property(retain) DYBetaUpdater *updater;
@property(assign) NSTextField *updateTitle, *updateDetail, *diagnosticDetail, *reportID;
@property(assign) DYActionButton *updateCheckButton, *updateInstallButton, *updateCancelButton, *sendSummaryButton;
@property(assign) NSButton *diagnosticToggle;
@property(assign) NSProgressIndicator *updateProgress;
@property(retain) NSTimer *updateProgressTimer;
@property BOOL updateCheckDone;
@end
@implementation AppDelegate
@@ -125,10 +134,21 @@ typedef NS_ENUM(NSInteger,DYRegistrationState) { DYChecking, DYRegistering, DYRe
self.window.appearance = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
self.window.titlebarAppearsTransparent = YES; self.window.backgroundColor = DYColor(.105,.14,.20);
self.window.contentMinSize = NSMakeSize(760,620); [self.window setContentSize:NSMakeSize(920,850)]; [self.window center];
DYBetaStart();
[self buildInterface]; [self buildMenu];
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(refreshDiagnostics:) name:DYBetaDiagnosticsChanged object:nil];
self.updater = [[[DYBetaUpdater alloc] init] autorelease];
__block AppDelegate *owner = self;
self.updater.changed = ^(NSDictionary *state) { [owner updateChanged:state]; };
self.updateProgressTimer = [NSTimer scheduledTimerWithTimeInterval:.2 target:self selector:@selector(refreshUpdateProgress:) userInfo:nil repeats:YES];
NSInteger expected=[NSUserDefaults.standardUserDefaults integerForKey:@"betaPendingUpdateBuild"];
if(expected>0 && [NSBundle.mainBundle.infoDictionary[@"CFBundleVersion"]integerValue]>=expected){
DYBetaEvent(@"update_installer",@{@"status":@"completed",@"count":@(expected)});
[NSUserDefaults.standardUserDefaults removeObjectForKey:@"betaPendingUpdateBuild"];
}
[NSWorkspace.sharedWorkspace.notificationCenter addObserver:self selector:@selector(accessibilityChanged:)
name:NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification object:nil];
[self.window makeKeyAndOrderFront:nil]; [self checkRegistration:nil];
[self.window makeKeyAndOrderFront:nil]; [self refreshDiagnostics:nil]; [self checkRegistration:nil]; [self.updater check];
}
- (void)buildMenu {
NSMenu *menu = [[[NSMenu alloc] initWithTitle:@"大鱼调色"] autorelease];
@@ -137,6 +157,7 @@ typedef NS_ENUM(NSInteger,DYRegistrationState) { DYChecking, DYRegistering, DYRe
for (NSArray *entry in @[@[@"关于大鱼调色",NSStringFromSelector(@selector(orderFrontStandardAboutPanel:)),@""],
@[@"查看功能介绍",NSStringFromSelector(@selector(keepIntroduction:)),@"i"],
@[@"重新检查插件",NSStringFromSelector(@selector(checkRegistration:)),@"r"],
@[@"检查公测更新",NSStringFromSelector(@selector(checkUpdate:)),@"u"],
@[@"访问发布地址",NSStringFromSelector(@selector(openWebsite:)),@""],
@[@"关闭窗口",NSStringFromSelector(@selector(closeWindow:)),@"w"],
@[@"退出大鱼调色",NSStringFromSelector(@selector(terminate:)),@"q"]]) {
@@ -190,6 +211,28 @@ typedef NS_ENUM(NSInteger,DYRegistrationState) { DYChecking, DYRegistering, DYRe
DYSurface *hostCard = DYCard(DYGreen(),host);
NSStackView *top = DYStack(@[self.registrationCard,hostCard],NSUserInterfaceLayoutOrientationHorizontal,14);
[self.registrationCard.heightAnchor constraintEqualToAnchor:hostCard.heightAnchor].active = YES;
self.updateTitle = DYLabel(@"公测更新",20,NSFontWeightSemibold,NSColor.whiteColor);
self.updateDetail = DYLabel(@"启动时自动检查,新版本由你确认安装。",13,NSFontWeightRegular,DYSecondary());
[self.updateDetail.heightAnchor constraintGreaterThanOrEqualToConstant:42].active = YES;
self.updateProgress = [[[NSProgressIndicator alloc] initWithFrame:NSZeroRect] autorelease];
self.updateProgress.style=NSProgressIndicatorStyleBar; self.updateProgress.indeterminate=NO;
self.updateProgress.minValue=0; self.updateProgress.maxValue=1; self.updateProgress.translatesAutoresizingMaskIntoConstraints=NO;
self.updateCheckButton=DYButton(@"检查更新",DYBlue(),NO,self,@selector(checkUpdate:));
self.updateInstallButton=DYButton(@"下载更新",DYColor(.20,.46,.94),YES,self,@selector(installUpdate:));
self.updateInstallButton.enabled=NO;
self.updateCancelButton=DYButton(@"取消下载",DYBlue(),NO,self,@selector(cancelUpdate:)); self.updateCancelButton.hidden=YES;
DYSurface *updateCard=DYCard(DYBlue(),DYStack(@[DYHeading(@"arrow.triangle.2.circlepath",@"持续改进,及时更新",DYBlue()),self.updateTitle,self.updateDetail,self.updateProgress,
DYStack(@[self.updateCheckButton,self.updateInstallButton],NSUserInterfaceLayoutOrientationHorizontal,8),self.updateCancelButton],NSUserInterfaceLayoutOrientationVertical,10));
self.diagnosticToggle=[NSButton checkboxWithTitle:@"参与公测诊断" target:self action:@selector(toggleDiagnostics:)];
self.diagnosticToggle.font=[NSFont systemFontOfSize:16 weight:NSFontWeightSemibold]; self.diagnosticToggle.state=DYBetaEnabled()?NSControlStateValueOn:NSControlStateValueOff;
self.diagnosticDetail=DYLabel(@"诊断准备中…",12,NSFontWeightRegular,DYSecondary());
self.reportID=DYLabel(@"报告标识准备中…",10,NSFontWeightRegular,DYSecondary());self.reportID.selectable=YES;
self.sendSummaryButton=DYButton(@"发送诊断摘要",DYColor(.67,.59,1),NO,self,@selector(sendSummary:));
DYSurface *diagnosticCard=DYCard(DYColor(.67,.59,1),DYStack(@[DYHeading(@"waveform.path.ecg",@"一起完善大鱼调色",DYColor(.67,.59,1)),self.diagnosticToggle,
DYLabel(@"仅发送版本、系统环境、加载耗时和本插件错误摘要;不发送素材、预设或账号。可随时关闭,诊断保留 30 天。",12,NSFontWeightRegular,DYSecondary()),
self.reportID,self.diagnosticDetail,self.sendSummaryButton],NSUserInterfaceLayoutOrientationVertical,10));
NSStackView *beta=DYStack(@[updateCard,diagnosticCard],NSUserInterfaceLayoutOrientationHorizontal,14);
[updateCard.heightAnchor constraintEqualToAnchor:diagnosticCard.heightAnchor].active=YES;
NSArray *features = @[
@[@"slider.horizontal.3",@"完整调色",@"精准还原,自由塑造",@"CST 色彩管理、光影与曲线\nHSL、色轮、蜘蛛盘与白平衡",DYBlue()],
@[@"square.grid.2x2",@"LUT 与风格",@"灵感,所见即所得",@"LUT 缩略图浏览与实时预览\n快速收藏,管理常用风格",DYColor(.67,.59,1)],
@@ -202,7 +245,7 @@ typedef NS_ENUM(NSInteger,DYRegistrationState) { DYChecking, DYRegistering, DYRe
NSStackView *row2 = DYStack(@[cards[2],cards[3]],NSUserInterfaceLayoutOrientationHorizontal,14);
[((NSView *)cards[0]).heightAnchor constraintEqualToAnchor:((NSView *)cards[1]).heightAnchor].active = YES;
[((NSView *)cards[2]).heightAnchor constraintEqualToAnchor:((NSView *)cards[3]).heightAnchor].active = YES;
NSStackView *content = DYStack(@[website,hero,top,DYHeading(@"sparkles",@"一套工具,完成你的色彩表达",NSColor.whiteColor),row1,row2],NSUserInterfaceLayoutOrientationVertical,18);
NSStackView *content = DYStack(@[website,hero,top,beta,DYHeading(@"sparkles",@"一套工具,完成你的色彩表达",NSColor.whiteColor),row1,row2],NSUserInterfaceLayoutOrientationVertical,18);
DYPin(content,document,30);
for (NSView *view in content.arrangedSubviews) [view.widthAnchor constraintEqualToAnchor:content.widthAnchor].active = YES;
[document.heightAnchor constraintGreaterThanOrEqualToAnchor:scroll.contentView.heightAnchor].active = YES;
@@ -294,11 +337,56 @@ typedef NS_ENUM(NSInteger,DYRegistrationState) { DYChecking, DYRegistering, DYRe
[self.diagnostics addEntriesFromDictionary:results]; self.diagnostics[@"status"] = success ? @"registered" : @"failed"; [self writeDiagnostics];
NSAccessibilityPostNotificationWithUserInfo(self.window,NSAccessibilityAnnouncementRequestedNotification,
@{NSAccessibilityAnnouncementKey:self.statusTitle.stringValue,NSAccessibilityPriorityKey:@(NSAccessibilityPriorityHigh)});
if (success && !self.keepOpen) {
self.secondsRemaining = 3; [self updateCountdown];
self.exitTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(exitTick:) userInfo:nil repeats:YES];
} else self.exitDetail.stringValue = success ? @"插件已就绪。关闭此窗口后,可继续在宿主中使用。" : @"注册尚未完成,应用会保留此窗口以便重试。";
DYBetaEvent(@"registration",@{@"status":success?@"registered":@"failed"});
if(success)[self maybeStartCountdown];
else self.exitDetail.stringValue=@"注册尚未完成,应用会保留此窗口以便重试。";
}
- (void)maybeStartCountdown {
if(self.terminating || self.registrationState!=DYReady)return;
if(self.keepOpen){self.exitDetail.stringValue=@"插件已就绪。关闭此窗口后,可继续在宿主中使用。";return;}
if(!self.updateCheckDone){self.exitDetail.stringValue=@"注册成功,正在检查公测更新…";return;}
if(self.exitTimer)return;
self.secondsRemaining=3;[self updateCountdown];
self.exitTimer=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(exitTick:) userInfo:nil repeats:YES];
}
- (void)updateChanged:(NSDictionary *)state {
if(self.terminating)return;
NSString *phase=state[@"phase"];
BOOL busy=[@[@"checking",@"downloading",@"validating"]containsObject:phase];
BOOL available=[@[@"available",@"ready",@"host_wait",@"installer"]containsObject:phase];
if(![phase isEqual:@"checking"]){self.updateCheckDone=YES;if(available)[self keepIntroduction:nil];}
self.updateTitle.stringValue=[phase isEqual:@"available"]?state[@"message"]:@"公测更新";
self.updateDetail.stringValue=state[@"message"]?:@"";
self.updateCheckButton.enabled=!busy;
self.updateInstallButton.enabled=[@[@"available",@"ready",@"host_wait",@"installer"]containsObject:phase];
self.updateInstallButton.title=[phase isEqual:@"available"]?@"下载更新":@"安装更新";
self.updateCancelButton.hidden=![phase isEqual:@"downloading"];
self.updateProgress.indeterminate=[@[@"checking",@"validating"]containsObject:phase];
if(self.updateProgress.indeterminate)[self.updateProgress startAnimation:nil];else [self.updateProgress stopAnimation:nil];
self.updateProgress.doubleValue=[@[@"ready",@"host_wait",@"installer"]containsObject:phase]?1:0;
[self maybeStartCountdown];
}
- (void)refreshUpdateProgress:(NSTimer *)timer {
if([self.updater.state[@"phase"]isEqual:@"downloading"])self.updateProgress.doubleValue=self.updater.downloadFraction;
}
- (void)checkUpdate:(id)sender { [self keepIntroduction:nil]; [self.updater check]; }
- (void)installUpdate:(id)sender {
[self keepIntroduction:nil];NSString *phase=self.updater.state[@"phase"];
if([phase isEqual:@"available"])[self.updater download];else [self.updater install];
}
- (void)cancelUpdate:(id)sender { [self keepIntroduction:nil];[self.updater cancel]; }
- (void)refreshDiagnostics:(NSNotification *)note {
NSDictionary *state=DYBetaStatus();BOOL enabled=DYBetaEnabled();self.diagnosticToggle.state=enabled?NSControlStateValueOn:NSControlStateValueOff;
self.sendSummaryButton.enabled=enabled;
self.reportID.stringValue=[NSString stringWithFormat:@"报告标识:%@",state[@"installation_id"]?:@"准备中…"];
NSNumber *uploaded=state[@"last_upload"];
if(!enabled)self.diagnosticDetail.stringValue=@"诊断已关闭。不会继续上传,待发送摘要已清除。";
else if(uploaded){NSDateFormatter *format=[[[NSDateFormatter alloc]init]autorelease];format.dateFormat=@"HH:mm:ss";
self.diagnosticDetail.stringValue=[NSString stringWithFormat:@"最近送达 %@ · 待发送 %@ 条",[format stringFromDate:[NSDate dateWithTimeIntervalSince1970:uploaded.doubleValue]],state[@"pending"]?:@0];}
else self.diagnosticDetail.stringValue=@"诊断将在后台发送,离线时暂存并稍后重试。";
}
- (void)toggleDiagnostics:(id)sender { [self keepIntroduction:nil];DYBetaSetEnabled(self.diagnosticToggle.state==NSControlStateValueOn);[self refreshDiagnostics:nil]; }
- (void)sendSummary:(id)sender { [self keepIntroduction:nil];DYBetaSendSummary();self.diagnosticDetail.stringValue=@"已加入后台发送队列,送达后会显示时间。"; }
- (void)updateCountdown { self.exitDetail.stringValue = [NSString stringWithFormat:@"%ld 秒后自动退出\n点击“查看功能介绍”可保留窗口",(long)self.secondsRemaining]; }
- (void)exitTick:(NSTimer *)timer {
if (--self.secondsRemaining <= 0) {
@@ -312,6 +400,7 @@ typedef NS_ENUM(NSInteger,DYRegistrationState) { DYChecking, DYRegistering, DYRe
}
- (void)confirmHost:(id)sender {
if (self.registrationState != DYReady) return;
DYBetaEvent(@"host_confirmed",@{@"status":@"user_confirmed"});
self.diagnostics[@"hostVerification"] = @"user-confirmed";
self.diagnostics[@"terminationReason"] = @"user-confirmed-host";
[self writeDiagnostics]; [NSApp terminate:nil];
@@ -343,7 +432,10 @@ typedef NS_ENUM(NSInteger,DYRegistrationState) { DYChecking, DYRegistering, DYRe
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)app { return YES; }
- (void)applicationWillTerminate:(NSNotification *)note {
self.terminating = YES; [self.exitTimer invalidate]; self.exitTimer = nil;
self.updater.changed=nil; [self.updater cancel];DYBetaStop();
[self.updateProgressTimer invalidate];self.updateProgressTimer=nil;
[NSNotificationCenter.defaultCenter removeObserver:self];
[NSWorkspace.sharedWorkspace.notificationCenter removeObserver:self];
}
- (void)dealloc { [_exitTimer invalidate]; [_exitTimer release]; [_diagnostics release]; [super dealloc]; }
- (void)dealloc { [_exitTimer invalidate]; [_exitTimer release]; [_diagnostics release]; [_updater release]; [_updateProgressTimer invalidate]; [_updateProgressTimer release]; [super dealloc]; }
@end