feat(macos): VoiceCatMac AppKit client + fix xcodebuild
The previous "shipped" claim was false — xcodebuild had never been run and the macOS app source was never committed. This commit adds the 17 Swift source files + xcodeproj and fixes three real defect classes so Debug and Release both build clean: 1. MainWindowController.swift compile errors: - NSAccessibility.post arg order (element:notification:userInfo:) - NSAccessibilityPriorityMedium -> NSAccessibilityPriorityLevel.medium - StreamSummary.streamId -> .id (Identifiable conformance) - drop redundant VoiceCatResult.description extension 2. Linker: add -lc++ to OTHER_LDFLAGS (libvoicecat-fat.a is C++20; pure-Swift app target has no .cpp sources so libc++ wasn't pulled in — swift test passed because Package.swift testTarget has linkerSettings: c++). 3. Release config: add ONLY_ACTIVE_ARCH=YES (XCFramework only has arm64). Verified: clean Debug + Release builds, otool -L shows libc++.1.dylib, nm shows _vc_client_create/_vc_version_string, app launches and runs.
This commit is contained in:
38
clients/apple/macOS/VoiceCatMac/AppDelegate.swift
Normal file
38
clients/apple/macOS/VoiceCatMac/AppDelegate.swift
Normal file
@@ -0,0 +1,38 @@
|
||||
import AppKit
|
||||
|
||||
final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
private var connectWindowController: ConnectWindowController?
|
||||
|
||||
func applicationDidFinishLaunching(_ notification: Notification) {
|
||||
buildMenuBar()
|
||||
NSApp.setActivationPolicy(.regular)
|
||||
connectWindowController = ConnectWindowController()
|
||||
connectWindowController?.showWindow(nil)
|
||||
NSApp.activate(ignoringOtherApps: false)
|
||||
}
|
||||
|
||||
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { true }
|
||||
|
||||
private func buildMenuBar() {
|
||||
let mainMenu = NSMenu()
|
||||
|
||||
let appItem = NSMenuItem()
|
||||
mainMenu.addItem(appItem)
|
||||
let appMenu = NSMenu()
|
||||
appMenu.addItem(NSMenuItem(title: "Quit VoiceCat",
|
||||
action: #selector(NSApplication.terminate(_:)),
|
||||
keyEquivalent: "q"))
|
||||
appItem.submenu = appMenu
|
||||
|
||||
let editItem = NSMenuItem()
|
||||
mainMenu.addItem(editItem)
|
||||
let editMenu = NSMenu(title: "Edit")
|
||||
editMenu.addItem(NSMenuItem(title: "Cut", action: #selector(NSText.cut(_:)), keyEquivalent: "x"))
|
||||
editMenu.addItem(NSMenuItem(title: "Copy", action: #selector(NSText.copy(_:)), keyEquivalent: "c"))
|
||||
editMenu.addItem(NSMenuItem(title: "Paste", action: #selector(NSText.paste(_:)), keyEquivalent: "v"))
|
||||
editMenu.addItem(NSMenuItem(title: "Select All", action: #selector(NSText.selectAll(_:)), keyEquivalent: "a"))
|
||||
editItem.submenu = editMenu
|
||||
|
||||
NSApp.mainMenu = mainMenu
|
||||
}
|
||||
}
|
||||
28
clients/apple/macOS/VoiceCatMac/Info.plist
Normal file
28
clients/apple/macOS/VoiceCatMac/Info.plist
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>VoiceCat</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>0.0.1</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>14.0</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2026 VoiceCat contributors. All rights reserved.</string>
|
||||
<key>NSMicrophoneUsageDescription</key>
|
||||
<string>VoiceCat uses your microphone to transmit voice audio to other participants in the current channel.</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
</dict>
|
||||
</plist>
|
||||
24
clients/apple/macOS/VoiceCatMac/Models/SavedServer.swift
Normal file
24
clients/apple/macOS/VoiceCatMac/Models/SavedServer.swift
Normal file
@@ -0,0 +1,24 @@
|
||||
import Foundation
|
||||
|
||||
enum AuthMode: String, Codable, CaseIterable {
|
||||
case guest
|
||||
case password
|
||||
}
|
||||
|
||||
struct SavedServer: Codable, Identifiable {
|
||||
var id: UUID = UUID()
|
||||
var host: String
|
||||
var port: UInt16
|
||||
var authMode: AuthMode
|
||||
var savedUsername: String?
|
||||
var keychainTag: String?
|
||||
|
||||
var displayString: String {
|
||||
switch authMode {
|
||||
case .guest:
|
||||
return "\(host):\(port) (Guest)"
|
||||
case .password:
|
||||
return "\(savedUsername ?? "")@\(host):\(port)"
|
||||
}
|
||||
}
|
||||
}
|
||||
69
clients/apple/macOS/VoiceCatMac/Models/ServerListStore.swift
Normal file
69
clients/apple/macOS/VoiceCatMac/Models/ServerListStore.swift
Normal file
@@ -0,0 +1,69 @@
|
||||
import Foundation
|
||||
import Security
|
||||
|
||||
enum ServerListStore {
|
||||
static var appSupportURL: URL {
|
||||
let url = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!
|
||||
return url.appendingPathComponent("VoiceCat", isDirectory: true)
|
||||
}
|
||||
|
||||
static var serversURL: URL {
|
||||
appSupportURL.appendingPathComponent("servers.json")
|
||||
}
|
||||
|
||||
static var tofuStorePath: String {
|
||||
appSupportURL.appendingPathComponent("tofu_pins.txt").path
|
||||
}
|
||||
|
||||
static func load() -> [SavedServer] {
|
||||
try? FileManager.default.createDirectory(at: appSupportURL, withIntermediateDirectories: true)
|
||||
guard let data = try? Data(contentsOf: serversURL),
|
||||
let list = try? JSONDecoder().decode([SavedServer].self, from: data) else { return [] }
|
||||
return list
|
||||
}
|
||||
|
||||
static func save(_ servers: [SavedServer]) {
|
||||
try? FileManager.default.createDirectory(at: appSupportURL, withIntermediateDirectories: true)
|
||||
if let data = try? JSONEncoder().encode(servers) {
|
||||
try? data.write(to: serversURL, options: .atomic)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Keychain
|
||||
|
||||
static func savePassword(_ password: String, tag: String) {
|
||||
guard let data = password.data(using: .utf8) else { return }
|
||||
deletePassword(tag: tag)
|
||||
let query: [CFString: Any] = [
|
||||
kSecClass: kSecClassGenericPassword,
|
||||
kSecAttrService: "cat.voice.VoiceCatMac",
|
||||
kSecAttrAccount: tag,
|
||||
kSecValueData: data,
|
||||
]
|
||||
SecItemAdd(query as CFDictionary, nil)
|
||||
}
|
||||
|
||||
static func loadPassword(tag: String) -> String? {
|
||||
let query: [CFString: Any] = [
|
||||
kSecClass: kSecClassGenericPassword,
|
||||
kSecAttrService: "cat.voice.VoiceCatMac",
|
||||
kSecAttrAccount: tag,
|
||||
kSecReturnData: true,
|
||||
kSecMatchLimit: kSecMatchLimitOne,
|
||||
]
|
||||
var result: AnyObject?
|
||||
guard SecItemCopyMatching(query as CFDictionary, &result) == errSecSuccess,
|
||||
let data = result as? Data,
|
||||
let password = String(data: data, encoding: .utf8) else { return nil }
|
||||
return password
|
||||
}
|
||||
|
||||
static func deletePassword(tag: String) {
|
||||
let query: [CFString: Any] = [
|
||||
kSecClass: kSecClassGenericPassword,
|
||||
kSecAttrService: "cat.voice.VoiceCatMac",
|
||||
kSecAttrAccount: tag,
|
||||
]
|
||||
SecItemDelete(query as CFDictionary)
|
||||
}
|
||||
}
|
||||
209
clients/apple/macOS/VoiceCatMac/Sheets/AccountsSheet.swift
Normal file
209
clients/apple/macOS/VoiceCatMac/Sheets/AccountsSheet.swift
Normal file
@@ -0,0 +1,209 @@
|
||||
import AppKit
|
||||
import VoiceCatCore
|
||||
|
||||
final class AccountsSheet: NSViewController {
|
||||
|
||||
private let client: VoiceCatClient
|
||||
private var accounts: [Account] = []
|
||||
private let tableView = NSTableView()
|
||||
private let statusLabel = NSTextField(labelWithString: "Loading…")
|
||||
|
||||
init(client: VoiceCatClient) {
|
||||
self.client = client
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) { fatalError() }
|
||||
|
||||
override func loadView() {
|
||||
view = NSView(frame: NSRect(x: 0, y: 0, width: 480, height: 340))
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
buildUI()
|
||||
refreshAccounts()
|
||||
}
|
||||
|
||||
private func buildUI() {
|
||||
let titleLabel = NSTextField(labelWithString: "Server Accounts")
|
||||
titleLabel.font = .boldSystemFont(ofSize: 13)
|
||||
|
||||
let userCol = NSTableColumn(identifier: NSUserInterfaceItemIdentifier("username"))
|
||||
userCol.title = "Username"; userCol.width = 160
|
||||
let adminCol = NSTableColumn(identifier: NSUserInterfaceItemIdentifier("admin"))
|
||||
adminCol.title = "Admin"; adminCol.width = 60
|
||||
let createdCol = NSTableColumn(identifier: NSUserInterfaceItemIdentifier("created"))
|
||||
createdCol.title = "Created"; createdCol.width = 120
|
||||
let loginCol = NSTableColumn(identifier: NSUserInterfaceItemIdentifier("login"))
|
||||
loginCol.title = "Last Login"; loginCol.width = 120
|
||||
|
||||
tableView.addTableColumn(userCol)
|
||||
tableView.addTableColumn(adminCol)
|
||||
tableView.addTableColumn(createdCol)
|
||||
tableView.addTableColumn(loginCol)
|
||||
tableView.dataSource = self; tableView.delegate = self
|
||||
tableView.allowsMultipleSelection = false
|
||||
tableView.setAccessibilityLabel("Server accounts")
|
||||
|
||||
let sv = NSScrollView()
|
||||
sv.documentView = tableView; sv.hasVerticalScroller = true
|
||||
sv.borderType = .bezelBorder
|
||||
|
||||
let refreshButton = NSButton(title: "Refresh", target: self, action: #selector(refreshClicked))
|
||||
refreshButton.bezelStyle = .rounded
|
||||
refreshButton.setAccessibilityLabel("Refresh account list")
|
||||
|
||||
let addButton = NSButton(title: "Add…", target: self, action: #selector(addClicked))
|
||||
addButton.bezelStyle = .rounded
|
||||
addButton.setAccessibilityLabel("Add new account")
|
||||
|
||||
let resetPwButton = NSButton(title: "Reset Password…", target: self, action: #selector(resetPwClicked))
|
||||
resetPwButton.bezelStyle = .rounded
|
||||
resetPwButton.setAccessibilityLabel("Reset selected account password")
|
||||
|
||||
let deleteButton = NSButton(title: "Delete…", target: self, action: #selector(deleteClicked))
|
||||
deleteButton.bezelStyle = .rounded
|
||||
deleteButton.setAccessibilityLabel("Delete selected account")
|
||||
|
||||
let doneButton = NSButton(title: "Done", target: self, action: #selector(doneClicked))
|
||||
doneButton.bezelStyle = .rounded; doneButton.keyEquivalent = "\r"
|
||||
doneButton.setAccessibilityLabel("Close accounts sheet")
|
||||
|
||||
statusLabel.textColor = .secondaryLabelColor
|
||||
statusLabel.setAccessibilityLabel("Status")
|
||||
|
||||
let toolbar = NSStackView(views: [refreshButton, addButton, resetPwButton, deleteButton, NSView()])
|
||||
toolbar.orientation = .horizontal; toolbar.spacing = 8
|
||||
|
||||
let bottomRow = NSStackView(views: [statusLabel, NSView(), doneButton])
|
||||
bottomRow.orientation = .horizontal; bottomRow.spacing = 8
|
||||
|
||||
let stack = NSStackView(views: [titleLabel, sv, toolbar, bottomRow])
|
||||
stack.orientation = .vertical; stack.spacing = 10
|
||||
stack.edgeInsets = NSEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
|
||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(stack)
|
||||
NSLayoutConstraint.activate([
|
||||
stack.topAnchor.constraint(equalTo: view.topAnchor),
|
||||
stack.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
stack.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||
stack.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
||||
sv.heightAnchor.constraint(equalToConstant: 200),
|
||||
])
|
||||
|
||||
client.onEvent = { [weak self] event in
|
||||
if event.type == .accountList { self?.pullAccounts() }
|
||||
}
|
||||
}
|
||||
|
||||
private func refreshAccounts() {
|
||||
statusLabel.stringValue = "Loading…"
|
||||
client.requestAccountList()
|
||||
}
|
||||
|
||||
private func pullAccounts() {
|
||||
accounts = client.listAccounts()
|
||||
tableView.reloadData()
|
||||
statusLabel.stringValue = "\(accounts.count) account\(accounts.count == 1 ? "" : "s")"
|
||||
}
|
||||
|
||||
@objc private func refreshClicked() { refreshAccounts() }
|
||||
|
||||
@objc private func addClicked() {
|
||||
let sheet = InputSheet(title: "New Account", prompt: "Username:", defaultValue: "")
|
||||
sheet.onComplete = { [weak self] username in
|
||||
guard let self, let username, !username.isEmpty else { return }
|
||||
let pwSheet = PasswordPromptSheet(prompt: "Password for \(username):")
|
||||
pwSheet.onComplete = { [weak self] password in
|
||||
guard let self, let password, !password.isEmpty else { return }
|
||||
let r = self.client.createAccount(username, password: password)
|
||||
if r == .ok {
|
||||
self.statusLabel.stringValue = "Account '\(username)' created."
|
||||
self.refreshAccounts()
|
||||
} else {
|
||||
self.statusLabel.stringValue = "Failed: \(r.description)"
|
||||
}
|
||||
}
|
||||
self.presentAsSheet(pwSheet)
|
||||
}
|
||||
presentAsSheet(sheet)
|
||||
}
|
||||
|
||||
@objc private func resetPwClicked() {
|
||||
let row = tableView.selectedRow
|
||||
guard row >= 0, row < accounts.count else { return }
|
||||
let account = accounts[row]
|
||||
let sheet = PasswordPromptSheet(prompt: "New password for \(account.username):")
|
||||
sheet.onComplete = { [weak self] password in
|
||||
guard let self, let password, !password.isEmpty else { return }
|
||||
let r = self.client.resetPassword(account.username, newPassword: password)
|
||||
self.statusLabel.stringValue = r == .ok
|
||||
? "Password reset for '\(account.username)'."
|
||||
: "Failed: \(r.description)"
|
||||
}
|
||||
presentAsSheet(sheet)
|
||||
}
|
||||
|
||||
@objc private func deleteClicked() {
|
||||
let row = tableView.selectedRow
|
||||
guard row >= 0, row < accounts.count else { return }
|
||||
let account = accounts[row]
|
||||
let alert = NSAlert()
|
||||
alert.messageText = "Delete account '\(account.username)'?"
|
||||
alert.informativeText = "This cannot be undone."
|
||||
alert.addButton(withTitle: "Delete"); alert.addButton(withTitle: "Cancel")
|
||||
alert.alertStyle = .warning
|
||||
guard let window = view.window else { return }
|
||||
alert.beginSheetModal(for: window) { [weak self] response in
|
||||
guard response == .alertFirstButtonReturn, let self else { return }
|
||||
let r = self.client.deleteAccount(account.username)
|
||||
self.statusLabel.stringValue = r == .ok
|
||||
? "Account '\(account.username)' deleted."
|
||||
: "Failed: \(r.description)"
|
||||
if r == .ok { self.refreshAccounts() }
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func doneClicked() { dismiss(nil) }
|
||||
|
||||
private func dateString(_ ms: UInt64) -> String {
|
||||
guard ms > 0 else { return "—" }
|
||||
let date = Date(timeIntervalSince1970: Double(ms) / 1000.0)
|
||||
return DateFormatter.localizedString(from: date, dateStyle: .short, timeStyle: .none)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - NSTableViewDataSource / Delegate
|
||||
|
||||
extension AccountsSheet: NSTableViewDataSource, NSTableViewDelegate {
|
||||
func numberOfRows(in tableView: NSTableView) -> Int { accounts.count }
|
||||
|
||||
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
|
||||
let acc = accounts[row]
|
||||
let id = tableColumn?.identifier ?? NSUserInterfaceItemIdentifier("cell")
|
||||
let cell = tableView.makeView(withIdentifier: id, owner: nil) as? NSTableCellView
|
||||
?? makeCell(id)
|
||||
switch tableColumn?.identifier.rawValue {
|
||||
case "username": cell.textField?.stringValue = acc.username
|
||||
case "admin": cell.textField?.stringValue = acc.isAdmin ? "Yes" : ""
|
||||
case "created": cell.textField?.stringValue = dateString(acc.createdAtUnixMs)
|
||||
case "login": cell.textField?.stringValue = dateString(acc.lastLoginUnixMs)
|
||||
default: break
|
||||
}
|
||||
return cell
|
||||
}
|
||||
|
||||
private func makeCell(_ id: NSUserInterfaceItemIdentifier) -> NSTableCellView {
|
||||
let cell = NSTableCellView(); cell.identifier = id
|
||||
let tf = NSTextField(labelWithString: "")
|
||||
tf.translatesAutoresizingMaskIntoConstraints = false
|
||||
cell.addSubview(tf); cell.textField = tf
|
||||
NSLayoutConstraint.activate([
|
||||
tf.leadingAnchor.constraint(equalTo: cell.leadingAnchor, constant: 4),
|
||||
tf.trailingAnchor.constraint(equalTo: cell.trailingAnchor, constant: -4),
|
||||
tf.centerYAnchor.constraint(equalTo: cell.centerYAnchor),
|
||||
])
|
||||
return cell
|
||||
}
|
||||
}
|
||||
154
clients/apple/macOS/VoiceCatMac/Sheets/AddServerSheet.swift
Normal file
154
clients/apple/macOS/VoiceCatMac/Sheets/AddServerSheet.swift
Normal file
@@ -0,0 +1,154 @@
|
||||
import AppKit
|
||||
|
||||
final class AddServerSheet: NSViewController {
|
||||
|
||||
var onComplete: ((SavedServer?) -> Void)?
|
||||
|
||||
private var editing: SavedServer?
|
||||
|
||||
private let hostField = NSTextField()
|
||||
private let portField: NSTextField = {
|
||||
let f = NSTextField()
|
||||
f.stringValue = "7878"
|
||||
return f
|
||||
}()
|
||||
private let authPicker = NSPopUpButton()
|
||||
private let usernameField = NSTextField()
|
||||
private let passwordField = NSSecureTextField()
|
||||
private let savePwCheckbox = NSButton(checkboxWithTitle: "Save password in Keychain", target: nil, action: nil)
|
||||
|
||||
init(editing: SavedServer?) {
|
||||
self.editing = editing
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) { fatalError() }
|
||||
|
||||
override func loadView() {
|
||||
view = NSView(frame: NSRect(x: 0, y: 0, width: 380, height: 260))
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
buildUI()
|
||||
if let s = editing {
|
||||
hostField.stringValue = s.host
|
||||
portField.stringValue = "\(s.port)"
|
||||
authPicker.selectItem(withTitle: s.authMode == .guest ? "Guest" : "Account")
|
||||
usernameField.stringValue = s.savedUsername ?? ""
|
||||
updateAuthVisibility()
|
||||
}
|
||||
}
|
||||
|
||||
private func buildUI() {
|
||||
let title = NSTextField(labelWithString: editing == nil ? "Add Server" : "Edit Server")
|
||||
title.font = .boldSystemFont(ofSize: 14)
|
||||
|
||||
let hostLabel = NSTextField(labelWithString: "Host:")
|
||||
let portLabel = NSTextField(labelWithString: "Port:")
|
||||
let authLabel = NSTextField(labelWithString: "Auth:")
|
||||
let userLabel = NSTextField(labelWithString: "Username:")
|
||||
let pwLabel = NSTextField(labelWithString: "Password:")
|
||||
|
||||
hostField.placeholderString = "hostname or IP"
|
||||
hostField.setAccessibilityLabel("Server hostname or IP address")
|
||||
|
||||
portField.setAccessibilityLabel("Server port")
|
||||
|
||||
authPicker.addItem(withTitle: "Guest")
|
||||
authPicker.addItem(withTitle: "Account")
|
||||
authPicker.target = self; authPicker.action = #selector(authChanged)
|
||||
authPicker.setAccessibilityLabel("Authentication mode")
|
||||
|
||||
usernameField.placeholderString = "username"
|
||||
usernameField.setAccessibilityLabel("Username")
|
||||
|
||||
passwordField.placeholderString = "leave blank to enter at connect"
|
||||
passwordField.setAccessibilityLabel("Password (optional — enter at connect time if blank)")
|
||||
|
||||
savePwCheckbox.setAccessibilityLabel("Save password in system Keychain")
|
||||
|
||||
let cancelButton = NSButton(title: "Cancel", target: self, action: #selector(cancelClicked))
|
||||
cancelButton.bezelStyle = .rounded
|
||||
let saveButton = NSButton(title: "Save", target: self, action: #selector(saveClicked))
|
||||
saveButton.bezelStyle = .rounded
|
||||
saveButton.keyEquivalent = "\r"
|
||||
saveButton.setAccessibilityLabel("Save server")
|
||||
|
||||
let grid = NSGridView(views: [
|
||||
[hostLabel, hostField],
|
||||
[portLabel, portField],
|
||||
[authLabel, authPicker],
|
||||
[userLabel, usernameField],
|
||||
[pwLabel, passwordField],
|
||||
[NSView(), savePwCheckbox],
|
||||
])
|
||||
grid.rowSpacing = 8
|
||||
grid.columnSpacing = 8
|
||||
grid.column(at: 0).xPlacement = .trailing
|
||||
|
||||
let buttonRow = NSStackView(views: [NSView(), cancelButton, saveButton])
|
||||
buttonRow.orientation = .horizontal; buttonRow.spacing = 8
|
||||
|
||||
let stack = NSStackView(views: [title, grid, buttonRow])
|
||||
stack.orientation = .vertical
|
||||
stack.spacing = 16
|
||||
stack.edgeInsets = NSEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)
|
||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(stack)
|
||||
NSLayoutConstraint.activate([
|
||||
stack.topAnchor.constraint(equalTo: view.topAnchor),
|
||||
stack.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
stack.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||
stack.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
||||
])
|
||||
|
||||
updateAuthVisibility()
|
||||
}
|
||||
|
||||
@objc private func authChanged() { updateAuthVisibility() }
|
||||
|
||||
private func updateAuthVisibility() {
|
||||
let isAccount = authPicker.titleOfSelectedItem == "Account"
|
||||
usernameField.isEnabled = isAccount
|
||||
passwordField.isEnabled = isAccount
|
||||
savePwCheckbox.isEnabled = isAccount
|
||||
}
|
||||
|
||||
@objc private func saveClicked() {
|
||||
let host = hostField.stringValue.trimmingCharacters(in: .whitespaces)
|
||||
guard !host.isEmpty else {
|
||||
hostField.becomeFirstResponder(); return
|
||||
}
|
||||
let portStr = portField.stringValue.trimmingCharacters(in: .whitespaces)
|
||||
guard let port = UInt16(portStr), port > 0 else {
|
||||
portField.becomeFirstResponder(); return
|
||||
}
|
||||
let isGuest = authPicker.titleOfSelectedItem == "Guest"
|
||||
var server = editing ?? SavedServer(host: host, port: port,
|
||||
authMode: isGuest ? .guest : .password)
|
||||
server.host = host; server.port = port
|
||||
server.authMode = isGuest ? .guest : .password
|
||||
server.savedUsername = isGuest ? nil : usernameField.stringValue.trimmingCharacters(in: .whitespaces)
|
||||
|
||||
if !isGuest && savePwCheckbox.state == .on {
|
||||
let pw = passwordField.stringValue
|
||||
if !pw.isEmpty {
|
||||
let tag = server.keychainTag ?? "voicecat.server.\(server.id.uuidString)"
|
||||
server.keychainTag = tag
|
||||
ServerListStore.savePassword(pw, tag: tag)
|
||||
}
|
||||
} else if isGuest {
|
||||
if let tag = server.keychainTag { ServerListStore.deletePassword(tag: tag) }
|
||||
server.keychainTag = nil
|
||||
}
|
||||
|
||||
dismiss(nil)
|
||||
onComplete?(server)
|
||||
}
|
||||
|
||||
@objc private func cancelClicked() {
|
||||
dismiss(nil)
|
||||
onComplete?(nil)
|
||||
}
|
||||
}
|
||||
93
clients/apple/macOS/VoiceCatMac/Sheets/BanUserSheet.swift
Normal file
93
clients/apple/macOS/VoiceCatMac/Sheets/BanUserSheet.swift
Normal file
@@ -0,0 +1,93 @@
|
||||
import AppKit
|
||||
|
||||
final class BanUserSheet: NSViewController {
|
||||
|
||||
var onComplete: ((String?, UInt64) -> Void)?
|
||||
|
||||
private let targetNickname: String
|
||||
private let reasonField = NSTextField()
|
||||
private let durationPicker = NSSegmentedControl(
|
||||
labels: ["1 hour", "24 hours", "7 days", "Permanent"],
|
||||
trackingMode: .selectOne,
|
||||
target: nil, action: nil
|
||||
)
|
||||
|
||||
init(nickname: String) {
|
||||
self.targetNickname = nickname
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) { fatalError() }
|
||||
|
||||
override func loadView() {
|
||||
view = NSView(frame: NSRect(x: 0, y: 0, width: 360, height: 160))
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
buildUI()
|
||||
}
|
||||
|
||||
private func buildUI() {
|
||||
let titleLabel = NSTextField(labelWithString: "Ban \(targetNickname)")
|
||||
titleLabel.font = .boldSystemFont(ofSize: 13)
|
||||
|
||||
let reasonLabel = NSTextField(labelWithString: "Reason:")
|
||||
reasonField.placeholderString = "Ban reason (optional)"
|
||||
reasonField.setAccessibilityLabel("Ban reason")
|
||||
|
||||
let durationLabel = NSTextField(labelWithString: "Duration:")
|
||||
durationPicker.selectedSegment = 3
|
||||
durationPicker.setAccessibilityLabel("Ban duration")
|
||||
|
||||
let cancelButton = NSButton(title: "Cancel", target: self, action: #selector(cancelClicked))
|
||||
cancelButton.bezelStyle = .rounded
|
||||
|
||||
let banButton = NSButton(title: "Ban", target: self, action: #selector(banClicked))
|
||||
banButton.bezelStyle = .rounded; banButton.keyEquivalent = "\r"
|
||||
banButton.setAccessibilityLabel("Confirm ban")
|
||||
|
||||
let buttonRow = NSStackView(views: [NSView(), cancelButton, banButton])
|
||||
buttonRow.orientation = .horizontal; buttonRow.spacing = 8
|
||||
|
||||
let grid = NSGridView(views: [
|
||||
[reasonLabel, reasonField],
|
||||
[durationLabel, durationPicker],
|
||||
])
|
||||
grid.rowSpacing = 8; grid.columnSpacing = 8
|
||||
grid.column(at: 0).xPlacement = .trailing
|
||||
|
||||
let stack = NSStackView(views: [titleLabel, grid, buttonRow])
|
||||
stack.orientation = .vertical; stack.spacing = 12
|
||||
stack.edgeInsets = NSEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
|
||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(stack)
|
||||
NSLayoutConstraint.activate([
|
||||
stack.topAnchor.constraint(equalTo: view.topAnchor),
|
||||
stack.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
stack.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||
stack.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
||||
])
|
||||
}
|
||||
|
||||
@objc private func banClicked() {
|
||||
let reason = reasonField.stringValue.trimmingCharacters(in: .whitespaces)
|
||||
let expiresUnixMs = expiryFromSelection()
|
||||
dismiss(nil)
|
||||
onComplete?(reason.isEmpty ? nil : reason, expiresUnixMs)
|
||||
}
|
||||
|
||||
@objc private func cancelClicked() {
|
||||
dismiss(nil)
|
||||
}
|
||||
|
||||
private func expiryFromSelection() -> UInt64 {
|
||||
let nowMs = UInt64(Date().timeIntervalSince1970 * 1000)
|
||||
switch durationPicker.selectedSegment {
|
||||
case 0: return nowMs + 3_600_000 // 1 hour
|
||||
case 1: return nowMs + 86_400_000 // 24 hours
|
||||
case 2: return nowMs + 604_800_000 // 7 days
|
||||
default: return 0 // permanent (0 = no expiry)
|
||||
}
|
||||
}
|
||||
}
|
||||
202
clients/apple/macOS/VoiceCatMac/Sheets/ChannelEditSheet.swift
Normal file
202
clients/apple/macOS/VoiceCatMac/Sheets/ChannelEditSheet.swift
Normal file
@@ -0,0 +1,202 @@
|
||||
import AppKit
|
||||
import VoiceCatCore
|
||||
|
||||
final class ChannelEditSheet: NSViewController {
|
||||
|
||||
var onComplete: ((ChannelEdit?) -> Void)?
|
||||
|
||||
private let channels: [Channel]
|
||||
private var editing: ChannelEdit?
|
||||
|
||||
private let nameField = NSTextField()
|
||||
private let topicField = NSTextField()
|
||||
private let parentPicker = NSPopUpButton()
|
||||
private let pwCheckbox = NSButton(checkboxWithTitle: "Password protected", target: nil, action: nil)
|
||||
private let pwField = NSSecureTextField()
|
||||
private let maxUsersField: NSTextField = {
|
||||
let f = NSTextField(); f.stringValue = "0"; return f
|
||||
}()
|
||||
private let sortOrderField: NSTextField = {
|
||||
let f = NSTextField(); f.stringValue = "0"; return f
|
||||
}()
|
||||
private let stereoCheckbox = NSButton(checkboxWithTitle: "Stereo", target: nil, action: nil)
|
||||
private let bitrateField: NSTextField = {
|
||||
let f = NSTextField(); f.stringValue = "64000"; return f
|
||||
}()
|
||||
private let fecCheckbox = NSButton(checkboxWithTitle: "FEC", target: nil, action: nil)
|
||||
private let dtxCheckbox = NSButton(checkboxWithTitle: "DTX", target: nil, action: nil)
|
||||
private let frameMsPicker = NSPopUpButton()
|
||||
|
||||
init(channels: [Channel], editing: ChannelEdit?) {
|
||||
self.channels = channels
|
||||
self.editing = editing
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) { fatalError() }
|
||||
|
||||
override func loadView() {
|
||||
view = NSView(frame: NSRect(x: 0, y: 0, width: 440, height: 360))
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
buildUI()
|
||||
populateIfEditing()
|
||||
}
|
||||
|
||||
private func buildUI() {
|
||||
let titleText = editing == nil ? "Create Channel" : "Edit Channel"
|
||||
let titleLabel = NSTextField(labelWithString: titleText)
|
||||
titleLabel.font = .boldSystemFont(ofSize: 13)
|
||||
|
||||
nameField.placeholderString = "Channel name"
|
||||
nameField.setAccessibilityLabel("Channel name")
|
||||
topicField.placeholderString = "Topic (optional)"
|
||||
topicField.setAccessibilityLabel("Channel topic")
|
||||
|
||||
parentPicker.addItem(withTitle: "(root)")
|
||||
parentPicker.menu?.items.last?.representedObject = nil as UInt32?
|
||||
for ch in channels.sorted(by: { $0.name < $1.name }) {
|
||||
let item = NSMenuItem(title: ch.name, action: nil, keyEquivalent: "")
|
||||
item.representedObject = ch.id
|
||||
parentPicker.menu?.addItem(item)
|
||||
}
|
||||
parentPicker.setAccessibilityLabel("Parent channel")
|
||||
|
||||
pwCheckbox.target = self; pwCheckbox.action = #selector(pwToggled)
|
||||
pwField.placeholderString = "password (leave blank to keep existing)"
|
||||
pwField.setAccessibilityLabel("Channel password")
|
||||
pwField.isEnabled = false
|
||||
|
||||
maxUsersField.setAccessibilityLabel("Max users (0 = unlimited)")
|
||||
sortOrderField.setAccessibilityLabel("Sort order")
|
||||
|
||||
for ms in ["20", "40", "60"] { frameMsPicker.addItem(withTitle: "\(ms) ms") }
|
||||
frameMsPicker.setAccessibilityLabel("Opus frame duration")
|
||||
|
||||
fecCheckbox.state = .on
|
||||
stereoCheckbox.setAccessibilityLabel("Stereo audio")
|
||||
bitrateField.setAccessibilityLabel("Bitrate in bits per second")
|
||||
fecCheckbox.setAccessibilityLabel("Forward error correction")
|
||||
dtxCheckbox.setAccessibilityLabel("Discontinuous transmission")
|
||||
|
||||
let generalGrid = NSGridView(views: [
|
||||
[NSTextField(labelWithString: "Name:"), nameField],
|
||||
[NSTextField(labelWithString: "Topic:"), topicField],
|
||||
[NSTextField(labelWithString: "Parent:"), parentPicker],
|
||||
[pwCheckbox, pwField],
|
||||
[NSTextField(labelWithString: "Max users:"), maxUsersField],
|
||||
[NSTextField(labelWithString: "Sort order:"), sortOrderField],
|
||||
])
|
||||
generalGrid.rowSpacing = 8; generalGrid.columnSpacing = 8
|
||||
generalGrid.column(at: 0).xPlacement = .trailing
|
||||
|
||||
let audioGrid = NSGridView(views: [
|
||||
[NSTextField(labelWithString: "Bitrate:"), bitrateField],
|
||||
[NSTextField(labelWithString: "Frame:"), frameMsPicker],
|
||||
[stereoCheckbox, fecCheckbox],
|
||||
[dtxCheckbox, NSView()],
|
||||
])
|
||||
audioGrid.rowSpacing = 8; audioGrid.columnSpacing = 8
|
||||
audioGrid.column(at: 0).xPlacement = .trailing
|
||||
|
||||
let tabs = NSTabView()
|
||||
let generalTab = NSTabViewItem(identifier: "general")
|
||||
generalTab.label = "General"
|
||||
generalTab.view = generalGrid
|
||||
let audioTab = NSTabViewItem(identifier: "audio")
|
||||
audioTab.label = "Audio"
|
||||
audioTab.view = audioGrid
|
||||
tabs.addTabViewItem(generalTab)
|
||||
tabs.addTabViewItem(audioTab)
|
||||
|
||||
let cancelButton = NSButton(title: "Cancel", target: self, action: #selector(cancelClicked))
|
||||
cancelButton.bezelStyle = .rounded
|
||||
let saveButton = NSButton(title: editing == nil ? "Create" : "Save",
|
||||
target: self, action: #selector(saveClicked))
|
||||
saveButton.bezelStyle = .rounded; saveButton.keyEquivalent = "\r"
|
||||
|
||||
let buttonRow = NSStackView(views: [NSView(), cancelButton, saveButton])
|
||||
buttonRow.orientation = .horizontal; buttonRow.spacing = 8
|
||||
|
||||
let stack = NSStackView(views: [titleLabel, tabs, buttonRow])
|
||||
stack.orientation = .vertical
|
||||
stack.spacing = 12
|
||||
stack.edgeInsets = NSEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
|
||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(stack)
|
||||
NSLayoutConstraint.activate([
|
||||
stack.topAnchor.constraint(equalTo: view.topAnchor),
|
||||
stack.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
stack.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||
stack.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
||||
])
|
||||
}
|
||||
|
||||
private func populateIfEditing() {
|
||||
guard let e = editing else { return }
|
||||
nameField.stringValue = e.name
|
||||
topicField.stringValue = e.topic
|
||||
if e.parentId != 0 {
|
||||
for item in parentPicker.itemArray where (item.representedObject as? UInt32) == e.parentId {
|
||||
parentPicker.select(item); break
|
||||
}
|
||||
}
|
||||
pwCheckbox.state = e.passwordProtected ? .on : .off
|
||||
pwField.isEnabled = e.passwordProtected
|
||||
maxUsersField.stringValue = "\(e.maxUsers)"
|
||||
sortOrderField.stringValue = "\(e.sortOrder)"
|
||||
stereoCheckbox.state = e.audio.stereo ? .on : .off
|
||||
bitrateField.stringValue = "\(e.audio.bitrateBps)"
|
||||
fecCheckbox.state = e.audio.fec ? .on : .off
|
||||
dtxCheckbox.state = e.audio.dtx ? .on : .off
|
||||
let frameStr = "\(e.audio.frameMs) ms"
|
||||
if let item = frameMsPicker.item(withTitle: frameStr) { frameMsPicker.select(item) }
|
||||
}
|
||||
|
||||
@objc private func pwToggled() {
|
||||
pwField.isEnabled = pwCheckbox.state == .on
|
||||
}
|
||||
|
||||
@objc private func saveClicked() {
|
||||
let name = nameField.stringValue.trimmingCharacters(in: .whitespaces)
|
||||
guard !name.isEmpty else { nameField.becomeFirstResponder(); return }
|
||||
|
||||
let parentId = parentPicker.selectedItem?.representedObject as? UInt32 ?? 0
|
||||
let maxUsers = UInt32(maxUsersField.stringValue) ?? 0
|
||||
let sortOrder = UInt32(sortOrderField.stringValue) ?? 0
|
||||
let bitrate = UInt32(bitrateField.stringValue) ?? 64000
|
||||
let frameMsStr = frameMsPicker.titleOfSelectedItem?.replacingOccurrences(of: " ms", with: "") ?? "20"
|
||||
let frameMs = UInt32(frameMsStr) ?? 20
|
||||
|
||||
let audio = AudioConfig(
|
||||
stereo: stereoCheckbox.state == .on,
|
||||
bitrateBps: bitrate,
|
||||
frameMs: frameMs,
|
||||
fec: fecCheckbox.state == .on,
|
||||
dtx: dtxCheckbox.state == .on
|
||||
)
|
||||
let pwProtected = pwCheckbox.state == .on
|
||||
let pw: String? = pwProtected ? (pwField.stringValue.isEmpty ? nil : pwField.stringValue) : nil
|
||||
|
||||
let result = ChannelEdit(
|
||||
id: editing?.id ?? 0,
|
||||
parentId: parentId,
|
||||
name: name,
|
||||
topic: topicField.stringValue,
|
||||
passwordProtected: pwProtected,
|
||||
password: pw,
|
||||
maxUsers: maxUsers,
|
||||
sortOrder: sortOrder,
|
||||
audio: audio
|
||||
)
|
||||
dismiss(nil)
|
||||
onComplete?(result)
|
||||
}
|
||||
|
||||
@objc private func cancelClicked() {
|
||||
dismiss(nil)
|
||||
onComplete?(nil)
|
||||
}
|
||||
}
|
||||
79
clients/apple/macOS/VoiceCatMac/Sheets/InputSheet.swift
Normal file
79
clients/apple/macOS/VoiceCatMac/Sheets/InputSheet.swift
Normal file
@@ -0,0 +1,79 @@
|
||||
import AppKit
|
||||
|
||||
final class InputSheet: NSViewController {
|
||||
|
||||
var onComplete: ((String?) -> Void)?
|
||||
|
||||
private let sheetTitle: String
|
||||
private let prompt: String
|
||||
private let defaultValue: String
|
||||
private let inputField = NSTextField()
|
||||
|
||||
init(title: String, prompt: String, defaultValue: String = "") {
|
||||
self.sheetTitle = title
|
||||
self.prompt = prompt
|
||||
self.defaultValue = defaultValue
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) { fatalError() }
|
||||
|
||||
override func loadView() {
|
||||
view = NSView(frame: NSRect(x: 0, y: 0, width: 320, height: 120))
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
buildUI()
|
||||
}
|
||||
|
||||
private func buildUI() {
|
||||
let titleLabel = NSTextField(labelWithString: sheetTitle)
|
||||
titleLabel.font = .boldSystemFont(ofSize: 13)
|
||||
|
||||
let promptLabel = NSTextField(labelWithString: prompt)
|
||||
promptLabel.setAccessibilityLabel(prompt)
|
||||
|
||||
inputField.stringValue = defaultValue
|
||||
inputField.setAccessibilityLabel(prompt)
|
||||
inputField.target = self; inputField.action = #selector(okClicked)
|
||||
|
||||
let cancelButton = NSButton(title: "Cancel", target: self, action: #selector(cancelClicked))
|
||||
cancelButton.bezelStyle = .rounded
|
||||
|
||||
let okButton = NSButton(title: "OK", target: self, action: #selector(okClicked))
|
||||
okButton.bezelStyle = .rounded; okButton.keyEquivalent = "\r"
|
||||
|
||||
let buttonRow = NSStackView(views: [NSView(), cancelButton, okButton])
|
||||
buttonRow.orientation = .horizontal; buttonRow.spacing = 8
|
||||
|
||||
let stack = NSStackView(views: [titleLabel, promptLabel, inputField, buttonRow])
|
||||
stack.orientation = .vertical; stack.spacing = 8
|
||||
stack.edgeInsets = NSEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
|
||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(stack)
|
||||
NSLayoutConstraint.activate([
|
||||
stack.topAnchor.constraint(equalTo: view.topAnchor),
|
||||
stack.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
stack.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||
stack.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
||||
])
|
||||
}
|
||||
|
||||
override func viewDidAppear() {
|
||||
super.viewDidAppear()
|
||||
inputField.becomeFirstResponder()
|
||||
inputField.selectText(nil)
|
||||
}
|
||||
|
||||
@objc private func okClicked() {
|
||||
let value = inputField.stringValue
|
||||
dismiss(nil)
|
||||
onComplete?(value)
|
||||
}
|
||||
|
||||
@objc private func cancelClicked() {
|
||||
dismiss(nil)
|
||||
onComplete?(nil)
|
||||
}
|
||||
}
|
||||
73
clients/apple/macOS/VoiceCatMac/Sheets/MoveUserSheet.swift
Normal file
73
clients/apple/macOS/VoiceCatMac/Sheets/MoveUserSheet.swift
Normal file
@@ -0,0 +1,73 @@
|
||||
import AppKit
|
||||
import VoiceCatCore
|
||||
|
||||
final class MoveUserSheet: NSViewController {
|
||||
|
||||
var onComplete: ((UInt32?) -> Void)?
|
||||
|
||||
private let channels: [Channel]
|
||||
private let currentChannelId: UInt32
|
||||
private let picker = NSPopUpButton()
|
||||
|
||||
init(channels: [Channel], currentChannelId: UInt32) {
|
||||
self.channels = channels.sorted(by: { $0.name < $1.name })
|
||||
self.currentChannelId = currentChannelId
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) { fatalError() }
|
||||
|
||||
override func loadView() {
|
||||
view = NSView(frame: NSRect(x: 0, y: 0, width: 300, height: 100))
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
buildUI()
|
||||
}
|
||||
|
||||
private func buildUI() {
|
||||
let label = NSTextField(labelWithString: "Move user to channel:")
|
||||
label.setAccessibilityLabel("Select destination channel")
|
||||
|
||||
for ch in channels where ch.id != currentChannelId {
|
||||
let item = NSMenuItem(title: ch.name, action: nil, keyEquivalent: "")
|
||||
item.representedObject = ch.id
|
||||
picker.menu?.addItem(item)
|
||||
}
|
||||
picker.setAccessibilityLabel("Destination channel")
|
||||
|
||||
let cancelButton = NSButton(title: "Cancel", target: self, action: #selector(cancelClicked))
|
||||
cancelButton.bezelStyle = .rounded
|
||||
|
||||
let moveButton = NSButton(title: "Move", target: self, action: #selector(moveClicked))
|
||||
moveButton.bezelStyle = .rounded; moveButton.keyEquivalent = "\r"
|
||||
moveButton.setAccessibilityLabel("Move user to selected channel")
|
||||
|
||||
let buttonRow = NSStackView(views: [NSView(), cancelButton, moveButton])
|
||||
buttonRow.orientation = .horizontal; buttonRow.spacing = 8
|
||||
|
||||
let stack = NSStackView(views: [label, picker, buttonRow])
|
||||
stack.orientation = .vertical; stack.spacing = 10
|
||||
stack.edgeInsets = NSEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
|
||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(stack)
|
||||
NSLayoutConstraint.activate([
|
||||
stack.topAnchor.constraint(equalTo: view.topAnchor),
|
||||
stack.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
stack.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||
stack.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
||||
])
|
||||
}
|
||||
|
||||
@objc private func moveClicked() {
|
||||
let channelId = picker.selectedItem?.representedObject as? UInt32
|
||||
dismiss(nil)
|
||||
onComplete?(channelId)
|
||||
}
|
||||
|
||||
@objc private func cancelClicked() {
|
||||
dismiss(nil)
|
||||
onComplete?(nil)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import AppKit
|
||||
|
||||
final class PasswordPromptSheet: NSViewController {
|
||||
|
||||
var onComplete: ((String?) -> Void)?
|
||||
|
||||
private let prompt: String
|
||||
private let passwordField = NSSecureTextField()
|
||||
|
||||
init(prompt: String) {
|
||||
self.prompt = prompt
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) { fatalError() }
|
||||
|
||||
override func loadView() {
|
||||
view = NSView(frame: NSRect(x: 0, y: 0, width: 320, height: 110))
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
buildUI()
|
||||
}
|
||||
|
||||
private func buildUI() {
|
||||
let promptLabel = NSTextField(labelWithString: prompt)
|
||||
promptLabel.lineBreakMode = .byWordWrapping
|
||||
promptLabel.setAccessibilityLabel(prompt)
|
||||
|
||||
passwordField.placeholderString = "password"
|
||||
passwordField.setAccessibilityLabel("Password")
|
||||
passwordField.target = self; passwordField.action = #selector(okClicked)
|
||||
|
||||
let cancelButton = NSButton(title: "Cancel", target: self, action: #selector(cancelClicked))
|
||||
cancelButton.bezelStyle = .rounded
|
||||
cancelButton.setAccessibilityLabel("Cancel")
|
||||
|
||||
let okButton = NSButton(title: "OK", target: self, action: #selector(okClicked))
|
||||
okButton.bezelStyle = .rounded
|
||||
okButton.keyEquivalent = "\r"
|
||||
okButton.setAccessibilityLabel("Submit password")
|
||||
|
||||
let buttonRow = NSStackView(views: [NSView(), cancelButton, okButton])
|
||||
buttonRow.orientation = .horizontal; buttonRow.spacing = 8
|
||||
|
||||
let stack = NSStackView(views: [promptLabel, passwordField, buttonRow])
|
||||
stack.orientation = .vertical
|
||||
stack.spacing = 10
|
||||
stack.edgeInsets = NSEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
|
||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(stack)
|
||||
NSLayoutConstraint.activate([
|
||||
stack.topAnchor.constraint(equalTo: view.topAnchor),
|
||||
stack.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
stack.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||
stack.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
||||
])
|
||||
}
|
||||
|
||||
override func viewDidAppear() {
|
||||
super.viewDidAppear()
|
||||
passwordField.becomeFirstResponder()
|
||||
}
|
||||
|
||||
@objc private func okClicked() {
|
||||
let pw = passwordField.stringValue
|
||||
dismiss(nil)
|
||||
onComplete?(pw)
|
||||
}
|
||||
|
||||
@objc private func cancelClicked() {
|
||||
dismiss(nil)
|
||||
onComplete?(nil)
|
||||
}
|
||||
}
|
||||
123
clients/apple/macOS/VoiceCatMac/Sheets/PerUserTuningSheet.swift
Normal file
123
clients/apple/macOS/VoiceCatMac/Sheets/PerUserTuningSheet.swift
Normal file
@@ -0,0 +1,123 @@
|
||||
import AppKit
|
||||
import VoiceCatCore
|
||||
|
||||
final class PerUserTuningSheet: NSViewController {
|
||||
|
||||
private let client: VoiceCatClient
|
||||
private let userId: UInt32
|
||||
private let nickname: String
|
||||
|
||||
private var streams: [StreamSummary] = []
|
||||
private var rows: [StreamRow] = []
|
||||
|
||||
private struct StreamRow {
|
||||
let streamId: UInt32
|
||||
let label: String
|
||||
let gainSlider: NSSlider
|
||||
let muteCheckbox: NSButton
|
||||
let nrCheckbox: NSButton
|
||||
}
|
||||
|
||||
init(client: VoiceCatClient, userId: UInt32, nickname: String) {
|
||||
self.client = client
|
||||
self.userId = userId
|
||||
self.nickname = nickname
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) { fatalError() }
|
||||
|
||||
override func loadView() {
|
||||
view = NSView(frame: NSRect(x: 0, y: 0, width: 400, height: 200))
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
streams = client.listUserStreams(userId)
|
||||
buildUI()
|
||||
}
|
||||
|
||||
private func buildUI() {
|
||||
let titleLabel = NSTextField(labelWithString: "Volume & Noise Settings — \(nickname)")
|
||||
titleLabel.font = .boldSystemFont(ofSize: 13)
|
||||
|
||||
var rowViews: [NSView] = [titleLabel]
|
||||
|
||||
for stream in streams {
|
||||
let (_, state) = client.getRemoteStream(userId: userId, streamId: stream.id)
|
||||
let gain = state?.gain ?? 1.0
|
||||
let muted = state?.muted ?? false
|
||||
let nr = state?.noiseReduction ?? false
|
||||
|
||||
let gainSlider = NSSlider(value: Double(gain * 100), minValue: 0, maxValue: 200, target: self, action: #selector(sliderChanged))
|
||||
gainSlider.tag = Int(stream.id)
|
||||
gainSlider.numberOfTickMarks = 0
|
||||
gainSlider.setAccessibilityLabel("Volume for \(stream.label): \(Int(gain * 100)) percent")
|
||||
|
||||
let muteCheckbox = NSButton(checkboxWithTitle: "Mute", target: self, action: #selector(muteChanged))
|
||||
muteCheckbox.state = muted ? .on : .off
|
||||
muteCheckbox.tag = Int(stream.id)
|
||||
muteCheckbox.setAccessibilityLabel("Mute \(stream.label)")
|
||||
|
||||
let nrCheckbox = NSButton(checkboxWithTitle: "Noise reduction", target: self, action: #selector(nrChanged))
|
||||
nrCheckbox.state = nr ? .on : .off
|
||||
nrCheckbox.tag = Int(stream.id)
|
||||
nrCheckbox.setAccessibilityLabel("Noise reduction for \(stream.label)")
|
||||
|
||||
let streamLabel = NSTextField(labelWithString: "\(stream.label):")
|
||||
let gainLabel = NSTextField(labelWithString: "Volume:")
|
||||
let row = NSStackView(views: [streamLabel, gainLabel, gainSlider, muteCheckbox, nrCheckbox])
|
||||
row.orientation = .horizontal; row.spacing = 8
|
||||
rowViews.append(row)
|
||||
|
||||
rows.append(StreamRow(streamId: stream.id, label: stream.label,
|
||||
gainSlider: gainSlider, muteCheckbox: muteCheckbox,
|
||||
nrCheckbox: nrCheckbox))
|
||||
}
|
||||
|
||||
if streams.isEmpty {
|
||||
rowViews.append(NSTextField(labelWithString: "This user has no active streams."))
|
||||
}
|
||||
|
||||
let doneButton = NSButton(title: "Done", target: self, action: #selector(doneClicked))
|
||||
doneButton.bezelStyle = .rounded; doneButton.keyEquivalent = "\r"
|
||||
doneButton.setAccessibilityLabel("Close settings")
|
||||
rowViews.append(NSStackView(views: [NSView(), doneButton]))
|
||||
|
||||
let stack = NSStackView(views: rowViews)
|
||||
stack.orientation = .vertical
|
||||
stack.spacing = 10
|
||||
stack.edgeInsets = NSEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
|
||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(stack)
|
||||
NSLayoutConstraint.activate([
|
||||
stack.topAnchor.constraint(equalTo: view.topAnchor),
|
||||
stack.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
stack.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||
])
|
||||
}
|
||||
|
||||
@objc private func sliderChanged(_ sender: NSSlider) {
|
||||
apply(streamId: UInt32(sender.tag))
|
||||
}
|
||||
|
||||
@objc private func muteChanged(_ sender: NSButton) {
|
||||
apply(streamId: UInt32(sender.tag))
|
||||
}
|
||||
|
||||
@objc private func nrChanged(_ sender: NSButton) {
|
||||
apply(streamId: UInt32(sender.tag))
|
||||
}
|
||||
|
||||
private func apply(streamId: UInt32) {
|
||||
guard let row = rows.first(where: { $0.streamId == streamId }) else { return }
|
||||
let gain = Float(row.gainSlider.doubleValue) / 100.0
|
||||
let muted = row.muteCheckbox.state == .on
|
||||
let nr = row.nrCheckbox.state == .on
|
||||
client.setRemoteStream(userId: userId, streamId: streamId,
|
||||
gain: gain, muted: muted, noiseReduction: nr)
|
||||
row.gainSlider.setAccessibilityLabel("Volume for \(row.label): \(Int(row.gainSlider.doubleValue)) percent")
|
||||
}
|
||||
|
||||
@objc private func doneClicked() { dismiss(nil) }
|
||||
}
|
||||
100
clients/apple/macOS/VoiceCatMac/Sheets/PermissionsSheet.swift
Normal file
100
clients/apple/macOS/VoiceCatMac/Sheets/PermissionsSheet.swift
Normal file
@@ -0,0 +1,100 @@
|
||||
import AppKit
|
||||
import VoiceCatCore
|
||||
|
||||
final class PermissionsSheet: NSViewController {
|
||||
|
||||
var onComplete: ((Permissions?) -> Void)?
|
||||
|
||||
private let targetNickname: String
|
||||
private let initial: Permissions
|
||||
|
||||
private let canCreateTempChannelCB = NSButton(checkboxWithTitle: "Create temporary channels", target: nil, action: nil)
|
||||
private let canKickCB = NSButton(checkboxWithTitle: "Kick users", target: nil, action: nil)
|
||||
private let canBanCB = NSButton(checkboxWithTitle: "Ban users", target: nil, action: nil)
|
||||
private let canMoveUsersCB = NSButton(checkboxWithTitle: "Move users between channels", target: nil, action: nil)
|
||||
private let canAdminAccountsCB = NSButton(checkboxWithTitle: "Manage accounts", target: nil, action: nil)
|
||||
private let isAdminCB = NSButton(checkboxWithTitle: "Full administrator", target: nil, action: nil)
|
||||
|
||||
init(nickname: String, current: Permissions) {
|
||||
self.targetNickname = nickname
|
||||
self.initial = current
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) { fatalError() }
|
||||
|
||||
override func loadView() {
|
||||
view = NSView(frame: NSRect(x: 0, y: 0, width: 340, height: 250))
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
buildUI()
|
||||
applyInitial()
|
||||
}
|
||||
|
||||
private func buildUI() {
|
||||
let titleLabel = NSTextField(labelWithString: "Permissions — \(targetNickname)")
|
||||
titleLabel.font = .boldSystemFont(ofSize: 13)
|
||||
|
||||
let checkboxes = [canCreateTempChannelCB, canKickCB, canBanCB,
|
||||
canMoveUsersCB, canAdminAccountsCB, isAdminCB]
|
||||
for cb in checkboxes {
|
||||
cb.setAccessibilityLabel(cb.title)
|
||||
}
|
||||
|
||||
let cancelButton = NSButton(title: "Cancel", target: self, action: #selector(cancelClicked))
|
||||
cancelButton.bezelStyle = .rounded
|
||||
|
||||
let saveButton = NSButton(title: "Save", target: self, action: #selector(saveClicked))
|
||||
saveButton.bezelStyle = .rounded; saveButton.keyEquivalent = "\r"
|
||||
saveButton.setAccessibilityLabel("Save permissions for \(targetNickname)")
|
||||
|
||||
let buttonRow = NSStackView(views: [NSView(), cancelButton, saveButton])
|
||||
buttonRow.orientation = .horizontal; buttonRow.spacing = 8
|
||||
|
||||
var views: [NSView] = [titleLabel]
|
||||
views.append(contentsOf: checkboxes)
|
||||
views.append(buttonRow)
|
||||
|
||||
let stack = NSStackView(views: views)
|
||||
stack.orientation = .vertical; stack.spacing = 8
|
||||
stack.alignment = .leading
|
||||
stack.edgeInsets = NSEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
|
||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(stack)
|
||||
NSLayoutConstraint.activate([
|
||||
stack.topAnchor.constraint(equalTo: view.topAnchor),
|
||||
stack.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
stack.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||
stack.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
||||
])
|
||||
}
|
||||
|
||||
private func applyInitial() {
|
||||
canCreateTempChannelCB.state = initial.canCreateTempChannel ? .on : .off
|
||||
canKickCB.state = initial.canKick ? .on : .off
|
||||
canBanCB.state = initial.canBan ? .on : .off
|
||||
canMoveUsersCB.state = initial.canMoveUsers ? .on : .off
|
||||
canAdminAccountsCB.state = initial.canAdminAccounts ? .on : .off
|
||||
isAdminCB.state = initial.isAdmin ? .on : .off
|
||||
}
|
||||
|
||||
@objc private func saveClicked() {
|
||||
let perms = Permissions(
|
||||
canCreateTempChannel: canCreateTempChannelCB.state == .on,
|
||||
canKick: canKickCB.state == .on,
|
||||
canBan: canBanCB.state == .on,
|
||||
canMoveUsers: canMoveUsersCB.state == .on,
|
||||
canAdminAccounts: canAdminAccountsCB.state == .on,
|
||||
isAdmin: isAdminCB.state == .on
|
||||
)
|
||||
dismiss(nil)
|
||||
onComplete?(perms)
|
||||
}
|
||||
|
||||
@objc private func cancelClicked() {
|
||||
dismiss(nil)
|
||||
onComplete?(nil)
|
||||
}
|
||||
}
|
||||
113
clients/apple/macOS/VoiceCatMac/Sheets/PttKeyCaptureSheet.swift
Normal file
113
clients/apple/macOS/VoiceCatMac/Sheets/PttKeyCaptureSheet.swift
Normal file
@@ -0,0 +1,113 @@
|
||||
import AppKit
|
||||
|
||||
final class PttKeyCaptureSheet: NSViewController {
|
||||
|
||||
var onComplete: ((UInt16?) -> Void)?
|
||||
|
||||
private let currentKeyCode: UInt16
|
||||
private var capturedKeyCode: UInt16?
|
||||
private let instructionLabel = NSTextField(labelWithString: "Press the key you want to use for push-to-talk…")
|
||||
private let captureView = KeyCaptureView()
|
||||
|
||||
init(currentKeyCode: UInt16) {
|
||||
self.currentKeyCode = currentKeyCode
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) { fatalError() }
|
||||
|
||||
override func loadView() {
|
||||
view = NSView(frame: NSRect(x: 0, y: 0, width: 320, height: 140))
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
buildUI()
|
||||
}
|
||||
|
||||
private func buildUI() {
|
||||
let titleLabel = NSTextField(labelWithString: "Set Push-to-Talk Key")
|
||||
titleLabel.font = .boldSystemFont(ofSize: 13)
|
||||
|
||||
instructionLabel.textColor = .secondaryLabelColor
|
||||
instructionLabel.lineBreakMode = .byWordWrapping
|
||||
instructionLabel.setAccessibilityLabel("Waiting for key press")
|
||||
|
||||
captureView.setAccessibilityLabel("Key capture area — press any key")
|
||||
captureView.setAccessibilityRole(.textArea)
|
||||
captureView.onKeyPressed = { [weak self] keyCode in
|
||||
self?.capturedKeyCode = keyCode
|
||||
self?.instructionLabel.stringValue = "Key captured: \(keyCodeName(keyCode)). Click Set to confirm."
|
||||
}
|
||||
|
||||
let cancelButton = NSButton(title: "Cancel", target: self, action: #selector(cancelClicked))
|
||||
cancelButton.bezelStyle = .rounded
|
||||
|
||||
let setButton = NSButton(title: "Set", target: self, action: #selector(setClicked))
|
||||
setButton.bezelStyle = .rounded; setButton.keyEquivalent = "\r"
|
||||
setButton.setAccessibilityLabel("Set captured key as PTT key")
|
||||
|
||||
let buttonRow = NSStackView(views: [NSView(), cancelButton, setButton])
|
||||
buttonRow.orientation = .horizontal; buttonRow.spacing = 8
|
||||
|
||||
captureView.translatesAutoresizingMaskIntoConstraints = false
|
||||
captureView.wantsLayer = true
|
||||
captureView.layer?.backgroundColor = NSColor.controlBackgroundColor.cgColor
|
||||
captureView.layer?.cornerRadius = 4
|
||||
|
||||
let stack = NSStackView(views: [titleLabel, instructionLabel, captureView, buttonRow])
|
||||
stack.orientation = .vertical; stack.spacing = 10
|
||||
stack.edgeInsets = NSEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
|
||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(stack)
|
||||
NSLayoutConstraint.activate([
|
||||
stack.topAnchor.constraint(equalTo: view.topAnchor),
|
||||
stack.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
stack.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||
stack.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
||||
captureView.heightAnchor.constraint(equalToConstant: 28),
|
||||
])
|
||||
}
|
||||
|
||||
override func viewDidAppear() {
|
||||
super.viewDidAppear()
|
||||
view.window?.makeFirstResponder(captureView)
|
||||
}
|
||||
|
||||
@objc private func setClicked() {
|
||||
let key = capturedKeyCode
|
||||
dismiss(nil)
|
||||
onComplete?(key)
|
||||
}
|
||||
|
||||
@objc private func cancelClicked() {
|
||||
dismiss(nil)
|
||||
onComplete?(nil)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Key capture view
|
||||
|
||||
private final class KeyCaptureView: NSView {
|
||||
var onKeyPressed: ((UInt16) -> Void)?
|
||||
override var acceptsFirstResponder: Bool { true }
|
||||
|
||||
override func keyDown(with event: NSEvent) {
|
||||
onKeyPressed?(event.keyCode)
|
||||
}
|
||||
|
||||
override func drawFocusRingMask() {
|
||||
NSBezierPath(roundedRect: bounds, xRadius: 4, yRadius: 4).fill()
|
||||
}
|
||||
override var focusRingMaskBounds: NSRect { bounds }
|
||||
}
|
||||
|
||||
private func keyCodeName(_ keyCode: UInt16) -> String {
|
||||
let map: [UInt16: String] = [
|
||||
0x60: "F5", 0x61: "F6", 0x62: "F7", 0x63: "F3", 0x64: "F8", 0x65: "F9",
|
||||
0x67: "F11", 0x69: "F13", 0x6A: "F16", 0x6B: "F14", 0x6D: "F10", 0x6F: "F12",
|
||||
0x71: "F15", 0x72: "Help", 0x73: "Home", 0x74: "PgUp", 0x75: "Del",
|
||||
0x76: "F4", 0x77: "End", 0x78: "F2", 0x79: "PgDn", 0x7A: "F1",
|
||||
]
|
||||
return map[keyCode] ?? "Key\(keyCode)"
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
import AppKit
|
||||
import VoiceCatCore
|
||||
|
||||
final class ServerIdentitySheet: NSViewController {
|
||||
|
||||
var onComplete: ((Bool) -> Void)?
|
||||
|
||||
private let tofuStatus: VoiceCatTofuStatus
|
||||
private let displayFingerprint: String
|
||||
|
||||
init(tofuStatus: VoiceCatTofuStatus, displayFingerprint: String) {
|
||||
self.tofuStatus = tofuStatus
|
||||
self.displayFingerprint = displayFingerprint
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) { fatalError() }
|
||||
|
||||
override func loadView() {
|
||||
view = NSView(frame: NSRect(x: 0, y: 0, width: 440, height: 220))
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
buildUI()
|
||||
}
|
||||
|
||||
private func buildUI() {
|
||||
let isMismatch = tofuStatus == .mismatch
|
||||
let titleText = isMismatch ? "Server Identity Mismatch — Possible MITM!" : "New Server Identity"
|
||||
let titleLabel = NSTextField(labelWithString: titleText)
|
||||
titleLabel.font = .boldSystemFont(ofSize: 14)
|
||||
if isMismatch { titleLabel.textColor = .systemRed }
|
||||
titleLabel.setAccessibilityLabel(titleText)
|
||||
|
||||
let bodyText: String
|
||||
if isMismatch {
|
||||
bodyText = "The server's identity has changed since you last connected. This may indicate a man-in-the-middle attack or that the server was reinstalled. Do NOT accept unless you know why the identity changed."
|
||||
} else {
|
||||
bodyText = "This is the first time you are connecting to this server. Verify the fingerprint below with the server administrator before accepting."
|
||||
}
|
||||
let bodyLabel = NSTextField(wrappingLabelWithString: bodyText)
|
||||
bodyLabel.textColor = .labelColor
|
||||
|
||||
let fpLabel = NSTextField(labelWithString: "Server fingerprint:")
|
||||
let fpField = NSTextField(labelWithString: displayFingerprint.isEmpty ? "(not available)" : displayFingerprint)
|
||||
fpField.font = NSFont.monospacedSystemFont(ofSize: 11, weight: .regular)
|
||||
fpField.isSelectable = true
|
||||
fpField.setAccessibilityLabel("Server identity fingerprint: \(displayFingerprint)")
|
||||
|
||||
let rejectButton = NSButton(title: "Reject (Disconnect)", target: self, action: #selector(rejectClicked))
|
||||
rejectButton.bezelStyle = .rounded
|
||||
rejectButton.setAccessibilityLabel("Reject server identity and disconnect")
|
||||
if isMismatch { rejectButton.keyEquivalent = "\r" }
|
||||
|
||||
let acceptButton = NSButton(title: "Accept", target: self, action: #selector(acceptClicked))
|
||||
acceptButton.bezelStyle = .rounded
|
||||
if !isMismatch { acceptButton.keyEquivalent = "\r" }
|
||||
acceptButton.setAccessibilityLabel("Accept server identity and continue connecting")
|
||||
|
||||
let buttonRow = NSStackView(views: [NSView(), rejectButton, acceptButton])
|
||||
buttonRow.orientation = .horizontal; buttonRow.spacing = 8
|
||||
|
||||
let fpRow = NSStackView(views: [fpLabel, fpField])
|
||||
fpRow.orientation = .horizontal; fpRow.spacing = 8
|
||||
|
||||
let stack = NSStackView(views: [titleLabel, bodyLabel, fpRow, buttonRow])
|
||||
stack.orientation = .vertical
|
||||
stack.spacing = 12
|
||||
stack.edgeInsets = NSEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)
|
||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(stack)
|
||||
NSLayoutConstraint.activate([
|
||||
stack.topAnchor.constraint(equalTo: view.topAnchor),
|
||||
stack.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
stack.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||
stack.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
||||
])
|
||||
}
|
||||
|
||||
@objc private func acceptClicked() {
|
||||
dismiss(nil)
|
||||
onComplete?(true)
|
||||
}
|
||||
|
||||
@objc private func rejectClicked() {
|
||||
dismiss(nil)
|
||||
onComplete?(false)
|
||||
}
|
||||
}
|
||||
6
clients/apple/macOS/VoiceCatMac/VoiceCatMac.entitlements
Normal file
6
clients/apple/macOS/VoiceCatMac/VoiceCatMac.entitlements
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,380 @@
|
||||
import AppKit
|
||||
import VoiceCatCore
|
||||
|
||||
final class ConnectWindowController: NSWindowController, NSWindowDelegate {
|
||||
|
||||
// MARK: - UI
|
||||
|
||||
private let serverTableView = NSTableView()
|
||||
private let serverScrollView = NSScrollView()
|
||||
private let addButton = NSButton()
|
||||
private let editButton = NSButton()
|
||||
private let removeButton = NSButton()
|
||||
private let connectButton = NSButton()
|
||||
private let statusLabel = NSTextField(labelWithString: "Select a server and click Connect.")
|
||||
|
||||
// MARK: - State
|
||||
|
||||
private var servers: [SavedServer] = ServerListStore.load()
|
||||
private var client: VoiceCatClient?
|
||||
private var identityDialogShown = false
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
init() {
|
||||
let window = NSWindow(
|
||||
contentRect: NSRect(x: 0, y: 0, width: 420, height: 320),
|
||||
styleMask: [.titled, .closable, .miniaturizable],
|
||||
backing: .buffered,
|
||||
defer: false
|
||||
)
|
||||
window.title = "VoiceCat — Connect"
|
||||
window.center()
|
||||
super.init(window: window)
|
||||
window.delegate = self
|
||||
buildUI()
|
||||
refreshServerList()
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) { fatalError() }
|
||||
|
||||
// MARK: - UI construction
|
||||
|
||||
private func buildUI() {
|
||||
guard let contentView = window?.contentView else { return }
|
||||
|
||||
// Server list
|
||||
let col = NSTableColumn(identifier: NSUserInterfaceItemIdentifier("server"))
|
||||
col.title = "Saved Servers"
|
||||
serverTableView.addTableColumn(col)
|
||||
serverTableView.headerView = nil
|
||||
serverTableView.dataSource = self
|
||||
serverTableView.delegate = self
|
||||
serverTableView.doubleAction = #selector(connectClicked)
|
||||
serverTableView.target = self
|
||||
serverTableView.setAccessibilityLabel("Saved servers")
|
||||
|
||||
serverScrollView.documentView = serverTableView
|
||||
serverScrollView.hasVerticalScroller = true
|
||||
serverScrollView.borderType = .bezelBorder
|
||||
serverScrollView.translatesAutoresizingMaskIntoConstraints = false
|
||||
contentView.addSubview(serverScrollView)
|
||||
|
||||
// Buttons row
|
||||
configureButton(addButton, title: "Add…", action: #selector(addClicked))
|
||||
configureButton(editButton, title: "Edit…", action: #selector(editClicked))
|
||||
configureButton(removeButton, title: "Remove", action: #selector(removeClicked))
|
||||
|
||||
let buttonStack = NSStackView(views: [addButton, editButton, removeButton, NSView()])
|
||||
buttonStack.orientation = .horizontal
|
||||
buttonStack.spacing = 8
|
||||
buttonStack.translatesAutoresizingMaskIntoConstraints = false
|
||||
contentView.addSubview(buttonStack)
|
||||
|
||||
// Status
|
||||
statusLabel.translatesAutoresizingMaskIntoConstraints = false
|
||||
statusLabel.textColor = .secondaryLabelColor
|
||||
statusLabel.setAccessibilityLabel("Connection status")
|
||||
contentView.addSubview(statusLabel)
|
||||
|
||||
// Connect button
|
||||
connectButton.title = "Connect"
|
||||
connectButton.bezelStyle = .rounded
|
||||
connectButton.keyEquivalent = "\r"
|
||||
connectButton.target = self
|
||||
connectButton.action = #selector(connectClicked)
|
||||
connectButton.translatesAutoresizingMaskIntoConstraints = false
|
||||
connectButton.setAccessibilityLabel("Connect to selected server")
|
||||
contentView.addSubview(connectButton)
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
serverScrollView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 12),
|
||||
serverScrollView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 12),
|
||||
serverScrollView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -12),
|
||||
serverScrollView.bottomAnchor.constraint(equalTo: buttonStack.topAnchor, constant: -8),
|
||||
|
||||
buttonStack.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 12),
|
||||
buttonStack.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -12),
|
||||
buttonStack.bottomAnchor.constraint(equalTo: statusLabel.topAnchor, constant: -12),
|
||||
|
||||
statusLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 12),
|
||||
statusLabel.trailingAnchor.constraint(equalTo: connectButton.leadingAnchor, constant: -8),
|
||||
statusLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -16),
|
||||
|
||||
connectButton.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -12),
|
||||
connectButton.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -12),
|
||||
connectButton.widthAnchor.constraint(equalToConstant: 90),
|
||||
])
|
||||
}
|
||||
|
||||
private func configureButton(_ button: NSButton, title: String, action: Selector) {
|
||||
button.title = title
|
||||
button.bezelStyle = .rounded
|
||||
button.target = self
|
||||
button.action = action
|
||||
button.translatesAutoresizingMaskIntoConstraints = false
|
||||
}
|
||||
|
||||
// MARK: - Server list management
|
||||
|
||||
private func refreshServerList() {
|
||||
serverTableView.reloadData()
|
||||
updateButtonStates()
|
||||
}
|
||||
|
||||
private func updateButtonStates() {
|
||||
let hasSelection = serverTableView.selectedRow >= 0
|
||||
connectButton.isEnabled = hasSelection
|
||||
editButton.isEnabled = hasSelection
|
||||
removeButton.isEnabled = hasSelection
|
||||
}
|
||||
|
||||
@objc private func addClicked() {
|
||||
let sheet = AddServerSheet(editing: nil)
|
||||
sheet.onComplete = { [weak self] server in
|
||||
guard let self, let server else { return }
|
||||
self.servers.append(server)
|
||||
ServerListStore.save(self.servers)
|
||||
self.refreshServerList()
|
||||
let newRow = self.servers.count - 1
|
||||
self.serverTableView.selectRowIndexes(IndexSet(integer: newRow), byExtendingSelection: false)
|
||||
}
|
||||
presentSheet(sheet)
|
||||
}
|
||||
|
||||
@objc private func editClicked() {
|
||||
let row = serverTableView.selectedRow
|
||||
guard row >= 0 else { return }
|
||||
let existing = servers[row]
|
||||
let sheet = AddServerSheet(editing: existing)
|
||||
sheet.onComplete = { [weak self] server in
|
||||
guard let self, let server else { return }
|
||||
self.servers[row] = server
|
||||
ServerListStore.save(self.servers)
|
||||
self.refreshServerList()
|
||||
}
|
||||
presentSheet(sheet)
|
||||
}
|
||||
|
||||
@objc private func removeClicked() {
|
||||
let row = serverTableView.selectedRow
|
||||
guard row >= 0 else { return }
|
||||
let server = servers[row]
|
||||
let alert = NSAlert()
|
||||
alert.messageText = "Remove server?"
|
||||
alert.informativeText = "Remove '\(server.displayString)' from the saved-server list?"
|
||||
alert.addButton(withTitle: "Remove")
|
||||
alert.addButton(withTitle: "Cancel")
|
||||
alert.alertStyle = .warning
|
||||
guard let window else { return }
|
||||
alert.beginSheetModal(for: window) { [weak self] response in
|
||||
guard response == .alertFirstButtonReturn, let self else { return }
|
||||
if let tag = self.servers[row].keychainTag {
|
||||
ServerListStore.deletePassword(tag: tag)
|
||||
}
|
||||
self.servers.remove(at: row)
|
||||
ServerListStore.save(self.servers)
|
||||
self.refreshServerList()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Connect flow
|
||||
|
||||
@objc private func connectClicked() {
|
||||
let row = serverTableView.selectedRow
|
||||
guard row >= 0 else { return }
|
||||
startConnect(server: servers[row])
|
||||
}
|
||||
|
||||
private func startConnect(server: SavedServer) {
|
||||
setBusy(true)
|
||||
setStatus("Connecting…")
|
||||
|
||||
try? FileManager.default.createDirectory(atPath: ServerListStore.appSupportURL.path,
|
||||
withIntermediateDirectories: true)
|
||||
let config = VoiceCatConfig(
|
||||
clientName: "VoiceCat-macOS",
|
||||
clientVersion: "0.0.1",
|
||||
logLevel: .info,
|
||||
tofuStorePath: ServerListStore.tofuStorePath
|
||||
)
|
||||
let newClient = VoiceCatClient(config: config)
|
||||
client = newClient
|
||||
identityDialogShown = false
|
||||
|
||||
newClient.onEvent = { [weak self] event in
|
||||
self?.handleEvent(event, server: server)
|
||||
}
|
||||
|
||||
let connectResult = newClient.connect(host: server.host, port: server.port)
|
||||
guard connectResult == .ok else {
|
||||
setStatus("Connect failed: \(connectResult)")
|
||||
cleanupFailedAttempt()
|
||||
return
|
||||
}
|
||||
|
||||
switch server.authMode {
|
||||
case .guest:
|
||||
let nick = server.savedUsername?.isEmpty == false ? server.savedUsername! : NSFullUserName()
|
||||
newClient.authenticateGuest(nick)
|
||||
case .password:
|
||||
let username = server.savedUsername ?? ""
|
||||
if let tag = server.keychainTag, let password = ServerListStore.loadPassword(tag: tag) {
|
||||
newClient.authenticateUser(username, password: password)
|
||||
} else {
|
||||
let pwSheet = PasswordPromptSheet(prompt: "Password for \(username)@\(server.host):")
|
||||
pwSheet.onComplete = { [weak self, weak newClient] password in
|
||||
guard let self, let newClient else { return }
|
||||
guard let password else {
|
||||
self.setStatus("Cancelled.")
|
||||
self.cleanupFailedAttempt()
|
||||
return
|
||||
}
|
||||
newClient.authenticateUser(username, password: password)
|
||||
}
|
||||
presentSheet(pwSheet)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func handleEvent(_ event: VoiceCatEvent, server: SavedServer) {
|
||||
switch event.type {
|
||||
case .connectionState:
|
||||
let label: String
|
||||
switch event.connectionState {
|
||||
case .connecting: label = "Connecting…"
|
||||
case .tlsHandshake: label = "TLS handshake…"
|
||||
case .verifyingIdentity: label = "Verifying server identity…"
|
||||
case .authenticating: label = "Authenticating…"
|
||||
case .connected: label = "Connected."
|
||||
default: label = statusLabel.stringValue
|
||||
}
|
||||
setStatus(label)
|
||||
|
||||
case .serverIdentity:
|
||||
handleServerIdentity(tofuStatus: event.tofuStatus ?? .firstConnect,
|
||||
displayText: client?.getServerIdentityDisplay() ?? "")
|
||||
|
||||
case .authResult:
|
||||
if event.result == .ok {
|
||||
let nickname = server.authMode == .guest
|
||||
? (server.savedUsername?.isEmpty == false ? server.savedUsername! : NSFullUserName())
|
||||
: (server.savedUsername ?? "")
|
||||
authSucceeded(client: client!, selfUserId: event.userId, nickname: nickname)
|
||||
} else {
|
||||
setStatus("Authentication failed: \(event.text ?? event.result.description)")
|
||||
cleanupFailedAttempt()
|
||||
}
|
||||
|
||||
case .disconnected:
|
||||
if client != nil {
|
||||
setStatus(event.text.map { "Disconnected: \($0)" } ?? "Disconnected.")
|
||||
cleanupFailedAttempt()
|
||||
}
|
||||
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
private func handleServerIdentity(tofuStatus: VoiceCatTofuStatus, displayText: String) {
|
||||
if identityDialogShown { return }
|
||||
if tofuStatus == .matched {
|
||||
client?.confirmServerIdentity(accept: true)
|
||||
return
|
||||
}
|
||||
identityDialogShown = true
|
||||
let sheet = ServerIdentitySheet(tofuStatus: tofuStatus, displayFingerprint: displayText)
|
||||
sheet.onComplete = { [weak self] accepted in
|
||||
self?.client?.confirmServerIdentity(accept: accepted)
|
||||
if !accepted {
|
||||
self?.setStatus("Server identity rejected.")
|
||||
self?.cleanupFailedAttempt()
|
||||
}
|
||||
}
|
||||
presentSheet(sheet)
|
||||
}
|
||||
|
||||
private func authSucceeded(client: VoiceCatClient, selfUserId: UInt32, nickname: String) {
|
||||
client.onEvent = nil
|
||||
let mainWC = MainWindowController(client: client, selfUserId: selfUserId, nickname: nickname)
|
||||
mainWC.showWindow(nil)
|
||||
self.client = nil
|
||||
close()
|
||||
}
|
||||
|
||||
private func cleanupFailedAttempt() {
|
||||
client?.onEvent = nil
|
||||
client = nil
|
||||
setBusy(false)
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private func setStatus(_ text: String) {
|
||||
statusLabel.stringValue = text
|
||||
}
|
||||
|
||||
private func setBusy(_ busy: Bool) {
|
||||
serverTableView.isEnabled = !busy
|
||||
addButton.isEnabled = !busy
|
||||
connectButton.isEnabled = !busy && serverTableView.selectedRow >= 0
|
||||
editButton.isEnabled = !busy && serverTableView.selectedRow >= 0
|
||||
removeButton.isEnabled = !busy && serverTableView.selectedRow >= 0
|
||||
}
|
||||
|
||||
private func presentSheet(_ vc: NSViewController) {
|
||||
if let parent = window?.contentViewController {
|
||||
parent.presentAsSheet(vc)
|
||||
} else {
|
||||
let contentVC = NSViewController()
|
||||
contentVC.view = window!.contentView!
|
||||
window?.contentViewController = contentVC
|
||||
contentVC.presentAsSheet(vc)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - NSWindowDelegate
|
||||
|
||||
func windowWillClose(_ notification: Notification) {
|
||||
client?.onEvent = nil
|
||||
client = nil
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - NSTableViewDataSource / Delegate
|
||||
|
||||
extension ConnectWindowController: NSTableViewDataSource, NSTableViewDelegate {
|
||||
func numberOfRows(in tableView: NSTableView) -> Int { servers.count }
|
||||
|
||||
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
|
||||
let id = NSUserInterfaceItemIdentifier("serverCell")
|
||||
let cell = tableView.makeView(withIdentifier: id, owner: nil) as? NSTableCellView
|
||||
?? makeTableCellView(identifier: id)
|
||||
cell.textField?.stringValue = servers[row].displayString
|
||||
return cell
|
||||
}
|
||||
|
||||
func tableViewSelectionDidChange(_ notification: Notification) {
|
||||
updateButtonStates()
|
||||
}
|
||||
|
||||
private func makeTableCellView(identifier: NSUserInterfaceItemIdentifier) -> NSTableCellView {
|
||||
let cell = NSTableCellView()
|
||||
cell.identifier = identifier
|
||||
let tf = NSTextField(labelWithString: "")
|
||||
tf.translatesAutoresizingMaskIntoConstraints = false
|
||||
cell.addSubview(tf)
|
||||
cell.textField = tf
|
||||
NSLayoutConstraint.activate([
|
||||
tf.leadingAnchor.constraint(equalTo: cell.leadingAnchor, constant: 4),
|
||||
tf.trailingAnchor.constraint(equalTo: cell.trailingAnchor, constant: -4),
|
||||
tf.centerYAnchor.constraint(equalTo: cell.centerYAnchor),
|
||||
])
|
||||
return cell
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Helper
|
||||
|
||||
|
||||
1185
clients/apple/macOS/VoiceCatMac/Windows/MainWindowController.swift
Normal file
1185
clients/apple/macOS/VoiceCatMac/Windows/MainWindowController.swift
Normal file
File diff suppressed because it is too large
Load Diff
5
clients/apple/macOS/VoiceCatMac/main.swift
Normal file
5
clients/apple/macOS/VoiceCatMac/main.swift
Normal file
@@ -0,0 +1,5 @@
|
||||
import AppKit
|
||||
|
||||
let delegate = AppDelegate()
|
||||
NSApplication.shared.delegate = delegate
|
||||
NSApplication.shared.run()
|
||||
Reference in New Issue
Block a user