#import "AppDelegate.h" #import "DYBetaUpdater.h" #import "../Shared/DYBetaDiagnostics.h" #import "../Shared/DYCodeIntegrity.h" #import "../Shared/DYOnlineLUT.h" static NSString *const DYPluginID = @"com.dayu.color.XPC"; static NSString *const DYReleaseAddress = @"https://dayu.media"; static dispatch_queue_t DYPluginRegistrationQueue(void) { static dispatch_queue_t queue; static dispatch_once_t once; dispatch_once(&once, ^{ queue = dispatch_queue_create("com.dayu.color.registration", DISPATCH_QUEUE_SERIAL); }); return queue; } static NSColor *DYColor(CGFloat r, CGFloat g, CGFloat b) { return [NSColor colorWithSRGBRed:r green:g blue:b alpha:1]; } static NSColor *DYBlue(void) { return DYColor(.36,.65,1); } static NSColor *DYGreen(void) { return DYColor(.26,.86,.53); } static NSColor *DYSecondary(void) { return DYColor(.70,.74,.81); } // Static opaque surfaces preserve the reference palette without expensive blur or motion. @interface DYSurface : NSView @property(retain) NSColor *tint; @property BOOL backdrop; @end @implementation DYSurface - (BOOL)isFlipped { return YES; } - (void)drawRect:(NSRect)dirty { BOOL contrast = NSWorkspace.sharedWorkspace.accessibilityDisplayShouldIncreaseContrast; NSBezierPath *shape = [NSBezierPath bezierPathWithRoundedRect:NSInsetRect(self.bounds,1,1) xRadius:self.backdrop ? 0 : 14 yRadius:self.backdrop ? 0 : 14]; NSColor *base = DYColor(.105,.115,.14); NSColor *start = self.backdrop ? DYColor(.105,.14,.20) : [base blendedColorWithFraction:.07 ofColor:self.tint]; NSColor *end = self.backdrop ? DYColor(.105,.115,.115) : base; NSGradient *gradient = [[[NSGradient alloc] initWithStartingColor:start endingColor:end] autorelease]; [gradient drawInBezierPath:shape angle:35]; if (!self.backdrop) { [[self.tint blendedColorWithFraction:contrast ? .15 : .62 ofColor:base] setStroke]; shape.lineWidth = contrast ? 2 : 1; [shape stroke]; } } - (void)dealloc { [_tint release]; [super dealloc]; } @end @interface DYActionButton : NSButton @property(retain) NSColor *tint; @property BOOL prominent; @end @implementation DYActionButton - (void)drawRect:(NSRect)dirty { NSRect rect = NSInsetRect(self.bounds,2,2); NSBezierPath *shape = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:rect.size.height/2 yRadius:rect.size.height/2]; NSColor *base = self.prominent ? self.tint : [DYColor(.10,.12,.16) blendedColorWithFraction:.18 ofColor:self.tint]; if (self.highlighted) base = [base blendedColorWithFraction:.2 ofColor:NSColor.blackColor]; [base setFill]; [shape fill]; [[self.tint blendedColorWithFraction:.35 ofColor:NSColor.whiteColor] setStroke]; shape.lineWidth = NSWorkspace.sharedWorkspace.accessibilityDisplayShouldIncreaseContrast ? 2 : 1; [shape stroke]; NSColor *text = self.enabled ? (self.prominent ? NSColor.whiteColor : self.tint) : DYSecondary(); NSDictionary *attrs = @{NSFontAttributeName:[NSFont systemFontOfSize:13 weight:NSFontWeightSemibold],NSForegroundColorAttributeName:text}; NSSize size = [self.title sizeWithAttributes:attrs]; [self.title drawAtPoint:NSMakePoint((NSWidth(self.bounds)-size.width)/2,(NSHeight(self.bounds)-size.height)/2) withAttributes:attrs]; } - (void)drawFocusRingMask { [[NSBezierPath bezierPathWithRoundedRect:NSInsetRect(self.bounds,2,2) xRadius:20 yRadius:20] fill]; } - (NSRect)focusRingMaskBounds { return self.bounds; } - (void)dealloc { [_tint release]; [super dealloc]; } @end static NSTextField *DYLabel(NSString *text, CGFloat size, NSFontWeight weight, NSColor *color) { NSTextField *label = [NSTextField wrappingLabelWithString:text]; label.font = [NSFont systemFontOfSize:size weight:weight]; label.textColor = color; label.translatesAutoresizingMaskIntoConstraints = NO; [label setContentCompressionResistancePriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationVertical]; return label; } static NSStackView *DYStack(NSArray *views, NSUserInterfaceLayoutOrientation orientation, CGFloat spacing) { NSStackView *stack = [NSStackView stackViewWithViews:views]; stack.orientation = orientation; stack.spacing = spacing; stack.detachesHiddenViews = YES; stack.alignment = orientation == NSUserInterfaceLayoutOrientationVertical ? NSLayoutAttributeLeading : NSLayoutAttributeTop; stack.translatesAutoresizingMaskIntoConstraints = NO; if (orientation == NSUserInterfaceLayoutOrientationHorizontal) stack.distribution = NSStackViewDistributionFillEqually; return stack; } static void DYPin(NSView *child, NSView *parent, CGFloat inset) { child.translatesAutoresizingMaskIntoConstraints = NO; [parent addSubview:child]; [NSLayoutConstraint activateConstraints:@[ [child.leadingAnchor constraintEqualToAnchor:parent.leadingAnchor constant:inset], [child.trailingAnchor constraintEqualToAnchor:parent.trailingAnchor constant:-inset], [child.topAnchor constraintEqualToAnchor:parent.topAnchor constant:inset], [child.bottomAnchor constraintEqualToAnchor:parent.bottomAnchor constant:-inset]]]; } static DYActionButton *DYButton(NSString *title, NSColor *tint, BOOL prominent, id target, SEL action) { DYActionButton *button = [DYActionButton buttonWithTitle:title target:target action:action]; button.tint = tint; button.prominent = prominent; button.bordered = NO; button.translatesAutoresizingMaskIntoConstraints = NO; [button.heightAnchor constraintEqualToConstant:34].active = YES; [button.widthAnchor constraintGreaterThanOrEqualToConstant:100].active = YES; return button; } static DYSurface *DYCard(NSColor *tint, NSStackView *content) { DYSurface *card = [[[DYSurface alloc] initWithFrame:NSZeroRect] autorelease]; card.tint = tint; card.translatesAutoresizingMaskIntoConstraints = NO; DYPin(content,card,18); for (NSView *view in content.arrangedSubviews) [view.widthAnchor constraintEqualToAnchor:content.widthAnchor].active = YES; return card; } static NSTextField *DYHeading(NSString *symbol, NSString *text, NSColor *color) { NSTextField *label = DYLabel(text,15,NSFontWeightSemibold,color); NSImage *image = [NSImage imageWithSystemSymbolName:symbol accessibilityDescription:nil]; if (image) { NSTextAttachment *attachment = [[[NSTextAttachment alloc] init] autorelease]; attachment.image = image; attachment.bounds = NSMakeRect(0,-3,18,18); NSMutableAttributedString *value = [[[NSMutableAttributedString alloc] initWithAttributedString:[NSAttributedString attributedStringWithAttachment:attachment]] autorelease]; [value appendAttributedString:[[[NSAttributedString alloc] initWithString:[@" " stringByAppendingString:text] attributes:@{NSFontAttributeName:label.font,NSForegroundColorAttributeName:color}] autorelease]]; label.attributedStringValue = value; label.accessibilityLabel = text; } return label; } typedef NS_ENUM(NSInteger,DYRegistrationState) { DYChecking, DYRegistering, DYReady, DYFailed }; @interface AppDelegate () @property(weak) IBOutlet NSWindow *window; @property(assign) NSTextField *statusTitle, *statusDetail; @property(assign) DYActionButton *retryButton, *confirmationButton; @property(assign) NSProgressIndicator *progress; @property(assign) DYSurface *registrationCard; @property DYRegistrationState registrationState; @property BOOL terminating; @property(retain) NSStatusItem *statusItem; @property(retain) NSMutableDictionary *diagnostics; @property(retain) DYBetaUpdater *updater; @property(assign) NSTextField *updateTitle, *diagnosticDetail; @property(assign) DYActionButton *updateCheckButton, *updateInstallButton, *updateCancelButton, *sendSummaryButton; @property(assign) NSButton *diagnosticToggle; @property(assign) NSProgressIndicator *updateProgress; @property(retain) NSTimer *updateProgressTimer; @property BOOL updateCheckDone; @property BOOL integrityRejected; @property(assign) NSTextField *accountTitle,*accountDetail; @property(assign) DYActionButton *loginButton,*accessButton,*logoutButton; @property(retain) NSProgress *accountTask; @property(copy) NSString *loginSessionKey; @property(retain) NSTimer *loginTimer; @property NSUInteger accountGeneration; @property BOOL pollingLogin; @end @implementation AppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)notification { self.window.title = @"大鱼调色"; self.window.appearance = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]; self.window.titlebarAppearsTransparent = YES; self.window.backgroundColor = DYColor(.105,.14,.20); self.window.contentMinSize = NSMakeSize(720,560); [self.window setContentSize:NSMakeSize(840,620)]; [self.window center]; DYBetaStart(); [self buildInterface]; [self buildMenu]; [self buildStatusItem]; [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]; }; 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 refreshDiagnostics:nil]; [self checkRegistration:nil]; [self.updater check]; [self refreshOnlineAccount:nil]; // Explicit QA opt-in on the signed, installed wrapper only. Never stalls the host. if([NSProcessInfo.processInfo.arguments containsObject:@"--diagnostics-probe"]) [self performSelector:@selector(runDiagnosticsProbe) withObject:nil afterDelay:5]; } - (void)runDiagnosticsProbe { DYBetaEvent(@"diagnostic_summary",@{@"status":@"probe_begin"}); [NSThread sleepForTimeInterval:12]; DYBetaEvent(@"diagnostic_summary",@{@"status":@"probe_recovered"}); } - (void)buildMenu { NSMenu *menu = [[[NSMenu alloc] initWithTitle:@"大鱼调色"] autorelease]; NSMenuItem *root = [[[NSMenuItem alloc] initWithTitle:@"大鱼调色" action:NULL keyEquivalent:@""] autorelease]; [menu addItem:root]; NSMenu *app = [[[NSMenu alloc] initWithTitle:@"大鱼调色"] autorelease]; root.submenu = app; for (NSArray *entry in @[@[@"关于大鱼调色",NSStringFromSelector(@selector(orderFrontStandardAboutPanel:)),@""], @[@"使用帮助",NSStringFromSelector(@selector(showUsage:)),@"i"], @[@"重新检查插件",NSStringFromSelector(@selector(checkRegistration:)),@"r"], @[@"检查公测更新",NSStringFromSelector(@selector(checkUpdate:)),@"u"], @[@"访问发布地址",NSStringFromSelector(@selector(openWebsite:)),@""], @[@"关闭窗口",NSStringFromSelector(@selector(closeWindow:)),@"w"], @[@"退出大鱼调色",NSStringFromSelector(@selector(terminate:)),@"q"]]) { NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:entry[0] action:NSSelectorFromString(entry[1]) keyEquivalent:entry[2]] autorelease]; item.target = [entry[0] isEqualToString:@"退出大鱼调色"] || [entry[0] isEqualToString:@"关于大鱼调色"] ? NSApp : self; [app addItem:item]; } NSApp.mainMenu = menu; } - (void)buildInterface { DYSurface *backdrop = [[[DYSurface alloc] initWithFrame:NSZeroRect] autorelease]; backdrop.backdrop = YES; self.window.contentView = backdrop; NSScrollView *scroll = [[[NSScrollView alloc] initWithFrame:NSZeroRect] autorelease]; scroll.drawsBackground = NO; scroll.hasVerticalScroller = YES; scroll.autohidesScrollers = YES; DYPin(scroll,backdrop,0); DYSurface *document = [[[DYSurface alloc] initWithFrame:NSZeroRect] autorelease]; document.backdrop = YES; document.translatesAutoresizingMaskIntoConstraints = NO; scroll.documentView = document; [NSLayoutConstraint activateConstraints:@[ [document.leadingAnchor constraintEqualToAnchor:scroll.contentView.leadingAnchor], [document.topAnchor constraintEqualToAnchor:scroll.contentView.topAnchor], [document.widthAnchor constraintEqualToAnchor:scroll.contentView.widthAnchor]]]; NSDictionary *info = NSBundle.mainBundle.infoDictionary; NSStackView *title = DYStack(@[ DYLabel(@"大鱼调色",28,NSFontWeightSemibold,NSColor.whiteColor), DYLabel([NSString stringWithFormat:@"%@ · %@",info[@"CFBundleShortVersionString"],info[@"CFBundleVersion"]],11,NSFontWeightRegular,DYSecondary()) ],NSUserInterfaceLayoutOrientationVertical,4); NSButton *help = [NSButton buttonWithTitle:@"使用帮助 ↗" target:self action:@selector(showUsage:)]; help.bordered = NO; help.contentTintColor = DYBlue(); NSStackView *header = DYStack(@[title,help],NSUserInterfaceLayoutOrientationHorizontal,12); header.distribution = NSStackViewDistributionFill; header.alignment = NSLayoutAttributeCenterY; self.accountTitle = DYLabel(@"正在检查…",20,NSFontWeightSemibold,NSColor.whiteColor); self.accountDetail = DYLabel(@"",13,NSFontWeightRegular,DYSecondary()); self.loginButton = DYButton(@"微信登录",DYBlue(),YES,self,@selector(loginOnlineAccount:)); self.accessButton = DYButton(@"刷新权限",DYBlue(),NO,self,@selector(refreshOnlineAccount:)); self.logoutButton = DYButton(@"退出登录",DYSecondary(),NO,self,@selector(logoutOnlineAccount:)); self.logoutButton.hidden = YES; NSButton *accountInfo = [NSButton buttonWithTitle:@"权限与预览说明" target:self action:@selector(showAccountInfo:)]; accountInfo.bordered = NO; accountInfo.contentTintColor = DYSecondary(); DYSurface *accountCard = DYCard(DYBlue(),DYStack(@[ DYHeading(@"person.crop.circle",@"在线 LUT",DYBlue()),self.accountTitle,self.accountDetail, DYStack(@[self.loginButton,self.accessButton,self.logoutButton],NSUserInterfaceLayoutOrientationHorizontal,8),accountInfo ],NSUserInterfaceLayoutOrientationVertical,12)); self.statusTitle = DYLabel(@"正在检查…",20,NSFontWeightSemibold,NSColor.whiteColor); self.statusDetail = DYLabel(@"",13,NSFontWeightRegular,DYSecondary()); self.progress = [[[NSProgressIndicator alloc] initWithFrame:NSZeroRect] autorelease]; self.progress.style = NSProgressIndicatorStyleBar; self.progress.indeterminate = YES; self.progress.translatesAutoresizingMaskIntoConstraints = NO; self.retryButton = DYButton(@"重新检查",DYBlue(),NO,self,@selector(checkRegistration:)); self.confirmationButton = DYButton(@"已确认,后台运行",DYSecondary(),NO,self,@selector(confirmHost:)); self.confirmationButton.enabled = NO; self.confirmationButton.toolTip = @"在宿主中确认效果正常后,可收起此窗口。"; self.registrationCard = DYCard(DYGreen(),DYStack(@[ DYHeading(@"puzzlepiece.extension",@"插件连接",DYGreen()),self.statusTitle,self.statusDetail,self.progress, DYStack(@[DYButton(@"打开 FCP",DYBlue(),YES,self,@selector(openFinalCut:)), DYButton(@"打开 Motion",DYSecondary(),NO,self,@selector(openMotion:))],NSUserInterfaceLayoutOrientationHorizontal,8), DYStack(@[self.retryButton,self.confirmationButton],NSUserInterfaceLayoutOrientationHorizontal,8) ],NSUserInterfaceLayoutOrientationVertical,12)); NSStackView *top = DYStack(@[accountCard,self.registrationCard],NSUserInterfaceLayoutOrientationHorizontal,14); [accountCard.heightAnchor constraintEqualToAnchor:self.registrationCard.heightAnchor].active = YES; self.updateTitle = DYLabel(@"检查中…",18,NSFontWeightSemibold,NSColor.whiteColor); self.updateProgress = [[[NSProgressIndicator alloc] initWithFrame:NSZeroRect] autorelease]; self.updateProgress.style = NSProgressIndicatorStyleBar; self.updateProgress.minValue = 0; self.updateProgress.maxValue = 1; self.updateProgress.translatesAutoresizingMaskIntoConstraints = NO; self.updateProgress.hidden = YES; self.updateCheckButton = DYButton(@"检查更新",DYBlue(),NO,self,@selector(checkUpdate:)); self.updateInstallButton = DYButton(@"下载更新",DYBlue(),YES,self,@selector(installUpdate:)); self.updateInstallButton.hidden = YES; self.updateInstallButton.enabled = NO; self.updateCancelButton = DYButton(@"取消下载",DYSecondary(),NO,self,@selector(cancelUpdate:)); self.updateCancelButton.hidden = YES; DYSurface *updateCard = DYCard(DYBlue(),DYStack(@[ DYHeading(@"arrow.triangle.2.circlepath",@"版本更新",DYBlue()),self.updateTitle,self.updateProgress, DYStack(@[self.updateCheckButton,self.updateInstallButton],NSUserInterfaceLayoutOrientationHorizontal,8),self.updateCancelButton ],NSUserInterfaceLayoutOrientationVertical,12)); self.diagnosticToggle = [NSButton checkboxWithTitle:@"参与公测诊断" target:self action:@selector(toggleDiagnostics:)]; self.diagnosticToggle.font = [NSFont systemFontOfSize:13 weight:NSFontWeightMedium]; self.diagnosticToggle.state = DYBetaEnabled()?NSControlStateValueOn:NSControlStateValueOff; self.diagnosticDetail = DYLabel(@"",12,NSFontWeightRegular,DYSecondary()); self.sendSummaryButton = DYButton(@"发送摘要",DYSecondary(),NO,self,@selector(sendSummary:)); NSButton *privacy = [NSButton buttonWithTitle:@"隐私说明" target:self action:@selector(showDiagnosticsInfo:)]; privacy.bordered = NO; privacy.contentTintColor = DYSecondary(); DYSurface *diagnosticCard = DYCard(DYSecondary(),DYStack(@[ DYHeading(@"waveform.path.ecg",@"诊断",DYSecondary()),self.diagnosticToggle,self.diagnosticDetail, DYStack(@[self.sendSummaryButton,privacy],NSUserInterfaceLayoutOrientationHorizontal,8) ],NSUserInterfaceLayoutOrientationVertical,12)); NSStackView *bottom = DYStack(@[updateCard,diagnosticCard],NSUserInterfaceLayoutOrientationHorizontal,14); [updateCard.heightAnchor constraintEqualToAnchor:diagnosticCard.heightAnchor].active = YES; NSStackView *content = DYStack(@[header,top,bottom],NSUserInterfaceLayoutOrientationVertical,18); DYPin(content,document,24); for (NSView *view in content.arrangedSubviews) [view.widthAnchor constraintEqualToAnchor:content.widthAnchor].active = YES; [document.heightAnchor constraintGreaterThanOrEqualToAnchor:scroll.contentView.heightAnchor].active = YES; } - (void)showUsage:(id)sender { NSAlert *alert = [[[NSAlert alloc] init] autorelease]; alert.messageText = @"使用大鱼调色"; alert.informativeText = @"在 Final Cut Pro 的“效果 → 大鱼调色”中,将效果拖到片段。Motion 中可使用原生滤镜。\n\n更新或重新注册插件后,请保存项目并重新打开宿主。关闭主窗口后,应用仍在后台运行,可从菜单栏重新打开或退出。"; [alert addButtonWithTitle:@"好"]; [alert beginSheetModalForWindow:self.window completionHandler:nil]; } - (void)showAccountInfo:(id)sender { NSAlert *alert = [[[NSAlert alloc] init] autorelease]; alert.messageText = @"在线 LUT"; alert.informativeText = @"有效会员,或已购买文章 14421 / 15792,可使用全部已发布在线 LUT。请在插件 LUT 浏览器中展开“在线 LUT”。\n\n浏览器会发送当前缓存帧缩略图到 dayu.media 生成预览,服务器仅在内存处理。点击 LUT 后下载到本地分类,可离线使用。"; [alert addButtonWithTitle:@"好"]; [alert beginSheetModalForWindow:self.window completionHandler:nil]; } - (void)showDiagnosticsInfo:(id)sender { NSAlert *alert = [[[NSAlert alloc] init] autorelease]; alert.messageText = @"公测诊断与隐私"; alert.informativeText = [NSString stringWithFormat:@"诊断向 dayu.media 发送版本、系统环境、阶段耗时、内存和本产品崩溃/卡顿调用栈摘要,保留30天。素材、预设和账号不在诊断内容中。可随时关闭。\n\n报告标识\n%@",DYBetaStatus()[@"installation_id"]?:@"准备中"]; [alert addButtonWithTitle:@"好"]; [alert beginSheetModalForWindow:self.window completionHandler:nil]; } - (void)stopAccountLogin { self.accountGeneration++;[self.accountTask cancel];self.accountTask=nil; [self.loginTimer invalidate];self.loginTimer=nil;self.loginSessionKey=nil;self.pollingLogin=NO; self.loginButton.title=@"微信登录";self.loginButton.enabled=YES;self.accessButton.enabled=YES; } - (void)showOnlineAccount:(NSDictionary *)value { self.accessButton.enabled=YES;self.logoutButton.enabled=YES; BOOL allowed=[value[@"allowed"]isKindOfClass:NSNumber.class]&&[value[@"allowed"]boolValue]; self.accountTitle.stringValue=allowed?@"已开通":@"尚未开通"; self.loginButton.hidden=YES;self.logoutButton.hidden=NO; NSString *name=[value[@"username"]isKindOfClass:NSString.class]?value[@"username"]:@"大鱼用户"; self.accountDetail.stringValue=name; } - (void)restoreBoundOnlineAccount { self.loginButton.hidden=NO;self.logoutButton.hidden=YES; NSUInteger generation=++self.accountGeneration;[self.accountTask cancel]; NSString *device=[DYOnlineLUTClient deviceUUID]; if(!device){self.accountTitle.stringValue=@"无法识别本机";self.accountDetail.stringValue=@"无法读取 macOS 硬件 UUID,请稍后重试。";return;} self.accountTitle.stringValue=@"正在识别账号…";self.accessButton.enabled=NO; self.accountTask=[DYOnlineLUTClient request:@"/device-login" body:@{@"device_uuid":device} authenticated:NO completion:^(NSData *data,NSError *error){ if(generation!=self.accountGeneration)return;self.accountTask=nil;self.accessButton.enabled=YES; NSDictionary *value=[DYOnlineLUTClient JSON:data error:&error]; NSDictionary *identity=[value[@"data"]isKindOfClass:NSDictionary.class]?value[@"data"]:nil; NSString *token=[identity[@"token"]isKindOfClass:NSString.class]?identity[@"token"]:nil; if(error||![value[@"success"]boolValue]||!token.length){self.accountTitle.stringValue=@"尚未登录";self.accountDetail.stringValue=error.localizedDescription?:([identity[@"message"]isKindOfClass:NSString.class]?identity[@"message"]:@"本机尚未绑定账号,请点击微信登录。已绑定账号可点击刷新权限重试。");return;} self.accessButton.enabled=NO; self.accountTask=[DYOnlineLUTClient request:@"/dayu-color/v1/lut/device" body:@{@"device_uuid":device,@"login_token":token} authenticated:NO completion:^(NSData *bytes,NSError *failure){ if(generation!=self.accountGeneration)return;self.accountTask=nil;self.accessButton.enabled=YES; NSDictionary *account=[DYOnlineLUTClient JSON:bytes error:&failure]; if(failure||![DYOnlineLUTClient saveCredential:account error:&failure]){self.accountTitle.stringValue=@"暂时无法识别本机账号";self.accountDetail.stringValue=failure.localizedDescription?:@"请刷新权限,或重新微信登录。";return;} [self showOnlineAccount:account]; }]; }]; } - (void)refreshOnlineAccount:(id)sender { if(self.loginSessionKey.length)return; if(sender)[NSUserDefaults.standardUserDefaults setBool:NO forKey:@"DYOnlineLUTAutomaticLoginDisabled"]; NSUInteger generation=++self.accountGeneration;[self.accountTask cancel]; self.logoutButton.enabled=[DYOnlineLUTClient credential]!=nil; self.logoutButton.hidden=!self.logoutButton.enabled;self.loginButton.hidden=self.logoutButton.enabled; if(!self.logoutButton.enabled){if(![NSUserDefaults.standardUserDefaults boolForKey:@"DYOnlineLUTAutomaticLoginDisabled"]){[self restoreBoundOnlineAccount];return;}self.accountTitle.stringValue=@"已退出登录";self.accountDetail.stringValue=@"点击刷新权限可识别本机已绑定账号,也可以重新微信登录。";return;} self.accountTitle.stringValue=@"正在检查权限…";self.accessButton.enabled=NO; self.accountTask=[DYOnlineLUTClient request:@"/dayu-color/v1/lut/status" body:@{} authenticated:YES completion:^(NSData *data,NSError *error){ if(generation!=self.accountGeneration)return;self.accountTask=nil;self.accessButton.enabled=YES; NSDictionary *value=[DYOnlineLUTClient JSON:data error:&error]; if(error||!value){if(error.code==401){[DYOnlineLUTClient clearCredential:nil];[self restoreBoundOnlineAccount];return;}self.accountTitle.stringValue=@"暂时无法验证权限";self.accountDetail.stringValue=error.localizedDescription?:@"请稍后重试。";return;} [self showOnlineAccount:value]; }]; } - (void)loginOnlineAccount:(id)sender { if(self.loginSessionKey.length){[self stopAccountLogin];self.accountTitle.stringValue=@"登录已取消";self.accountDetail.stringValue=@"可以重新点击微信登录。";return;} [self stopAccountLogin];NSUInteger generation=self.accountGeneration; NSString *device=[DYOnlineLUTClient deviceUUID]; if(!device){self.accountDetail.stringValue=@"无法读取本机身份,请稍后重试。";return;} self.loginButton.enabled=NO;self.accessButton.enabled=NO;self.accountTitle.stringValue=@"正在创建微信登录…"; NSDictionary *info=NSBundle.mainBundle.infoDictionary; self.accountTask=[DYOnlineLUTClient request:@"/dayu-app/v1/login/session" body:@{@"device_uuid":device,@"app_name":@"DayuColor",@"client_bundle":@"com.dayu.color",@"client_version":info[@"CFBundleShortVersionString"]?:@"",@"client_build":info[@"CFBundleVersion"]?:@"",@"client_platform":@"macOS"} authenticated:NO completion:^(NSData *data,NSError *error){ if(generation!=self.accountGeneration)return;self.accountTask=nil; NSDictionary *value=[DYOnlineLUTClient JSON:data error:&error]; NSString *key=[value[@"session_key"]isKindOfClass:NSString.class]?value[@"session_key"]:nil; NSURL *url=[value[@"login_url"]isKindOfClass:NSString.class]?[NSURL URLWithString:value[@"login_url"]]:nil; if(error||key.length<32||![url.scheme isEqual:@"https"]||![url.host.lowercaseString isEqual:@"dayu.media"]||![url.path isEqual:@"/oauth/weixin"]){ [self stopAccountLogin];self.accountTitle.stringValue=@"登录未完成";self.accountDetail.stringValue=error.localizedDescription?:@"登录服务返回的地址无效。";return; } self.loginSessionKey=key;self.accountTitle.stringValue=@"请在浏览器中完成微信登录";self.accountDetail.stringValue=@"完成扫码和账号确认后,这里会自动验证在线 LUT 权限。"; self.loginButton.title=@"取消登录";self.loginButton.enabled=YES; if(![NSWorkspace.sharedWorkspace openURL:url]){[self stopAccountLogin];self.accountDetail.stringValue=@"无法打开浏览器,请重试。";return;} self.loginTimer=[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(pollOnlineLogin:) userInfo:@{ @"started":NSDate.date } repeats:YES]; }]; } - (void)pollOnlineLogin:(NSTimer *)timer { if(self.pollingLogin||!self.loginSessionKey.length)return; if([timer.userInfo[@"started"]timeIntervalSinceNow]<-600){[self stopAccountLogin];self.accountDetail.stringValue=@"二维码已过期,请重新登录。";return;} NSUInteger generation=self.accountGeneration;self.pollingLogin=YES; self.accountTask=[DYOnlineLUTClient request:@"/dayu-color/v1/lut/session" body:@{@"session_key":self.loginSessionKey,@"device_uuid":[DYOnlineLUTClient deviceUUID]?:@""} authenticated:NO completion:^(NSData *data,NSError *error){ if(generation!=self.accountGeneration)return;self.pollingLogin=NO;self.accountTask=nil; NSDictionary *value=[DYOnlineLUTClient JSON:data error:&error]; if(error){if(error.code==401||error.code==400){[self stopAccountLogin];self.accountDetail.stringValue=error.localizedDescription;}return;} if(![value[@"status"]isEqual:@"approved"]){self.accountDetail.stringValue=[value[@"message"]isKindOfClass:NSString.class]?value[@"message"]:@"等待微信登录…";return;} if(![DYOnlineLUTClient saveCredential:value error:&error]){[self stopAccountLogin];self.accountDetail.stringValue=error.localizedDescription;return;} [NSUserDefaults.standardUserDefaults setBool:NO forKey:@"DYOnlineLUTAutomaticLoginDisabled"];[self stopAccountLogin];[self refreshOnlineAccount:nil]; }]; } - (void)logoutOnlineAccount:(id)sender { [self stopAccountLogin];NSUInteger generation=self.accountGeneration; self.accountTask=[DYOnlineLUTClient request:@"/dayu-color/v1/lut/logout" body:@{} authenticated:YES completion:^(NSData *data,NSError *error){ if(generation!=self.accountGeneration)return;self.accountTask=nil; if(error&&error.code!=401){self.accountDetail.stringValue=@"暂时无法通知服务器退出,请联网后重试。";return;} NSError *local=nil;if(![DYOnlineLUTClient clearCredential:&local]){self.accountDetail.stringValue=local.localizedDescription;return;}[NSUserDefaults.standardUserDefaults setBool:YES forKey:@"DYOnlineLUTAutomaticLoginDisabled"];[self refreshOnlineAccount:nil]; }]; } // PluginKit runs on a worker queue. Arguments are never interpreted as shell commands. - (NSDictionary *)runPluginKit:(NSArray *)arguments { NSTask *task = [[[NSTask alloc] init] autorelease]; task.executableURL = [NSURL fileURLWithPath:@"/usr/bin/pluginkit"]; task.arguments = arguments; NSPipe *pipe = [NSPipe pipe]; task.standardOutput = pipe; task.standardError = pipe; NSError *error = nil; if (![task launchAndReturnError:&error]) return @{@"code":@(-1),@"output":error.localizedDescription ?: @"无法启动插件登记服务"}; NSDate *deadline = [NSDate dateWithTimeIntervalSinceNow:8]; while (task.running && deadline.timeIntervalSinceNow > 0) [NSThread sleepForTimeInterval:.05]; if (task.running) { [task terminate]; return @{@"code":@(-2),@"output":@"插件登记服务响应超时"}; } NSData *data = [pipe.fileHandleForReading readDataToEndOfFile]; NSString *output = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease] ?: @""; return @{@"code":@(task.terminationStatus),@"output":output}; } - (BOOL)registry:(NSDictionary *)query containsPlugin:(NSString *)path { if ([query[@"code"] intValue] != 0) return NO; for (NSString *line in [query[@"output"] componentsSeparatedByCharactersInSet:NSCharacterSet.newlineCharacterSet]) { NSArray *fields = [line componentsSeparatedByString:@"\t"]; if (fields.count < 4) continue; NSString *identity = [fields[0] stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet]; if ([identity hasPrefix:@"+"]) identity = [[identity substringFromIndex:1] stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet]; NSString *registered = [[fields lastObject] stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet]; // 1.1 is the registration protocol, not the APP version. NSString *expected = [DYPluginID stringByAppendingString:@"(1.1)"]; if ([identity isEqualToString:expected] && [registered.stringByResolvingSymlinksInPath isEqualToString:path.stringByResolvingSymlinksInPath]) return YES; } return NO; } - (BOOL)registry:(NSDictionary *)query listsExactPath:(NSString *)path { NSString *suffix = [@"\t" stringByAppendingString:path]; for (NSString *line in [query[@"output"] componentsSeparatedByCharactersInSet:NSCharacterSet.newlineCharacterSet]) { if ([line hasSuffix:suffix]) return YES; } return NO; } - (NSString *)removeRejectedPluginRegistration:(NSString *)path { NSArray *arguments = @[@"-m",@"-A",@"-D",@"-v",@"-i",DYPluginID]; NSDictionary *before = [self runPluginKit:arguments]; if ([before[@"code"] intValue] != 0) return @"query-failed"; if (![self registry:before listsExactPath:path]) return @"not-registered"; if (![path.stringByStandardizingPath isEqualToString:path.stringByResolvingSymlinksInPath]) return @"skipped-symlink"; [self runPluginKit:@[@"-r",path]]; NSDictionary *after = [self runPluginKit:arguments]; if ([after[@"code"] intValue] != 0 || [self registry:after listsExactPath:path]) return @"removal-unverified"; return @"removed"; } - (void)rejectModifiedInstallation:(NSDictionary *)results { if (self.integrityRejected || self.terminating) return; self.integrityRejected = YES; [self.updater stopForIntegrityFailure]; [self finishRegistration:NO details:DYIntegrityRecoveryMessage results:results]; self.retryButton.enabled = NO; NSString *path = [NSBundle.mainBundle.bundlePath stringByAppendingPathComponent:DYPluginRelativePath]; dispatch_async(DYPluginRegistrationQueue(), ^{ @autoreleasepool { NSString *removal = [self removeRejectedPluginRegistration:path]; dispatch_async(dispatch_get_main_queue(), ^{ self.diagnostics[@"registrationRevocation"] = removal; [self writeDiagnostics]; }); } }); } - (void)checkRegistration:(id)sender { if (self.integrityRejected) return; if (self.diagnostics && (self.registrationState == DYChecking || self.registrationState == DYRegistering)) return; self.registrationState = DYChecking; self.retryButton.enabled = NO; self.retryButton.title = @"检查中…"; self.statusTitle.stringValue = @"正在检查插件…"; self.statusTitle.textColor = NSColor.whiteColor; self.statusDetail.stringValue = @"正在检查本机插件登记,随后自动提交注册。"; self.progress.hidden = NO; self.progress.indeterminate = YES; [self.progress startAnimation:nil]; NSString *path = [NSBundle.mainBundle.bundlePath stringByAppendingPathComponent:DYPluginRelativePath]; self.diagnostics = [NSMutableDictionary dictionaryWithDictionary:@{ @"bundleID":NSBundle.mainBundle.bundleIdentifier ?: @"",@"version":[NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"] ?: @"", @"build":[NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"] ?: @"",@"executable":NSBundle.mainBundle.executablePath ?: @"", @"pid":@(NSProcessInfo.processInfo.processIdentifier),@"plugin":path,@"status":@"checking"}]; dispatch_async(DYPluginRegistrationQueue(), ^{ @autoreleasepool { NSString *failedComponent = nil; OSStatus status = DYValidateRunningInstallation(DYCodeRoleWrapper, &failedComponent); if (status != errSecSuccess) { NSDictionary *results = @{@"integrity":@"rejected", @"integrityComponent":failedComponent, @"integrityOSStatus":@(status)}; dispatch_async(dispatch_get_main_queue(), ^{ [self rejectModifiedInstallation:results]; }); return; } NSBundle *plugin = [NSBundle bundleWithPath:path]; NSDictionary *attributes = [plugin objectForInfoDictionaryKey:@"PlugInKit"][@"Attributes"]; BOOL validComponent = [plugin.bundleIdentifier isEqualToString:DYPluginID] && [[plugin objectForInfoDictionaryKey:@"CFBundleVersion"] isEqual:[NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"]] && [attributes[@"com.apple.protocol"] isEqual:@"FxPlug"] && [attributes[@"com.apple.version"] isEqual:@"1.1"]; if (!validComponent) { dispatch_async(dispatch_get_main_queue(), ^{ if (!self.integrityRejected) [self finishRegistration:NO details:@"未找到完整的插件组件。请从发布地址重新安装大鱼调色。" results:@{}]; }); return; } // The stand-alone wrapper can inspect the registry directly. Registration // and actual host rendering remain separate states; the user confirms FCP. NSDictionary *before = [self runPluginKit:@[@"-m",@"-v",@"-i",DYPluginID]]; dispatch_async(dispatch_get_main_queue(), ^{ if (self.integrityRejected) return; self.registrationState = DYRegistering; self.statusTitle.stringValue = @"正在注册插件…"; self.statusDetail.stringValue = @"正在向系统提交插件注册,并核对当前安装位置。"; }); NSDictionary *add = [self runPluginKit:@[@"-a",path]]; NSDictionary *after = nil; BOOL registered = NO; for (NSInteger attempt=0; attempt<4; attempt++) { if (attempt) [NSThread sleepForTimeInterval:.35]; after = [self runPluginKit:@[@"-m",@"-v",@"-i",DYPluginID]]; registered = [self registry:after containsPlugin:path]; if (registered) break; } BOOL submissionAccepted = [add[@"code"] intValue] == 0; NSString *message = registered ? @"在宿主中应用效果并确认画面正常。" : @"插件注册尚未完成。请点击“重新检查”,或重新安装后再试。窗口将保持打开。"; NSDictionary *results = @{@"integrity":@"verified",@"before":before,@"submission":add,@"after":after ?: @{},@"registered":@(registered), @"discoveryVerified":@(registered),@"submissionAccepted":@(submissionAccepted),@"hostVerification":@"awaiting-user-confirmation", @"confirmationMethod":registered ? @"exact-path-discovery" : @"unconfirmed"}; dispatch_async(dispatch_get_main_queue(), ^{ if (!self.integrityRejected) [self finishRegistration:registered details:message results:results]; }); } }); } - (void)finishRegistration:(BOOL)success details:(NSString *)details results:(NSDictionary *)results { if (self.terminating) return; self.registrationState = success ? DYReady : DYFailed; [self.progress stopAnimation:nil]; self.progress.hidden = YES; self.progress.indeterminate = NO; self.progress.doubleValue = success ? 100 : 0; self.registrationCard.tint = success ? DYGreen() : DYColor(1,.67,.30); [self.registrationCard setNeedsDisplay:YES]; self.statusTitle.stringValue = success ? @"已连接" : (self.integrityRejected ? @"安装完整性验证失败" : @"需要重新检查"); self.statusTitle.textColor = success ? DYGreen() : DYColor(1,.75,.4); self.statusDetail.stringValue = details; self.retryButton.title = @"重新检查"; self.retryButton.enabled = YES; self.confirmationButton.enabled = success; [self.diagnostics addEntriesFromDictionary:results]; self.diagnostics[@"status"] = success ? @"registered" : @"failed"; [self writeDiagnostics]; NSAccessibilityPostNotificationWithUserInfo(self.window,NSAccessibilityAnnouncementRequestedNotification, @{NSAccessibilityAnnouncementKey:self.statusTitle.stringValue,NSAccessibilityPriorityKey:@(NSAccessibilityPriorityHigh)}); DYBetaEvent(@"registration",@{@"status":success?@"registered":@"failed"}); } - (void)buildStatusItem { self.statusItem=[NSStatusBar.systemStatusBar statusItemWithLength:NSVariableStatusItemLength]; self.statusItem.button.image=[NSImage imageWithSystemSymbolName:@"slider.horizontal.3" accessibilityDescription:@"大鱼调色后台诊断"]; self.statusItem.button.toolTip=@"大鱼调色 · 后台运行"; NSMenu *menu=[[[NSMenu alloc]initWithTitle:@"大鱼调色"]autorelease]; NSMenuItem *show=[menu addItemWithTitle:@"打开大鱼调色" action:@selector(showMainWindow:) keyEquivalent:@""];show.target=self; NSMenuItem *send=[menu addItemWithTitle:@"发送诊断摘要" action:@selector(sendSummary:) keyEquivalent:@""];send.target=self; [menu addItem:NSMenuItem.separatorItem]; NSMenuItem *quit=[menu addItemWithTitle:@"退出大鱼调色" action:@selector(terminate:) keyEquivalent:@""];quit.target=NSApp; self.statusItem.menu=menu; } - (void)showMainWindow:(id)sender { [self.window makeKeyAndOrderFront:nil];[NSApp activateIgnoringOtherApps:YES]; } - (BOOL)applicationShouldHandleReopen:(NSApplication *)app hasVisibleWindows:(BOOL)visible { if(!visible)[self showMainWindow:nil];return YES; } - (void)updateChanged:(NSDictionary *)state { if(self.terminating)return; NSString *phase=state[@"phase"]; BOOL rejected = [phase isEqual:@"integrity_rejected"]; if (rejected) [self rejectModifiedInstallation:@{@"integrity":@"rejected"}]; 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=state[@"message"]?:@"版本更新"; self.updateInstallButton.hidden=!available; self.updateProgress.hidden=!busy; self.updateCheckButton.enabled=!busy && !rejected; self.updateInstallButton.enabled=[@[@"available",@"ready",@"host_wait",@"installer"]containsObject:phase]; self.updateInstallButton.title=[phase isEqual:@"available"]?@"下载更新":@"安装更新"; self.updateCancelButton.hidden=![phase isEqual:@"downloading"]; [self.updateProgressTimer invalidate];self.updateProgressTimer=nil; if([phase isEqual:@"downloading"])self.updateProgressTimer=[NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:@selector(refreshUpdateProgress:) userInfo:nil repeats:YES]; 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; } - (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; 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)keepIntroduction:(id)sender { [self showMainWindow:sender]; } - (void)confirmHost:(id)sender { if (self.registrationState != DYReady) return; DYBetaEvent(@"host_confirmed",@{@"status":@"user_confirmed"}); self.diagnostics[@"hostVerification"] = @"user-confirmed"; [self writeDiagnostics]; [self.window orderOut:nil]; } - (void)writeDiagnostics { NSURL *base = [NSFileManager.defaultManager URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask].firstObject; NSURL *folder = [base URLByAppendingPathComponent:@"com.dayu.color" isDirectory:YES]; [NSFileManager.defaultManager createDirectoryAtURL:folder withIntermediateDirectories:YES attributes:nil error:nil]; NSData *data = [NSJSONSerialization dataWithJSONObject:self.diagnostics options:NSJSONWritingPrettyPrinted error:nil]; [data writeToURL:[folder URLByAppendingPathComponent:@"Registration.json"] options:NSDataWritingAtomic error:nil]; } - (void)openHostWithIdentifiers:(NSArray *)identifiers name:(NSString *)name { [self keepIntroduction:nil]; NSURL *url = nil; for (NSString *identifier in identifiers) { url = [NSWorkspace.sharedWorkspace URLForApplicationWithBundleIdentifier:identifier]; if (url) break; } if (!url) { [self showMessage:[@"未找到 " stringByAppendingString:name] detail:@"请先安装宿主应用,再从效果或滤镜中使用大鱼调色。"]; return; } [NSWorkspace.sharedWorkspace openApplicationAtURL:url configuration:NSWorkspaceOpenConfiguration.configuration completionHandler:^(NSRunningApplication *app,NSError *error) { if (error) dispatch_async(dispatch_get_main_queue(), ^{ [self showMessage:@"无法打开宿主" detail:error.localizedDescription]; }); }]; } - (void)openFinalCut:(id)sender { [self openHostWithIdentifiers:@[@"com.apple.FinalCut",@"com.apple.FinalCutApp"] name:@"Final Cut Pro"]; } - (void)openMotion:(id)sender { [self openHostWithIdentifiers:@[@"com.apple.motionapp",@"com.apple.motionappApp"] name:@"Motion"]; } - (void)openWebsite:(id)sender { [self keepIntroduction:nil]; if (![NSWorkspace.sharedWorkspace openURL:[NSURL URLWithString:DYReleaseAddress]]) [self showMessage:@"无法打开发布地址" detail:DYReleaseAddress]; } - (void)showMessage:(NSString *)title detail:(NSString *)detail { NSAlert *alert = [[[NSAlert alloc] init] autorelease]; alert.messageText = title; alert.informativeText = detail; [alert addButtonWithTitle:@"好"]; [alert beginSheetModalForWindow:self.window completionHandler:nil]; } - (void)closeWindow:(id)sender { [self.window performClose:sender]; } - (void)accessibilityChanged:(NSNotification *)note { [self.window.contentView setNeedsDisplay:YES]; } - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)app { return NO; } - (void)applicationWillTerminate:(NSNotification *)note { [self stopAccountLogin]; self.terminating = YES; [NSStatusBar.systemStatusBar removeStatusItem:self.statusItem]; 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 { [_statusItem release]; [_diagnostics release]; [_updater release]; [_updateProgressTimer invalidate]; [_updateProgressTimer release]; [super dealloc]; } @end