ui布局自适应
This commit is contained in:
1 parent
98f44890f8
commit
3587129b90
40 files changed
+929
-142
No files matched your search
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "config.hpp"
|
||||
#include "connector_service.hpp"
|
||||
#include "local_certificate.hpp"
|
||||
#include "platform.hpp"
|
||||
|
||||
using connector::ConnectorConfig;
|
||||
@@ -15,6 +16,7 @@ using connector::ConnectorService;
|
||||
@property(nonatomic, strong) NSTextField* statusLabel;
|
||||
@property(nonatomic, strong) NSArray<NSView*>* pathControls;
|
||||
@property(nonatomic, strong) NSButton* connectionButton;
|
||||
@property(nonatomic, strong) NSButton* safariButton;
|
||||
@property(nonatomic, assign) ConnectorService* service;
|
||||
@property(nonatomic, copy) NSString* startupError;
|
||||
@end
|
||||
@@ -72,6 +74,9 @@ using connector::ConnectorService;
|
||||
self.pathControls = @[pathLabel, self.pathField, browse, automatic, save];
|
||||
self.connectionButton = [self button:@"断开连接" frame:NSMakeRect(460, 25, 130, 36) action:@selector(toggleConnection:)];
|
||||
[content addSubview:self.connectionButton];
|
||||
self.safariButton = [self button:@"启用 Safari 支持" frame:NSMakeRect(315, 25, 130, 36) action:@selector(enableSafari:)];
|
||||
self.safariButton.toolTip = @"安装仅用于 127.0.0.1 的本地证书,使 Safari 可以访问 HTTPS 连接器。";
|
||||
[content addSubview:self.safariButton];
|
||||
[self refreshStatus:nil];
|
||||
[self.window makeKeyAndOrderFront:nil];
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
@@ -82,6 +87,9 @@ using connector::ConnectorService;
|
||||
const BOOL ownsPort = self.service && self.service->running();
|
||||
const BOOL portOccupied = ownsPort || connector::connector_port_in_use();
|
||||
self.connectionButton.title = portOccupied ? @"停止连接" : @"启动连接";
|
||||
const BOOL safariTrusted = connector::local_certificate_trusted();
|
||||
self.safariButton.title = safariTrusted ? @"Safari 支持已启用" : @"启用 Safari 支持";
|
||||
self.safariButton.enabled = !safariTrusted;
|
||||
if (self.startupError.length > 0 && !portOccupied) {
|
||||
self.statusLabel.stringValue = [@"● 连接器未启动 · " stringByAppendingString:self.startupError];
|
||||
self.statusLabel.textColor = NSColor.systemRedColor;
|
||||
@@ -121,6 +129,34 @@ using connector::ConnectorService;
|
||||
[self refreshStatus:nil];
|
||||
}
|
||||
|
||||
- (void)enableSafari:(id)sender {
|
||||
(void)sender;
|
||||
NSAlert* confirmation = [[NSAlert alloc] init];
|
||||
confirmation.messageText = @"启用 Safari 本机连接";
|
||||
confirmation.informativeText = @"连接器会把一个仅用于 127.0.0.1 的本地证书加入当前用户的 SSL 信任列表。系统可能要求你确认。";
|
||||
[confirmation addButtonWithTitle:@"继续"];
|
||||
[confirmation addButtonWithTitle:@"取消"];
|
||||
if ([confirmation runModal] != NSAlertFirstButtonReturn) return;
|
||||
|
||||
std::string error;
|
||||
if (!connector::trust_local_certificate(error)) {
|
||||
NSAlert* alert = [[NSAlert alloc] init];
|
||||
alert.messageText = @"无法启用 Safari 支持";
|
||||
alert.informativeText = [NSString stringWithUTF8String:error.c_str()];
|
||||
[alert runModal];
|
||||
return;
|
||||
}
|
||||
if (self.service && self.service->running() && !self.service->secure_running()) {
|
||||
self.service->stop();
|
||||
}
|
||||
if (self.service && !self.service->running()) {
|
||||
std::string startError;
|
||||
self.service->start(startError);
|
||||
self.startupError = [NSString stringWithUTF8String:startError.c_str()];
|
||||
}
|
||||
[self refreshStatus:nil];
|
||||
}
|
||||
|
||||
- (void)selectSpine:(id)sender {
|
||||
(void)sender;
|
||||
NSOpenPanel* panel = [NSOpenPanel openPanel];
|
||||
|
||||
Reference in new issue
Block a user