diff --git a/MeoAsstMac.xcodeproj/project.pbxproj b/MeoAsstMac.xcodeproj/project.pbxproj index 73e367b4a..8cc2275b5 100644 --- a/MeoAsstMac.xcodeproj/project.pbxproj +++ b/MeoAsstMac.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 55; + objectVersion = 70; objects = { /* Begin PBXBuildFile section */ @@ -214,6 +214,10 @@ 92F78D4E2A0B361C00999BD0 /* TaskTimerManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskTimerManager.swift; sourceTree = ""; }; /* End PBXFileReference section */ +/* Begin PBXFileSystemSynchronizedRootGroup section */ + 1B317DDD2DC10BE9008A5ABB /* App Intents */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = "App Intents"; sourceTree = ""; }; +/* End PBXFileSystemSynchronizedRootGroup section */ + /* Begin PBXFrameworksBuildPhase section */ 833786C828F188D800D39D6F /* Frameworks */ = { isa = PBXFrameworksBuildPhase; @@ -359,6 +363,7 @@ isa = PBXGroup; children = ( 833786CE28F188D800D39D6F /* MeoAsstMacApp.swift */, + 1B317DDD2DC10BE9008A5ABB /* App Intents */, 8329858F29EDAC91009F7ED5 /* Core */, 8341195129EC258D00044F45 /* Model */, 8329858E29EDAC7B009F7ED5 /* Views */, @@ -481,6 +486,9 @@ ); dependencies = ( ); + fileSystemSynchronizedGroups = ( + 1B317DDD2DC10BE9008A5ABB /* App Intents */, + ); name = MAA; packageProductDependencies = ( 830C3D1B29BC7D8600B13A9F /* Sparkle */, diff --git a/MeoAsstMac/App Intents/Intents.intentdefinition b/MeoAsstMac/App Intents/Intents.intentdefinition new file mode 100644 index 000000000..f2b023be5 --- /dev/null +++ b/MeoAsstMac/App Intents/Intents.intentdefinition @@ -0,0 +1,161 @@ + + + + + INEnums + + INIntentDefinitionModelVersion + 1.2 + INIntentDefinitionNamespace + kyeMw4 + INIntentDefinitionSystemVersion + 24F5053j + INIntentDefinitionToolsBuildVersion + 16E140 + INIntentDefinitionToolsVersion + 16.3 + INIntents + + + INIntentCategory + generic + INIntentConfigurable + + INIntentDescription + 开始用户设定的一键长草任务序列 + INIntentDescriptionID + aohWss + INIntentManagedParameterCombinations + + + + INIntentParameterCombinationSupportsBackgroundExecution + + INIntentParameterCombinationTitle + 开始一键长草 + INIntentParameterCombinationTitleID + dheMtd + INIntentParameterCombinationUpdatesLinked + + + + INIntentName + RunMAA + INIntentParameterCombinations + + + + INIntentParameterCombinationIsPrimary + + INIntentParameterCombinationSubtitle + 开始用户设定的一键长草任务序列 + INIntentParameterCombinationSubtitleID + NWsSjw + INIntentParameterCombinationSupportsBackgroundExecution + + INIntentParameterCombinationTitle + 开始一键长草 + INIntentParameterCombinationTitleID + 9Z968c + + + INIntentResponse + + INIntentResponseCodes + + + INIntentResponseCodeName + success + INIntentResponseCodeSuccess + + + + INIntentResponseCodeName + failure + + + INIntentResponseLastParameterTag + 1 + + INIntentTitle + 开始一键长草 + INIntentTitleID + 58dePC + INIntentType + Custom + INIntentVerb + Do + + + INIntentCategory + generic + INIntentConfigurable + + INIntentDescription + 终止用户设定的一键长草任务序列 + INIntentDescriptionID + 3y9D4C + INIntentManagedParameterCombinations + + + + INIntentParameterCombinationSupportsBackgroundExecution + + INIntentParameterCombinationTitle + 终止一键长草 + INIntentParameterCombinationTitleID + ybNxoN + INIntentParameterCombinationUpdatesLinked + + + + INIntentName + StopMAA + INIntentParameterCombinations + + + + INIntentParameterCombinationIsPrimary + + INIntentParameterCombinationSubtitle + 终止用户设定的一键长草任务序列 + INIntentParameterCombinationSubtitleID + ZEEcIP + INIntentParameterCombinationSupportsBackgroundExecution + + INIntentParameterCombinationTitle + 终止一键长草 + INIntentParameterCombinationTitleID + Yki2ar + + + INIntentResponse + + INIntentResponseCodes + + + INIntentResponseCodeName + success + INIntentResponseCodeSuccess + + + + INIntentResponseCodeName + failure + + + + INIntentTitle + 终止一键长草 + INIntentTitleID + Hv22KO + INIntentType + Custom + INIntentVerb + Do + + + INTypes + + + diff --git a/MeoAsstMac/App Intents/IntentsHandler.swift b/MeoAsstMac/App Intents/IntentsHandler.swift new file mode 100644 index 000000000..dea2bb7db --- /dev/null +++ b/MeoAsstMac/App Intents/IntentsHandler.swift @@ -0,0 +1,43 @@ +// +// IntentsHandler.swift +// MAA +// +// Created by 罗板栗 on 2025/4/29. +// + +import Foundation +import SwiftUI +import Intents + +class RunMAAIntentHandler: NSObject, RunMAAIntentHandling { + weak var viewModel: MAAViewModel? + + init(viewModel: MAAViewModel?) { + self.viewModel = viewModel + } + + func handle(intent: RunMAAIntent, completion: @escaping (RunMAAIntentResponse) -> Void) { + let respond = RunMAAIntentResponse(code: .success, userActivity: nil) + Task { @MainActor in + viewModel?.dailyTasksDetailMode = .log + await viewModel?.tryStartTasks() + } + completion(respond) + } +} + +class StopMAAIntentHandler: NSObject, StopMAAIntentHandling { + weak var viewModel: MAAViewModel? + + init(viewModel: MAAViewModel?) { + self.viewModel = viewModel + } + + func handle(intent: StopMAAIntent, completion: @escaping (StopMAAIntentResponse) -> Void) { + let respond = StopMAAIntentResponse(code: .success, userActivity: nil) + Task { @MainActor in + try await viewModel?.stop() + } + completion(respond) + } +} diff --git a/MeoAsstMac/Info.plist b/MeoAsstMac/Info.plist index 5a0f2a5f5..d45cdde8c 100644 --- a/MeoAsstMac/Info.plist +++ b/MeoAsstMac/Info.plist @@ -2,6 +2,11 @@ + INIntentsSupported + + RunMAAIntent + StopMAAIntent + NSAppTransportSecurity NSExceptionDomains @@ -22,6 +27,11 @@ + NSUserActivityTypes + + RunMAAIntent + StopMAAIntent + SUEnableInstallerLauncherService SUFeedURL diff --git a/MeoAsstMac/MeoAsstMacApp.swift b/MeoAsstMac/MeoAsstMacApp.swift index e416dbc1a..0618a6901 100644 --- a/MeoAsstMac/MeoAsstMacApp.swift +++ b/MeoAsstMac/MeoAsstMacApp.swift @@ -7,6 +7,7 @@ import Sparkle import SwiftUI +import Intents @main struct MeoAsstMacApp: App { @@ -31,6 +32,7 @@ struct MeoAsstMacApp: App { .environmentObject(appViewModel) .onAppear { TaskTimerManager.shared.connectToModel(viewModel: appViewModel) + appDelegate.setViewModel(appViewModel) } } .commands { @@ -85,6 +87,7 @@ final class MaaUpdaterDelegate: NSObject, SPUUpdaterDelegate { } private class AppDelegate: NSObject, NSApplicationDelegate { + private var viewModel: MAAViewModel? func applicationWillFinishLaunching(_ notification: Notification) { NSWindow.allowsAutomaticWindowTabbing = false } @@ -92,4 +95,17 @@ private class AppDelegate: NSObject, NSApplicationDelegate { func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { true } + + func application(_ application: NSApplication, handlerFor intent: INIntent) -> Any? { + if intent is RunMAAIntent { + return RunMAAIntentHandler(viewModel: viewModel) + } else if intent is StopMAAIntent { + return StopMAAIntentHandler(viewModel: viewModel) + } + return nil + } + + func setViewModel(_ model: MAAViewModel) { + viewModel = model + } }