Files
VirtualBuddy/VirtualWormhole/Source/Services/DefaultsImport/Implementation/DefaultsDomainDescriptor.swift
Guilherme Rambo e686949edc New socket-based host<>guest communication transport (#763)
* New host<>guest transport/protocol implementation

* Implemented minimal legacy guest protocol to maintain clipboard functionality for guests that can't run the latest VirtualBuddyGuest app

* Fix missing dependency

* Change VMBridge Swift package to remote

* Disable VirtualBuddyGuest clipboard sharing support on legacy OSes, leave macOS 13 support for shared folder mount
2026-09-14 14:16:07 -03:00

57 lines
1.7 KiB
Swift

//
// DefaultsDomainDescriptor.swift
// VirtualWormhole
//
// Created by Guilherme Rambo on 09/03/23.
//
import Cocoa
import UniformTypeIdentifiers
public struct DefaultsDomainDescriptor: Identifiable, Codable, Sendable {
public struct Target: Identifiable, Codable, Sendable {
public var id: String { bundleIdentifier }
public var bundleIdentifier: String
public var name: String
public var isSystemService: Bool
}
public struct Restart: Codable, Sendable {
public var command: String
public var needsConfirmation = true
public var shouldRelaunch = true
}
public var id: Target.ID { target.id }
public var target: Target
public var ignoredKeyPaths: [String] = []
public var restart: Restart?
}
public extension DefaultsDomainDescriptor.Target {
var isRunning: Bool {
/// System services are not included in `NSRunningApplication.runningApplications`,
/// so just assume they're always running (which will be the case most of the time).
guard !isSystemService else { return true }
return NSRunningApplication.runningApplications(withBundleIdentifier: bundleIdentifier).contains(where: { !$0.isTerminated })
}
var bundleURL: URL? {
NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleIdentifier)
}
func iconImage(with size: CGSize = CGSize(width: 128, height: 128)) -> NSImage {
func getIcon() -> NSImage {
guard let url = bundleURL else {
return NSWorkspace.shared.icon(for: .application)
}
return NSWorkspace.shared.icon(forFile: url.path)
}
let image = getIcon()
image.size = size
return image
}
}