mirror of
https://github.com/utmapp/UTM.git
synced 2026-10-12 02:24:01 +00:00
revert(spotlight): remove Spotlight indexing from main PR branch; keep only AppIntents ID fix and auto-activate on Start (macOS)
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
//
|
||||
// Copyright © 2025 osy. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import AppIntents
|
||||
import CoreSpotlight
|
||||
|
||||
enum UTMEntityIndexer {
|
||||
/// Rebuild the Spotlight index for all VM entities (macOS 15+/iOS 18+).
|
||||
@MainActor
|
||||
static func reindexAll(with data: UTMData) async {
|
||||
guard #available(iOS 18, macOS 15, tvOS 18, watchOS 11, *) else {
|
||||
return
|
||||
}
|
||||
let entities: [UTMVirtualMachineEntity] = data.virtualMachines.map { UTMVirtualMachineEntity(from: $0) }
|
||||
do {
|
||||
let index = CSSearchableIndex.default()
|
||||
try await index.deleteAppEntities(ofType: UTMVirtualMachineEntity.self)
|
||||
if !entities.isEmpty {
|
||||
try await index.indexAppEntities(entities)
|
||||
logger.debug("[Indexing] Indexed \(entities.count) VM entities for Spotlight")
|
||||
} else {
|
||||
logger.debug("[Indexing] Cleared VM entity index (no entities)")
|
||||
}
|
||||
} catch {
|
||||
logger.error("[Indexing] Failed to (re)index VM entities: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
//
|
||||
|
||||
import AppIntents
|
||||
import CoreSpotlight
|
||||
|
||||
@available(iOS 16, macOS 13, tvOS 16, watchOS 9, *)
|
||||
struct UTMVirtualMachineEntity: AppEntity {
|
||||
@@ -62,21 +61,6 @@ struct UTMVirtualMachineEntity: AppEntity {
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 18, macOS 15, *)
|
||||
extension UTMVirtualMachineEntity: IndexedEntity {
|
||||
// Spotlight searchable attributes for this VM entity
|
||||
var attributeSet: CSSearchableItemAttributeSet {
|
||||
let attrs = CSSearchableItemAttributeSet()
|
||||
attrs.title = name
|
||||
attrs.contentDescription = description
|
||||
if let iconURL {
|
||||
attrs.thumbnailURL = iconURL
|
||||
}
|
||||
// Light keywords for common queries
|
||||
attrs.keywords = ["vm", "virtual machine", String(describing: state)]
|
||||
return attrs
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 16, macOS 13, tvOS 16, watchOS 9, *)
|
||||
extension UTMVirtualMachineState: AppEnum {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
import SwiftUI
|
||||
import AppIntents
|
||||
import CoreSpotlight
|
||||
|
||||
struct UTMApp: App {
|
||||
let data: UTMData
|
||||
@@ -36,16 +35,12 @@ struct UTMApp: App {
|
||||
.onAppear {
|
||||
appDelegate.data = data
|
||||
NSApp.scriptingDelegate = appDelegate
|
||||
Task { await reindexVms() }
|
||||
}
|
||||
.onReceive(.vmSessionError) { notification in
|
||||
if let message = notification.userInfo?["Message"] as? String {
|
||||
data.showErrorAlert(message: message)
|
||||
}
|
||||
}
|
||||
.onChange(of: data.virtualMachines) { _ in
|
||||
Task { await reindexVms() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SceneBuilder
|
||||
@@ -86,22 +81,5 @@ struct UTMApp: App {
|
||||
return oldBody
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func reindexVms() async {
|
||||
guard #available(macOS 15, *) else { return }
|
||||
let entities = data.virtualMachines.map { UTMVirtualMachineEntity(from: $0) }
|
||||
do {
|
||||
let index = CSSearchableIndex.default()
|
||||
try await index.deleteAppEntities(ofType: UTMVirtualMachineEntity.self)
|
||||
if !entities.isEmpty {
|
||||
try await index.indexAppEntities(entities)
|
||||
logger.debug("[Indexing] Indexed \(entities.count) VM entities for Spotlight")
|
||||
} else {
|
||||
logger.debug("[Indexing] Cleared VM entity index (no entities)")
|
||||
}
|
||||
} catch {
|
||||
logger.error("[Indexing] Failed to (re)index VM entities: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user