|
|
@@ -13,30 +13,30 @@ function parseRunProcessResult(stdout) {
|
|
|
return []
|
|
|
}
|
|
|
|
|
|
-/** 正常完成才返回:run-process 脚本跑完并退出时调用 */
|
|
|
+/** run-process 脚本跑完并退出时调用,按结果设红或灰 */
|
|
|
function onRunComplete(setIsRunning, res, lastSelectedDevices) {
|
|
|
- // setIsRunning(false)
|
|
|
let failedIps = parseRunProcessResult(res.stdout || '')
|
|
|
if (failedIps.length === 0 && res.exitCode !== 0 && lastSelectedDevices?.length) {
|
|
|
failedIps = [lastSelectedDevices[0]]
|
|
|
}
|
|
|
- setExecutionStatus(false, [], failedIps)
|
|
|
+ setExecutionStatus('red', failedIps)
|
|
|
}
|
|
|
|
|
|
-/** 执行中途有错误返回:脚本抛错、崩溃、超时等 Promise reject 时调用 */
|
|
|
+/** 脚本抛错、崩溃、超时等 Promise reject 时调用,置灰 */
|
|
|
function onRunError(setIsRunning) {
|
|
|
- // setIsRunning(false)
|
|
|
- setExecutionStatus(false, [], [])
|
|
|
+ setExecutionStatus('gray')
|
|
|
}
|
|
|
|
|
|
class ProcessItemClass {
|
|
|
constructor() {}
|
|
|
|
|
|
+ /** 初始化流程项与 setIsRunning 引用 */
|
|
|
init(processInfo, setIsRunning) {
|
|
|
this.processInfo = processInfo
|
|
|
this.setIsRunning = setIsRunning
|
|
|
}
|
|
|
|
|
|
+ /** 勾选设备后启动 run-process,并维护执行状态灯 */
|
|
|
play() {
|
|
|
const selectedDevices = getSelectedDevices()
|
|
|
if (!Array.isArray(selectedDevices) || selectedDevices.length === 0) {
|
|
|
@@ -44,31 +44,37 @@ class ProcessItemClass {
|
|
|
hintView.show()
|
|
|
return
|
|
|
}
|
|
|
+ this._stopped = false
|
|
|
this.setIsRunning(true)
|
|
|
this._lastRunParams = [JSON.stringify(selectedDevices), this.processInfo.name]
|
|
|
- setExecutionStatus(true, selectedDevices, [])
|
|
|
+ setExecutionStatus('green')
|
|
|
window.electronAPI.runNodejsScript('run-process', ...this._lastRunParams)
|
|
|
.then((res) => {
|
|
|
+ if (this._stopped) return
|
|
|
const normalExit = res.exitCode === 0 || res.exitCode === 1
|
|
|
if (normalExit) {
|
|
|
onRunComplete(this.setIsRunning, res, selectedDevices)
|
|
|
- } else {
|
|
|
- onRunError(this.setIsRunning)
|
|
|
+ return
|
|
|
}
|
|
|
+ onRunError(this.setIsRunning)
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ if (this._stopped) return
|
|
|
+ onRunError(this.setIsRunning)
|
|
|
})
|
|
|
- .catch(() => onRunError(this.setIsRunning))
|
|
|
}
|
|
|
|
|
|
+ /** 停止当前 run-process 并置灰,忽略后续 then/catch 对状态的覆盖 */
|
|
|
stop() {
|
|
|
+ this._stopped = true
|
|
|
this.setIsRunning(false)
|
|
|
- setExecutionStatus(false, [], [])
|
|
|
+ setExecutionStatus('gray')
|
|
|
const params = this._lastRunParams || []
|
|
|
window.electronAPI.killNodejsScript('run-process', ...params).catch(() => {})
|
|
|
}
|
|
|
|
|
|
- delete() {
|
|
|
-
|
|
|
- }
|
|
|
+ /** 删除本流程项(预留) */
|
|
|
+ delete() {}
|
|
|
}
|
|
|
|
|
|
export { ProcessItemClass }
|