MCPcopy
hub / github.com/ZToolsCenter/ZTools / executeSystemCommand

Function executeSystemCommand

src/main/api/renderer/systemCommands.ts:94–225  ·  view source on GitHub ↗
(
  command: string,
  ctx: SystemCommandContext,
  param?: any
)

Source from the content-addressed store, hash-verified

92 * 执行系统内置指令
93 */
94export async function executeSystemCommand(
95 command: string,
96 ctx: SystemCommandContext,
97 param?: any
98): Promise<any> {
99 const execAsync = promisify(exec)
100
101 const platform = process.platform
102
103 let cmd = ''
104
105 switch (command) {
106 case 'clear':
107 return handleClear(ctx)
108
109 case 'clear-history':
110 return handleClearHistory(ctx)
111
112 case 'reboot':
113 if (platform === 'darwin') {
114 cmd = 'osascript -e "tell application \\"System Events\\" to restart"'
115 } else if (platform === 'win32') {
116 cmd = 'shutdown /r /t 0'
117 } else if (platform === 'linux') {
118 cmd = 'systemctl reboot'
119 }
120 break
121
122 case 'shutdown':
123 if (platform === 'darwin') {
124 cmd = 'osascript -e "tell application \\"System Events\\" to shut down"'
125 } else if (platform === 'win32') {
126 cmd = 'shutdown /s /t 0'
127 } else if (platform === 'linux') {
128 cmd = 'systemctl poweroff'
129 }
130 break
131
132 case 'logoff':
133 if (platform === 'darwin') {
134 cmd = 'osascript -e "tell application \\"System Events\\" to log out"'
135 } else if (platform === 'win32') {
136 cmd = 'shutdown /l'
137 } else if (platform === 'linux') {
138 cmd =
139 'gnome-session-quit --logout --no-prompt || xfce4-session-logout --logout || qdbus org.kde.ksmserver /KSMServer logout 0 0 0 || loginctl terminate-user $USER'
140 }
141 break
142
143 case 'sleep':
144 if (platform === 'darwin') {
145 cmd = 'osascript -e "tell application \\"System Events\\" to sleep"'
146 } else if (platform === 'win32') {
147 ctx.mainWindow?.hide()
148 cmd = `powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -WindowStyle Hidden -Command "Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.Application]::SetSuspendState('Suspend', $false, $false)"`
149 } else if (platform === 'linux') {
150 cmd = 'systemctl suspend'
151 }

Callers 2

launchMethod · 0.90

Calls 14

handleClearFunction · 0.85
handleClearHistoryFunction · 0.85
handleWebSearchFunction · 0.85
handleOpenUrlFunction · 0.85
handleOpenFolderFunction · 0.85
handleWindowInfoFunction · 0.85
handleCopyPathFunction · 0.85
handleOpenTerminalFunction · 0.85
handleColorPickerFunction · 0.85
handleScreenshotFunction · 0.85
handleDynamicWebSearchFunction · 0.85

Tested by

no test coverage detected