接入在线 LUT 权限、登录与服务器帧预览初版,待正式验收
这个提交包含在:
1 父节点
f7d0a80a2e
当前提交
a2a8624dc0
12 个文件已更改
+938
-18
没有与搜索条件相匹配的文件
@@ -2,6 +2,7 @@
|
||||
#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";
|
||||
@@ -132,6 +133,13 @@ typedef NS_ENUM(NSInteger,DYRegistrationState) { DYChecking, DYRegistering, DYRe
|
||||
@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
|
||||
@@ -154,6 +162,7 @@ typedef NS_ENUM(NSInteger,DYRegistrationState) { DYChecking, DYRegistering, DYRe
|
||||
[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];
|
||||
@@ -246,6 +255,14 @@ typedef NS_ENUM(NSInteger,DYRegistrationState) { DYChecking, DYRegistering, DYRe
|
||||
self.reportID,self.diagnosticDetail,self.sendSummaryButton],NSUserInterfaceLayoutOrientationVertical,10));
|
||||
NSStackView *beta=DYStack(@[updateCard,diagnosticCard],NSUserInterfaceLayoutOrientationHorizontal,14);
|
||||
[updateCard.heightAnchor constraintEqualToAnchor:diagnosticCard.heightAnchor].active=YES;
|
||||
self.accountTitle=DYLabel(@"在线 LUT",22,NSFontWeightSemibold,NSColor.whiteColor);
|
||||
self.accountDetail=DYLabel(@"在主 APP 登录后,即可在插件 LUT 浏览器中使用在线分类。",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:));
|
||||
DYSurface *accountCard=DYCard(DYBlue(),DYStack(@[DYHeading(@"person.crop.circle",@"大鱼账号 · 在线 LUT",DYBlue()),self.accountTitle,self.accountDetail,
|
||||
DYLabel(@"有效会员,或已购买文章 14421 / 15792,即可浏览和下载全部已发布在线 LUT。\n在插件中点击“在线预览当前帧”会发送当前帧缩略图到 dayu.media;服务器仅在本次请求中处理,不保存预览帧。",12,NSFontWeightRegular,DYSecondary()),
|
||||
DYStack(@[self.loginButton,self.accessButton,self.logoutButton],NSUserInterfaceLayoutOrientationHorizontal,8)],NSUserInterfaceLayoutOrientationVertical,12));
|
||||
NSArray *features = @[
|
||||
@[@"slider.horizontal.3",@"完整调色",@"精准还原,自由塑造",@"CST 色彩管理、光影与曲线\nHSL、色轮、蜘蛛盘与白平衡",DYBlue()],
|
||||
@[@"square.grid.2x2",@"LUT 与风格",@"灵感,所见即所得",@"LUT 缩略图浏览与实时预览\n快速收藏,管理常用风格",DYColor(.67,.59,1)],
|
||||
@@ -258,12 +275,74 @@ 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,beta,DYHeading(@"sparkles",@"一套工具,完成你的色彩表达",NSColor.whiteColor),row1,row2],NSUserInterfaceLayoutOrientationVertical,18);
|
||||
NSStackView *content = DYStack(@[website,hero,accountCard,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;
|
||||
}
|
||||
|
||||
- (void)stopAccountLogin {
|
||||
self.accountGeneration++;[self.accountTask cancel];self.accountTask=nil;
|
||||
[self.loginTimer invalidate];self.loginTimer=nil;self.loginSessionKey=nil;self.pollingLogin=NO;
|
||||
self.loginButton.enabled=YES;self.accessButton.enabled=YES;
|
||||
}
|
||||
- (void)refreshOnlineAccount:(id)sender {
|
||||
if(self.loginSessionKey.length)return;
|
||||
NSUInteger generation=++self.accountGeneration;[self.accountTask cancel];
|
||||
self.logoutButton.enabled=[DYOnlineLUTClient credential]!=nil;
|
||||
if(!self.logoutButton.enabled){self.accountTitle.stringValue=@"尚未登录";self.accountDetail.stringValue=@"点击微信登录,在浏览器中完成账号确认后自动返回。";return;}
|
||||
self.accountTitle.stringValue=@"正在验证在线 LUT 权限…";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){self.accountTitle.stringValue=@"暂时无法验证权限";self.accountDetail.stringValue=error.localizedDescription?:@"请稍后重试。";return;}
|
||||
BOOL allowed=[value[@"allowed"]isKindOfClass:NSNumber.class]&&[value[@"allowed"]boolValue];
|
||||
self.accountTitle.stringValue=allowed?@"在线 LUT 已开放":@"账号已登录,尚无在线 LUT 权限";
|
||||
NSString *name=[value[@"username"]isKindOfClass:NSString.class]?value[@"username"]:@"大鱼用户";
|
||||
self.accountDetail.stringValue=[NSString stringWithFormat:@"%@\n%@",name,allowed?@"在 FCP 的 LUT 浏览器切换“在线 LUT”即可使用。":@"需要有效会员,或购买文章 14421 / 15792。购买后点击刷新权限。"];
|
||||
}];
|
||||
}
|
||||
- (void)loginOnlineAccount:(id)sender {
|
||||
[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 权限。";
|
||||
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;}
|
||||
[self stopAccountLogin];[self refreshOnlineAccount:nil];
|
||||
}];
|
||||
}
|
||||
- (void)logoutOnlineAccount:(id)sender {
|
||||
[self stopAccountLogin];
|
||||
self.accountTask=[DYOnlineLUTClient request:@"/dayu-color/v1/lut/logout" body:@{} authenticated:YES completion:^(NSData *data,NSError *error){
|
||||
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;}[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;
|
||||
@@ -501,6 +580,7 @@ typedef NS_ENUM(NSInteger,DYRegistrationState) { DYChecking, DYRegistering, DYRe
|
||||
- (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();
|
||||
|
||||
在新工单中引用
屏蔽一个用户