Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/nova-desktop/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dist/
node_modules/
dist/
src-tauri/target/
src-tauri/gen/
src-tauri/binaries/
src-tauri/native/
103 changes: 50 additions & 53 deletions apps/nova-desktop/README.md

Large diffs are not rendered by default.

14 changes: 1 addition & 13 deletions apps/nova-desktop/index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Nova</title>
</head>
<body>
<div id="root">Loading Nova…</div>
<script src="/startup.js"></script>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Nova</title></head><body class="antialiased"><div id="root"></div><script type="module" src="/src/main.tsx"></script></body></html>
65 changes: 65 additions & 0 deletions apps/nova-desktop/installer/Installation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import Foundation

enum InstallationError: LocalizedError {
case invalidPayload
case alreadyInstalled
case invalidDestination

var errorDescription: String? {
switch self {
case .invalidPayload: return "The Nova application is missing or damaged. Download the installer again."
case .alreadyInstalled: return "Nova is already installed in this location."
case .invalidDestination: return "Choose an Applications folder outside the installer."
}
}
}

enum Installation {
static func validate(_ application: URL) throws {
guard Bundle(url: application)?.bundleIdentifier == "ai.supercode.nova" else {
throw InstallationError.invalidPayload
}
let verifier = Process()
verifier.executableURL = URL(fileURLWithPath: "/usr/bin/codesign")
verifier.arguments = ["--verify", "--deep", "--strict", application.path]
verifier.standardOutput = FileHandle.nullDevice
verifier.standardError = FileHandle.nullDevice
try verifier.run()
verifier.waitUntilExit()
guard verifier.terminationStatus == 0 else { throw InstallationError.invalidPayload }
}

static func install(source: URL, directory: URL, replace: Bool) throws -> URL {
let files = FileManager.default
let folder = directory.resolvingSymlinksInPath().standardizedFileURL
let payload = source.resolvingSymlinksInPath().standardizedFileURL
guard !folder.path.hasPrefix("/Volumes/"),
!folder.pathComponents.contains(where: { $0.hasSuffix(".app") }),
folder != payload else { throw InstallationError.invalidDestination }
var isDirectory: ObjCBool = false
guard files.fileExists(atPath: folder.path, isDirectory: &isDirectory), isDirectory.boolValue else {
throw InstallationError.invalidDestination
}
let destination = folder.appendingPathComponent("Nova.app")
if files.fileExists(atPath: destination.path), !replace { throw InstallationError.alreadyInstalled }
let nonce = UUID().uuidString
let staged = folder.appendingPathComponent(".Nova-install-\(nonce).app")
let backup = folder.appendingPathComponent(".Nova-backup-\(nonce).app")
defer { try? files.removeItem(at: staged) }
try validate(payload)
try files.copyItem(at: payload, to: staged)
try validate(staged)
// Keep the previous app intact until the complete, verified copy is ready.
let existing = files.fileExists(atPath: destination.path)
if existing && !replace { throw InstallationError.alreadyInstalled }
if existing { try files.moveItem(at: destination, to: backup) }
do {
try files.moveItem(at: staged, to: destination)
} catch {
if existing { try? files.moveItem(at: backup, to: destination) }
throw error
}
if existing { try? files.removeItem(at: backup) }
return destination
}
}
204 changes: 204 additions & 0 deletions apps/nova-desktop/installer/InstallerWindow.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
import AppKit
import AVFoundation

@MainActor
final class InstallerBackground: NSView {
private let poster = CALayer()
private let playerLayer = AVPlayerLayer()
private let shade = CAGradientLayer()
private let player = AVQueuePlayer()
private var looper: AVPlayerLooper?
private var observer: NSObjectProtocol?

init(resources: URL) {
super.init(frame: .zero)
wantsLayer = true
layer?.backgroundColor = NSColor.black.cgColor
poster.contents = NSImage(contentsOf: resources.appendingPathComponent("site-bg-poster.jpg"))?.cgImage(forProposedRect: nil, context: nil, hints: nil)
poster.contentsGravity = .resizeAspectFill
poster.masksToBounds = true
layer?.addSublayer(poster)
playerLayer.player = player
playerLayer.videoGravity = .resizeAspectFill
playerLayer.masksToBounds = true
layer?.addSublayer(playerLayer)
shade.colors = [NSColor.black.withAlphaComponent(0.4).cgColor, NSColor.black.withAlphaComponent(0.75).cgColor]
layer?.addSublayer(shade)
player.isMuted = true
let item = AVPlayerItem(url: resources.appendingPathComponent("site-bg.mp4"))
looper = AVPlayerLooper(player: player, templateItem: item)
observer = NSWorkspace.shared.notificationCenter.addObserver(forName: NSWorkspace.accessibilityDisplayOptionsDidChangeNotification, object: nil, queue: .main) { [weak self] _ in
MainActor.assumeIsolated { self?.updatePlayback() }
}
updatePlayback()
}

required init?(coder: NSCoder) { nil }

func updatePlayback(visible: Bool = true) {
let reduced = NSWorkspace.shared.accessibilityDisplayShouldReduceMotion
playerLayer.isHidden = reduced
if reduced || !visible { player.pause() } else { player.play() }
}

override func layout() {
super.layout()
CATransaction.begin()
CATransaction.setDisableActions(true)
poster.frame = bounds
playerLayer.frame = bounds
shade.frame = bounds
CATransaction.commit()
}
}

@MainActor
final class InstallerWindow: NSObject, NSWindowDelegate {
let window: NSWindow
private let resources: URL
private let background: InstallerBackground
private let status = NSTextField(wrappingLabelWithString: "Install Nova to your Applications folder.")
private let progress = NSProgressIndicator()
private let installButton = NSButton(title: "Install Nova", target: nil, action: nil)
private let locationButton = NSButton(title: "Choose location…", target: nil, action: nil)
private var directory = URL(fileURLWithPath: "/Applications", isDirectory: true)
private var installed: URL?
private var installing = false
var canQuit: Bool { !installing }

init(resources: URL) {
self.resources = resources
background = InstallerBackground(resources: resources)
window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 820, height: 540), styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView], backing: .buffered, defer: false)
super.init()
window.title = "Install Nova"
window.titleVisibility = .hidden
window.titlebarAppearsTransparent = true
window.backgroundColor = .black
window.minSize = NSSize(width: 640, height: 460)
window.isReleasedWhenClosed = false
window.delegate = self
window.contentView = background

let icon = NSImageView()
icon.image = NSImage(contentsOf: resources.appendingPathComponent("Nova.icns"))
icon.imageScaling = .scaleProportionallyUpOrDown
icon.setAccessibilityLabel("Nova")
icon.widthAnchor.constraint(equalToConstant: 80).isActive = true
icon.heightAnchor.constraint(equalToConstant: 80).isActive = true
let title = NSTextField(labelWithString: "Welcome to Nova")
title.font = .systemFont(ofSize: 34, weight: .medium)
title.textColor = .white
title.alignment = .center
status.font = .systemFont(ofSize: 15)
status.textColor = NSColor.white.withAlphaComponent(0.85)
status.alignment = .center
progress.style = .spinning
progress.controlSize = .small
progress.isDisplayedWhenStopped = false
installButton.target = self
installButton.action = #selector(install)
installButton.bezelStyle = .rounded
installButton.controlSize = .large
installButton.keyEquivalent = "\r"
installButton.contentTintColor = .white
locationButton.target = self
locationButton.action = #selector(chooseLocation)
locationButton.bezelStyle = .inline
locationButton.contentTintColor = NSColor.white.withAlphaComponent(0.85)
let stack = NSStackView(views: [icon, title, status, progress, installButton, locationButton])
stack.orientation = .vertical
stack.alignment = .centerX
stack.spacing = 18
stack.translatesAutoresizingMaskIntoConstraints = false
background.addSubview(stack)
NSLayoutConstraint.activate([
stack.centerXAnchor.constraint(equalTo: background.centerXAnchor),
stack.centerYAnchor.constraint(equalTo: background.centerYAnchor, constant: 8),
stack.widthAnchor.constraint(equalTo: background.widthAnchor, multiplier: 0.8),
status.widthAnchor.constraint(equalTo: stack.widthAnchor),
installButton.widthAnchor.constraint(greaterThanOrEqualToConstant: 190),
])
window.center()
}

@objc private func chooseLocation() {
let panel = NSOpenPanel()
panel.title = "Choose where to install Nova"
panel.prompt = "Choose folder"
panel.canChooseDirectories = true
panel.canChooseFiles = false
panel.allowsMultipleSelection = false
panel.canCreateDirectories = true
panel.directoryURL = directory
panel.beginSheetModal(for: window) { [weak self] response in
guard response == .OK, let url = panel.url, let self else { return }
self.directory = url
self.status.stringValue = "Install Nova in \(url.path)."
}
}

@objc private func install() {
if let installed {
NSWorkspace.shared.openApplication(at: installed, configuration: NSWorkspace.OpenConfiguration()) { [weak self] _, error in
DispatchQueue.main.async {
if let error { self?.status.stringValue = "Nova couldn’t open: \(error.localizedDescription)" }
else { NSApp.terminate(nil) }
}
}
return
}
guard !installing else { return }
let destination = directory.appendingPathComponent("Nova.app")
if NSRunningApplication.runningApplications(withBundleIdentifier: "ai.supercode.nova").contains(where: { $0.bundleURL?.standardizedFileURL == destination.standardizedFileURL }) {
showError("Quit Nova before replacing the installed app, then try again.")
return
}
let exists = FileManager.default.fileExists(atPath: destination.path)
if exists {
let alert = NSAlert()
alert.messageText = "Replace the existing Nova app?"
alert.informativeText = "This replaces only Nova.app in \(directory.path). Your conversations and settings are kept."
alert.addButton(withTitle: "Replace Nova")
alert.addButton(withTitle: "Cancel")
guard alert.runModal() == .alertFirstButtonReturn else { return }
}
installing = true
installButton.isEnabled = false
locationButton.isEnabled = false
status.stringValue = "Installing Nova…"
progress.startAnimation(nil)
let source = resources.appendingPathComponent("Nova.app")
let folder = directory
Task {
do {
let result = try await Task.detached(priority: .userInitiated) {
try Installation.install(source: source, directory: folder, replace: exists)
}.value
installed = result
status.stringValue = "Nova is installed and ready to open."
installButton.title = "Open Nova"
locationButton.isHidden = true
} catch {
status.stringValue = "Installation couldn’t finish. Try another location or check folder permissions."
showError(error.localizedDescription)
locationButton.isEnabled = true
}
installing = false
progress.stopAnimation(nil)
installButton.isEnabled = true
}
}

private func showError(_ message: String) {
let alert = NSAlert()
alert.messageText = "Nova couldn’t be installed"
alert.informativeText = message
alert.addButton(withTitle: "OK")
alert.beginSheetModal(for: window)
}

func windowShouldClose(_ sender: NSWindow) -> Bool { !installing }
func windowDidMiniaturize(_ notification: Notification) { background.updatePlayback(visible: false) }
func windowDidDeminiaturize(_ notification: Notification) { background.updatePlayback() }
}
33 changes: 33 additions & 0 deletions apps/nova-desktop/installer/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import AppKit

@MainActor
final class InstallerDelegate: NSObject, NSApplicationDelegate {
private var controller: InstallerWindow?

func applicationDidFinishLaunching(_ notification: Notification) {
guard let resources = Bundle.main.resourceURL else { NSApp.terminate(nil); return }
let menu = NSMenu()
let appItem = NSMenuItem()
let appMenu = NSMenu()
appMenu.addItem(withTitle: "Quit Install Nova", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q")
appItem.submenu = appMenu
menu.addItem(appItem)
NSApp.mainMenu = menu
controller = InstallerWindow(resources: resources)
controller?.window.makeKeyAndOrderFront(nil)
NSApp.activate(ignoringOtherApps: true)
}

func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { true }
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
controller?.canQuit == false ? .terminateCancel : .terminateNow
}
}

MainActor.assumeIsolated {
let application = NSApplication.shared
let delegate = InstallerDelegate()
application.delegate = delegate
application.setActivationPolicy(.regular)
withExtendedLifetime(delegate) { application.run() }
}
63 changes: 63 additions & 0 deletions apps/nova-desktop/installer/tests/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import Foundation

let files = FileManager.default
let root = files.temporaryDirectory.appendingPathComponent("nova-install-test-\(UUID().uuidString)")
try files.createDirectory(at: root, withIntermediateDirectories: true)
defer { try? files.removeItem(at: root) }
let source = root.appendingPathComponent("Payload.app")
let destination = root.appendingPathComponent("Applications")
try files.createDirectory(at: source.appendingPathComponent("Contents/Resources"), withIntermediateDirectories: true)
try files.createDirectory(at: source.appendingPathComponent("Contents/MacOS"), withIntermediateDirectories: true)
try files.createDirectory(at: destination, withIntermediateDirectories: true)
try files.copyItem(at: URL(fileURLWithPath: "/usr/bin/true"), to: source.appendingPathComponent("Contents/MacOS/Nova"))
let plist: [String: Any] = ["CFBundleIdentifier": "ai.supercode.nova", "CFBundleExecutable": "Nova", "CFBundlePackageType": "APPL"]
try PropertyListSerialization.data(fromPropertyList: plist, format: .xml, options: 0).write(to: source.appendingPathComponent("Contents/Info.plist"))

func sign() throws {
let process = Process()
process.executableURL = URL(fileURLWithPath: "/usr/bin/codesign")
process.arguments = ["--force", "--sign", "-", source.path]
try process.run()
process.waitUntilExit()
precondition(process.terminationStatus == 0, "Could not sign fixture")
}
func assertMarker(_ app: URL, _ expected: String) throws {
let actual = try String(contentsOf: app.appendingPathComponent("Contents/Resources/marker"), encoding: .utf8)
precondition(actual == expected)
}
func expectFailure(_ operation: () throws -> Void) {
do { try operation(); fatalError("Expected operation to fail") } catch {}
}

try Data("first".utf8).write(to: source.appendingPathComponent("Contents/Resources/marker"))
try sign()
let installed = try Installation.install(source: source, directory: destination, replace: false)
try assertMarker(installed, "first")
print("PASS: signed app installs into selected folder")
expectFailure { _ = try Installation.install(source: source, directory: destination, replace: false) }
try assertMarker(installed, "first")
print("PASS: existing app is preserved without replacement approval")

try Data("second".utf8).write(to: source.appendingPathComponent("Contents/Resources/marker"))
try sign()
_ = try Installation.install(source: source, directory: destination, replace: true)
try assertMarker(installed, "second")
print("PASS: replacement installs verified new payload")

try Data("tampered".utf8).write(to: source.appendingPathComponent("Contents/Resources/marker"))
expectFailure { _ = try Installation.install(source: source, directory: destination, replace: true) }
try assertMarker(installed, "second")
print("PASS: damaged payload cannot replace an existing app")
expectFailure { _ = try Installation.install(source: source, directory: source, replace: true) }
expectFailure { _ = try Installation.install(source: source, directory: root.appendingPathComponent("Missing"), replace: true) }
let leftovers = try files.contentsOfDirectory(atPath: destination.path).filter { $0.hasPrefix(".Nova-") }
precondition(leftovers.isEmpty)
print("PASS: invalid destinations rejected and staging files cleaned")

if let payloadPath = CommandLine.arguments.dropFirst().first {
let realDestination = root.appendingPathComponent("Real Applications")
try files.createDirectory(at: realDestination, withIntermediateDirectories: true)
let result = try Installation.install(source: URL(fileURLWithPath: payloadPath), directory: realDestination, replace: false)
try Installation.validate(result)
print("PASS: complete release payload installs and validates in a temporary folder")
}
Loading
Loading