From 5a898f4b7515e5c800890a6134a2d4d64d63e90f Mon Sep 17 00:00:00 2001 From: ChestnutLUO Date: Tue, 29 Apr 2025 23:14:27 +0800 Subject: [PATCH 1/3] Add RunMAA and StopMAA Shortcut --- MeoAsstMac.xcodeproj/project.pbxproj | 10 +- .../App Intents/Intents.intentdefinition | 161 ++++++++++++++++++ MeoAsstMac/App Intents/IntentsHandler.swift | 41 +++++ MeoAsstMac/Info.plist | 10 ++ MeoAsstMac/MeoAsstMacApp.swift | 27 +++ 5 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 MeoAsstMac/App Intents/Intents.intentdefinition create mode 100644 MeoAsstMac/App Intents/IntentsHandler.swift 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..ec9e119e2 --- /dev/null +++ b/MeoAsstMac/App Intents/IntentsHandler.swift @@ -0,0 +1,41 @@ +// +// 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) { + Task { @MainActor in + viewModel?.dailyTasksDetailMode = .log + await viewModel?.tryStartTasks() + return RunMAAIntentResponseCode.success + } + } +} + +class StopMAAIntentHandler: NSObject, StopMAAIntentHandling { + weak var viewModel: MAAViewModel? + + init(viewModel: MAAViewModel?) { + self.viewModel = viewModel + } + + func handle(intent: StopMAAIntent, completion: @escaping (StopMAAIntentResponse) -> Void) { + Task { @MainActor in + try await viewModel?.stop() + return StopMAAIntentResponseCode.success + } + } +} 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..cc6ee2f42 100644 --- a/MeoAsstMac/MeoAsstMacApp.swift +++ b/MeoAsstMac/MeoAsstMacApp.swift @@ -7,6 +7,7 @@ import Sparkle import SwiftUI +import Intents @main struct MeoAsstMacApp: App { @@ -23,6 +24,7 @@ struct MeoAsstMacApp: App { let isRelease = true #endif updaterController = .init(startingUpdater: isRelease, updaterDelegate: updaterDelegate, userDriverDelegate: nil) + appDelegate.setViewModel(appViewModel) } var body: some Scene { @@ -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,28 @@ private class AppDelegate: NSObject, NSApplicationDelegate { func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { true } + + func application(_ application: NSApplication, handlerFor intent: INIntent) -> Any? { + //if intent is RunMAAIntent { + // Task { @MainActor in + // viewModel?.dailyTasksDetailMode = .log + // await viewModel?.tryStartTasks() + // } + // return nil + //}else if intent is StopMAAIntent { + // Task { @MainActor in + // try await viewModel?.stop() } + // return nil + //} + 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 + } } From 7c5471a5cfc9a8239b2dc120711c1592be214acb Mon Sep 17 00:00:00 2001 From: ChestnutLUO Date: Wed, 30 Apr 2025 07:42:49 +0800 Subject: [PATCH 2/3] Fix Shortcut error --- MeoAsstMac/App Intents/IntentsHandler.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MeoAsstMac/App Intents/IntentsHandler.swift b/MeoAsstMac/App Intents/IntentsHandler.swift index ec9e119e2..dea2bb7db 100644 --- a/MeoAsstMac/App Intents/IntentsHandler.swift +++ b/MeoAsstMac/App Intents/IntentsHandler.swift @@ -17,11 +17,12 @@ class RunMAAIntentHandler: NSObject, RunMAAIntentHandling { } func handle(intent: RunMAAIntent, completion: @escaping (RunMAAIntentResponse) -> Void) { + let respond = RunMAAIntentResponse(code: .success, userActivity: nil) Task { @MainActor in viewModel?.dailyTasksDetailMode = .log await viewModel?.tryStartTasks() - return RunMAAIntentResponseCode.success } + completion(respond) } } @@ -33,9 +34,10 @@ class StopMAAIntentHandler: NSObject, StopMAAIntentHandling { } func handle(intent: StopMAAIntent, completion: @escaping (StopMAAIntentResponse) -> Void) { + let respond = StopMAAIntentResponse(code: .success, userActivity: nil) Task { @MainActor in try await viewModel?.stop() - return StopMAAIntentResponseCode.success } + completion(respond) } } From 1488cb185d0c835ef764218cd2318f53dbcf7030 Mon Sep 17 00:00:00 2001 From: ChestnutLUO Date: Wed, 30 Apr 2025 08:07:53 +0800 Subject: [PATCH 3/3] =?UTF-8?q?Fix=20=E5=BF=AB=E6=8D=B7=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E4=B8=8EUI=E4=B8=8D=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MeoAsstMac/MeoAsstMacApp.swift | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/MeoAsstMac/MeoAsstMacApp.swift b/MeoAsstMac/MeoAsstMacApp.swift index cc6ee2f42..0618a6901 100644 --- a/MeoAsstMac/MeoAsstMacApp.swift +++ b/MeoAsstMac/MeoAsstMacApp.swift @@ -24,7 +24,6 @@ struct MeoAsstMacApp: App { let isRelease = true #endif updaterController = .init(startingUpdater: isRelease, updaterDelegate: updaterDelegate, userDriverDelegate: nil) - appDelegate.setViewModel(appViewModel) } var body: some Scene { @@ -33,6 +32,7 @@ struct MeoAsstMacApp: App { .environmentObject(appViewModel) .onAppear { TaskTimerManager.shared.connectToModel(viewModel: appViewModel) + appDelegate.setViewModel(appViewModel) } } .commands { @@ -97,26 +97,15 @@ private class AppDelegate: NSObject, NSApplicationDelegate { } func application(_ application: NSApplication, handlerFor intent: INIntent) -> Any? { - //if intent is RunMAAIntent { - // Task { @MainActor in - // viewModel?.dailyTasksDetailMode = .log - // await viewModel?.tryStartTasks() - // } - // return nil - //}else if intent is StopMAAIntent { - // Task { @MainActor in - // try await viewModel?.stop() } - // return nil - //} - 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 + 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 + } }