Skip to content
Open
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
10 changes: 9 additions & 1 deletion MeoAsstMac.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 55;
objectVersion = 70;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -214,6 +214,10 @@
92F78D4E2A0B361C00999BD0 /* TaskTimerManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskTimerManager.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFileSystemSynchronizedRootGroup section */
1B317DDD2DC10BE9008A5ABB /* App Intents */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = "App Intents"; sourceTree = "<group>"; };
/* End PBXFileSystemSynchronizedRootGroup section */

/* Begin PBXFrameworksBuildPhase section */
833786C828F188D800D39D6F /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
Expand Down Expand Up @@ -359,6 +363,7 @@
isa = PBXGroup;
children = (
833786CE28F188D800D39D6F /* MeoAsstMacApp.swift */,
1B317DDD2DC10BE9008A5ABB /* App Intents */,
8329858F29EDAC91009F7ED5 /* Core */,
8341195129EC258D00044F45 /* Model */,
8329858E29EDAC7B009F7ED5 /* Views */,
Expand Down Expand Up @@ -481,6 +486,9 @@
);
dependencies = (
);
fileSystemSynchronizedGroups = (
1B317DDD2DC10BE9008A5ABB /* App Intents */,
);
name = MAA;
packageProductDependencies = (
830C3D1B29BC7D8600B13A9F /* Sparkle */,
Expand Down
161 changes: 161 additions & 0 deletions MeoAsstMac/App Intents/Intents.intentdefinition
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>INEnums</key>
<array/>
<key>INIntentDefinitionModelVersion</key>
<string>1.2</string>
<key>INIntentDefinitionNamespace</key>
<string>kyeMw4</string>
<key>INIntentDefinitionSystemVersion</key>
<string>24F5053j</string>
<key>INIntentDefinitionToolsBuildVersion</key>
<string>16E140</string>
<key>INIntentDefinitionToolsVersion</key>
<string>16.3</string>
<key>INIntents</key>
<array>
<dict>
<key>INIntentCategory</key>
<string>generic</string>
<key>INIntentConfigurable</key>
<true/>
<key>INIntentDescription</key>
<string>开始用户设定的一键长草任务序列</string>
<key>INIntentDescriptionID</key>
<string>aohWss</string>
<key>INIntentManagedParameterCombinations</key>
<dict>
<key></key>
<dict>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
<key>INIntentParameterCombinationTitle</key>
<string>开始一键长草</string>
<key>INIntentParameterCombinationTitleID</key>
<string>dheMtd</string>
<key>INIntentParameterCombinationUpdatesLinked</key>
<true/>
</dict>
</dict>
<key>INIntentName</key>
<string>RunMAA</string>
<key>INIntentParameterCombinations</key>
<dict>
<key></key>
<dict>
<key>INIntentParameterCombinationIsPrimary</key>
<true/>
<key>INIntentParameterCombinationSubtitle</key>
<string>开始用户设定的一键长草任务序列</string>
<key>INIntentParameterCombinationSubtitleID</key>
<string>NWsSjw</string>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
<key>INIntentParameterCombinationTitle</key>
<string>开始一键长草</string>
<key>INIntentParameterCombinationTitleID</key>
<string>9Z968c</string>
</dict>
</dict>
<key>INIntentResponse</key>
<dict>
<key>INIntentResponseCodes</key>
<array>
<dict>
<key>INIntentResponseCodeName</key>
<string>success</string>
<key>INIntentResponseCodeSuccess</key>
<true/>
</dict>
<dict>
<key>INIntentResponseCodeName</key>
<string>failure</string>
</dict>
</array>
<key>INIntentResponseLastParameterTag</key>
<integer>1</integer>
</dict>
<key>INIntentTitle</key>
<string>开始一键长草</string>
<key>INIntentTitleID</key>
<string>58dePC</string>
<key>INIntentType</key>
<string>Custom</string>
<key>INIntentVerb</key>
<string>Do</string>
</dict>
<dict>
<key>INIntentCategory</key>
<string>generic</string>
<key>INIntentConfigurable</key>
<true/>
<key>INIntentDescription</key>
<string>终止用户设定的一键长草任务序列</string>
<key>INIntentDescriptionID</key>
<string>3y9D4C</string>
<key>INIntentManagedParameterCombinations</key>
<dict>
<key></key>
<dict>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
<key>INIntentParameterCombinationTitle</key>
<string>终止一键长草</string>
<key>INIntentParameterCombinationTitleID</key>
<string>ybNxoN</string>
<key>INIntentParameterCombinationUpdatesLinked</key>
<true/>
</dict>
</dict>
<key>INIntentName</key>
<string>StopMAA</string>
<key>INIntentParameterCombinations</key>
<dict>
<key></key>
<dict>
<key>INIntentParameterCombinationIsPrimary</key>
<true/>
<key>INIntentParameterCombinationSubtitle</key>
<string>终止用户设定的一键长草任务序列</string>
<key>INIntentParameterCombinationSubtitleID</key>
<string>ZEEcIP</string>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
<key>INIntentParameterCombinationTitle</key>
<string>终止一键长草</string>
<key>INIntentParameterCombinationTitleID</key>
<string>Yki2ar</string>
</dict>
</dict>
<key>INIntentResponse</key>
<dict>
<key>INIntentResponseCodes</key>
<array>
<dict>
<key>INIntentResponseCodeName</key>
<string>success</string>
<key>INIntentResponseCodeSuccess</key>
<true/>
</dict>
<dict>
<key>INIntentResponseCodeName</key>
<string>failure</string>
</dict>
</array>
</dict>
<key>INIntentTitle</key>
<string>终止一键长草</string>
<key>INIntentTitleID</key>
<string>Hv22KO</string>
<key>INIntentType</key>
<string>Custom</string>
<key>INIntentVerb</key>
<string>Do</string>
</dict>
</array>
<key>INTypes</key>
<array/>
</dict>
</plist>
43 changes: 43 additions & 0 deletions MeoAsstMac/App Intents/IntentsHandler.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
10 changes: 10 additions & 0 deletions MeoAsstMac/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>INIntentsSupported</key>
<array>
<string>RunMAAIntent</string>
<string>StopMAAIntent</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
Expand All @@ -22,6 +27,11 @@
</dict>
</dict>
</dict>
<key>NSUserActivityTypes</key>
<array>
<string>RunMAAIntent</string>
<string>StopMAAIntent</string>
</array>
<key>SUEnableInstallerLauncherService</key>
<true/>
<key>SUFeedURL</key>
Expand Down
16 changes: 16 additions & 0 deletions MeoAsstMac/MeoAsstMacApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Sparkle
import SwiftUI
import Intents

@main
struct MeoAsstMacApp: App {
Expand All @@ -31,6 +32,7 @@ struct MeoAsstMacApp: App {
.environmentObject(appViewModel)
.onAppear {
TaskTimerManager.shared.connectToModel(viewModel: appViewModel)
appDelegate.setViewModel(appViewModel)
}
}
.commands {
Expand Down Expand Up @@ -85,11 +87,25 @@ final class MaaUpdaterDelegate: NSObject, SPUUpdaterDelegate {
}

private class AppDelegate: NSObject, NSApplicationDelegate {
private var viewModel: MAAViewModel?
func applicationWillFinishLaunching(_ notification: Notification) {
NSWindow.allowsAutomaticWindowTabbing = false
}

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
}
}