Voxley / app · voxley.si / Sources / Voxley / VoxleyAbout.swift
| 1 | import AppKit |
| 2 | import SwiftUI |
| 3 | |
| 4 | @MainActor |
| 5 | final class AboutWindow { |
| 6 | private var window: NSWindow? |
| 7 | |
| 8 | func show() { |
| 9 | if window == nil { |
| 10 | let window = NSPanel( |
| 11 | contentRect: NSRect(x: 0, y: 0, width: 510, height: 300), |
| 12 | styleMask: [.titled, .closable], backing: .buffered, defer: false |
| 13 | ) |
| 14 | window.title = "About Voxley" |
| 15 | window.isReleasedWhenClosed = false |
| 16 | window.contentView = NSHostingView(rootView: VoxleyAbout()) |
| 17 | window.center() |
| 18 | self.window = window |
| 19 | } |
| 20 | NSApp.activate() |
| 21 | window?.makeKeyAndOrderFront(nil) |
| 22 | window?.orderFrontRegardless() |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | struct VoxleyAbout: View { |
| 27 | private static let website = URL(string: "https://voxley.si/")! |
| 28 | |
| 29 | private var version: String { |
| 30 | Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "" |
| 31 | } |
| 32 | |
| 33 | private var appIcon: NSImage { |
| 34 | Bundle.main.url(forResource: "AppIcon", withExtension: "icns") |
| 35 | .flatMap(NSImage.init(contentsOf:)) ?? NSApp.applicationIconImage |
| 36 | } |
| 37 | |
| 38 | var body: some View { |
| 39 | ScrollView { |
| 40 | VStack(alignment: .leading, spacing: 16) { |
| 41 | HStack(spacing: 14) { |
| 42 | Image(nsImage: appIcon) |
| 43 | .resizable().scaledToFit().frame(width: 62, height: 62) |
| 44 | .accessibilityHidden(true) |
| 45 | VStack(alignment: .leading, spacing: 3) { |
| 46 | Text("Voxley").font(.largeTitle.weight(.semibold)) |
| 47 | Text("Version \(version)") |
| 48 | .foregroundStyle(.secondary) |
| 49 | } |
| 50 | } |
| 51 | Text("Private dictation for Mac. Speak wherever you type, with transcription on your device.") |
| 52 | .fixedSize(horizontal: false, vertical: true) |
| 53 | |
| 54 | VStack(alignment: .leading, spacing: 8) { |
| 55 | Text("Follow Voxley").font(.headline) |
| 56 | followLink("Website", icon: "globe", destination: Self.website) |
| 57 | } |
| 58 | } |
| 59 | .padding(24) |
| 60 | .frame(maxWidth: 540, alignment: .leading) |
| 61 | .frame(maxWidth: .infinity) |
| 62 | } |
| 63 | .background(.black) |
| 64 | .tint(.voxleyAccent) |
| 65 | } |
| 66 | |
| 67 | private func followLink(_ title: LocalizedStringKey, icon: String, destination: URL) -> some View { |
| 68 | Link(destination: destination) { |
| 69 | Label { |
| 70 | Text(title) |
| 71 | .foregroundStyle(Color.voxleyAccent) |
| 72 | } icon: { |
| 73 | Image(systemName: icon) |
| 74 | .foregroundStyle(Color.voxleyAccent) |
| 75 | } |
| 76 | .font(.callout.weight(.medium)) |
| 77 | .padding(.horizontal, 12) |
| 78 | .frame(minHeight: 34) |
| 79 | .glassEffect(.regular.interactive(), in: Capsule()) |
| 80 | .contentShape(Capsule()) |
| 81 | } |
| 82 | .buttonStyle(.plain) |
| 83 | } |
| 84 | } |