( executor: CommandExecutor, )
| 51 | } |
| 52 | |
| 53 | export function createStopMacAppExecutor( |
| 54 | executor: CommandExecutor, |
| 55 | ): NonStreamingExecutor<StopMacAppParams, StopMacAppResult> { |
| 56 | return async (params) => { |
| 57 | const artifacts = createStopMacAppArtifacts(params); |
| 58 | |
| 59 | if (!params.appName && params.processId === undefined) { |
| 60 | return buildStopFailure(artifacts, 'Either appName or processId must be provided.'); |
| 61 | } |
| 62 | |
| 63 | const target = params.processId ? `PID ${params.processId}` : params.appName!; |
| 64 | log('info', `Stopping macOS app: ${target}`); |
| 65 | |
| 66 | try { |
| 67 | const command = |
| 68 | params.processId !== undefined |
| 69 | ? ['kill', String(params.processId)] |
| 70 | : ['pkill', '-f', params.appName!]; |
| 71 | const result = await executor(command, 'Stop macOS App'); |
| 72 | |
| 73 | if (!result.success) { |
| 74 | return buildStopFailure( |
| 75 | artifacts, |
| 76 | `Stop macOS app operation failed: ${result.error ?? 'Unknown error'}`, |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | return buildStopSuccess(artifacts); |
| 81 | } catch (error) { |
| 82 | return buildStopFailure( |
| 83 | artifacts, |
| 84 | `Stop macOS app operation failed: ${toErrorMessage(error)}`, |
| 85 | ); |
| 86 | } |
| 87 | }; |
| 88 | } |
| 89 | |
| 90 | export const schema = stopMacAppSchema.shape; |
| 91 |
no test coverage detected