|
|
@@ -90,26 +90,47 @@ function controllerChoiceMatches(config, type, dir) {
|
|
|
&& sameDir(config[spec.pathKey], dir)
|
|
|
}
|
|
|
|
|
|
+function uniqueDirs(dirs) {
|
|
|
+ const result = []
|
|
|
+ for (const dir of dirs) {
|
|
|
+ if (!dir) continue
|
|
|
+ if (result.some((item) => sameDir(item, dir))) continue
|
|
|
+ result.push(dir)
|
|
|
+ }
|
|
|
+ return result
|
|
|
+}
|
|
|
+
|
|
|
+function rememberController(config, detected, dir) {
|
|
|
+ if (!controllerChoiceMatches(config, detected, dir)) {
|
|
|
+ Log.info(`按安装目录识别为 ${CONTROLLERS[detected].label}: ${dir}`)
|
|
|
+ saveControllerChoice(detected, dir)
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ type: detected,
|
|
|
+ ...CONTROLLERS[detected],
|
|
|
+ dir,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
function getController() {
|
|
|
const config = readConfigFile() || {}
|
|
|
const type = normalizeControlType(config.controlType)
|
|
|
const spec = CONTROLLERS[type]
|
|
|
const dir = config.controlPath || config[spec.pathKey] || ""
|
|
|
|
|
|
- // 以目录里实际存在的 exe 为准。
|
|
|
- // 否则会出现 controlPath 已是 Smart Shooter 6,controlType 仍是 digiCamControl,
|
|
|
- // 程序却去这个目录里找 CameraControl.exe。
|
|
|
- const detected = detectController(dir)
|
|
|
- if (detected) {
|
|
|
- if (!controllerChoiceMatches(config, detected, dir)) {
|
|
|
- Log.info(`按安装目录识别为 ${CONTROLLERS[detected].label}: ${dir}`)
|
|
|
- saveControllerChoice(detected, dir)
|
|
|
- }
|
|
|
- return {
|
|
|
- type: detected,
|
|
|
- ...CONTROLLERS[detected],
|
|
|
- dir,
|
|
|
- }
|
|
|
+ // 上次选中的目录里有 exe 时,以那个 exe 为准。
|
|
|
+ // 避免 controlPath 已是 Smart Shooter 6,controlType 仍是 digiCamControl。
|
|
|
+ const selected = detectController(config.controlPath)
|
|
|
+ if (selected) return rememberController(config, selected, config.controlPath)
|
|
|
+
|
|
|
+ // controlPath 无效时,再找该类型自己的目录和出厂目录,避免坏路径挡住已经装好的程序。
|
|
|
+ const fallbackDirs = uniqueDirs([
|
|
|
+ config[spec.pathKey],
|
|
|
+ defaultConfig[spec.pathKey],
|
|
|
+ type === "SmartShooter6" ? defaultConfig.controlPath : "",
|
|
|
+ ])
|
|
|
+ for (const candidate of fallbackDirs) {
|
|
|
+ if (detectController(candidate) === type) return rememberController(config, type, candidate)
|
|
|
}
|
|
|
|
|
|
// 默认 Smart Shooter 6 目录下没有程序时,再找 Smart Shooter 5。只影响本次启动,不回写配置。
|
|
|
@@ -177,10 +198,14 @@ async function ensureCameraController() {
|
|
|
|
|
|
if (!exists) {
|
|
|
// 弹出文件夹选择对话框
|
|
|
- const { canceled, filePaths } = await dialog.showOpenDialog({
|
|
|
+ const dialogOptions = {
|
|
|
title: '选择 相机控制安装软件 文件夹',
|
|
|
properties: ['openDirectory']
|
|
|
- });
|
|
|
+ }
|
|
|
+ const mainWindow = CoreWindow.getMainWindow()
|
|
|
+ const { canceled, filePaths } = mainWindow && !mainWindow.isDestroyed()
|
|
|
+ ? await dialog.showOpenDialog(mainWindow, dialogOptions)
|
|
|
+ : await dialog.showOpenDialog(dialogOptions);
|
|
|
|
|
|
if (!canceled && filePaths.length > 0) {
|
|
|
const selectedPath = filePaths[0];
|
|
|
@@ -203,7 +228,7 @@ async function ensureCameraController() {
|
|
|
}
|
|
|
}
|
|
|
const res = await openCameraControlCmd();
|
|
|
-
|
|
|
+
|
|
|
// Smart Shooter 5 / 6 启动后最小化窗口;digiCamControl 走自己的最小化命令
|
|
|
if(isSmartShooterType(getController().type)){
|
|
|
// 等待软件启动完成
|
|
|
@@ -215,7 +240,7 @@ async function ensureCameraController() {
|
|
|
}
|
|
|
}, 3000); // 等待3秒让软件完全启动
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return res;
|
|
|
} catch (error) {
|
|
|
Log.error('检查 第三方相机控制器 是否存在时出错:', error);
|
|
|
@@ -237,7 +262,10 @@ function openCameraControlCmd() {
|
|
|
|
|
|
let child
|
|
|
try {
|
|
|
- child = spawn(exePath, [], { cwd: path.dirname(exePath) })
|
|
|
+ child = spawn(exePath, [], {
|
|
|
+ cwd: path.dirname(exePath),
|
|
|
+ stdio: 'ignore',
|
|
|
+ })
|
|
|
} catch (error) {
|
|
|
Log.error('无法启动第三方相机控制器:', error)
|
|
|
finish(reject, error)
|
|
|
@@ -248,10 +276,6 @@ function openCameraControlCmd() {
|
|
|
isProcessRunning = true
|
|
|
console.log('[CAMERA-DEBUG] spawn PID:', child.pid, 'cwd:', path.dirname(exePath), '时间:', new Date().toISOString());
|
|
|
|
|
|
- child.stdout.on('data', (data) => {
|
|
|
- console.log('[CAMERA-DEBUG] stdout 收到数据:', data.toString().substring(0, 100));
|
|
|
- });
|
|
|
-
|
|
|
child.on('close', (code) => {
|
|
|
console.log('[CAMERA-DEBUG] close 事件触发! PID:', cameraProcess?.pid, '退出码:', code, '时间:', new Date().toISOString());
|
|
|
isProcessRunning = false;
|