|
|
@@ -1,137 +1,23 @@
|
|
|
'use strict';
|
|
|
-
|
|
|
-const path = require('path');
|
|
|
-const fs = require('fs');
|
|
|
const { Controller } = require('ee-core');
|
|
|
-const { spawn } = require('child_process');
|
|
|
+const { checkCameraControlCmdExists, closeCameraControlTips} = require('../utils/camera');
|
|
|
const { liveShow, liveHide, setParams, capture, getParams,CMD,captureLive,closeOtherWindow } = require('../api/camera');
|
|
|
|
|
|
-const { dialog } = require('electron'); // 引入 electron 的 dialog 模块
|
|
|
-const { windowManager } = require('node-window-manager');
|
|
|
-const CoreWindow = require("ee-core/electron/window");
|
|
|
-
|
|
|
-async function checkCameraControlCmdExists(digiCamControlPath) {
|
|
|
- try {
|
|
|
-
|
|
|
- // 拼接 CameraControlCmd.exe 的完整路径
|
|
|
- const exePath = path.join(digiCamControlPath, 'CameraControl.exe');
|
|
|
-
|
|
|
- // 检查文件是否存在
|
|
|
- const exists = await fs.promises.access(exePath, fs.constants.F_OK)
|
|
|
- .then(() => true)
|
|
|
- .catch(() => false);
|
|
|
-
|
|
|
- if (!exists) {
|
|
|
- // 弹出文件夹选择对话框
|
|
|
- const { canceled, filePaths } = await dialog.showOpenDialog({
|
|
|
- title: '选择 digiCamControl 文件夹',
|
|
|
- properties: ['openDirectory']
|
|
|
- });
|
|
|
-
|
|
|
- if (!canceled && filePaths.length > 0) {
|
|
|
- const selectedPath = filePaths[0];
|
|
|
- // 更新 app.config.json 中的 digiCamControl 值
|
|
|
- // config.digiCamControl = selectedPath;
|
|
|
- // fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
|
- digiCamControlPath = selectedPath
|
|
|
- const win = CoreWindow.getMainWindow()
|
|
|
- win.webContents.send('controller.camera.digiCamControlPath', {
|
|
|
- code:0,
|
|
|
- data:selectedPath,
|
|
|
- });
|
|
|
- // return true; // 重新检查文件是否存在
|
|
|
- } else {
|
|
|
- console.error('用户未选择文件夹');
|
|
|
- return {
|
|
|
- status:-1,
|
|
|
- msg:"无法找到或运行 CameraControlCmd.exe",
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- const res = await openCameraControlCmd(digiCamControlPath);
|
|
|
- return res;
|
|
|
- } catch (error) {
|
|
|
- console.error('检查 CameraControlCmd.exe 是否存在时出错:', error);
|
|
|
- throw error;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-async function openCameraControlCmd(digiCamControlPath) {
|
|
|
- return new Promise(async (resolve, reject) => {
|
|
|
- try {
|
|
|
- // 获取 digiCamControl 文件夹路径
|
|
|
-
|
|
|
- // 拼接 CameraControlCmd.exe 的完整路径
|
|
|
- const exePath = path.join(digiCamControlPath, 'CameraControl.exe');
|
|
|
-
|
|
|
- // 检查文件是否存在
|
|
|
- await fs.promises.access(exePath, fs.constants.F_OK);
|
|
|
- try {
|
|
|
-
|
|
|
- const child = spawn(exePath);
|
|
|
-
|
|
|
- child.stdout.on('data', (data) => {
|
|
|
+const { readConfigFile } = require('../utils/config');
|
|
|
|
|
|
- resolve(true)
|
|
|
- });
|
|
|
-
|
|
|
- child.on('close', (code) => {
|
|
|
- if (code === 0) {
|
|
|
- reject(false)
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- } catch (error) {
|
|
|
- console.error('error CameraControlCmd.exe:', error);
|
|
|
- throw error;
|
|
|
- }
|
|
|
-
|
|
|
- console.log('CameraControlCmd.exe start');
|
|
|
- } catch (error) {
|
|
|
- console.error('无法找到或运行 CameraControlCmd.exe:', error);
|
|
|
- throw error;
|
|
|
- }
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-async function closeCameraControlTips() {
|
|
|
- try {
|
|
|
- await closeOtherWindow()
|
|
|
-/* const windows = windowManager.getWindows();
|
|
|
-
|
|
|
- for (const window of windows) {
|
|
|
- const title = window.getTitle();
|
|
|
-
|
|
|
- if (title.indexOf('digiCamControl')>=0) {
|
|
|
- console.log(title);
|
|
|
- console.log(window);
|
|
|
- window.minimize(); // 关闭窗口
|
|
|
- // window.hide()
|
|
|
- // break;
|
|
|
- }
|
|
|
- }*/
|
|
|
- }catch (e) {
|
|
|
- console.log(e)
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
let isOPen = true
|
|
|
class CameraController extends Controller {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
}
|
|
|
|
|
|
- async connect(digiCamControlPath) {
|
|
|
+ async connect() {
|
|
|
try {
|
|
|
await getParams('iso').catch(e=>{
|
|
|
isOPen = false;
|
|
|
})
|
|
|
if(!isOPen){
|
|
|
- await checkCameraControlCmdExists(digiCamControlPath)
|
|
|
+ await checkCameraControlCmdExists()
|
|
|
await CMD('All_Minimize')
|
|
|
await closeCameraControlTips()
|
|
|
isOPen = true
|
|
|
@@ -150,9 +36,12 @@ class CameraController extends Controller {
|
|
|
}
|
|
|
return true;
|
|
|
} catch (error) {
|
|
|
+
|
|
|
+ let msg = '请安装digiCamControl软件,并打开digiCamControl软件的web服务,端口为5513'
|
|
|
+ if(readConfigFile().controlType === 'SmartShooter') msg = '请安装SmartShooter5软件'
|
|
|
return {
|
|
|
status:-1,
|
|
|
- msg:"请安装digiCamControl软件,并打开digiCamControl软件的web服务,端口为5513",
|
|
|
+ msg,
|
|
|
}
|
|
|
}
|
|
|
}
|