@@ -26,7 +26,7 @@ export class FFBoxService extends (EventEmitter as new () => TypedEventEmitter<F
2626 private workingStatus : WorkingStatus = WorkingStatus . idle ;
2727 private maxThreads = 1 ;
2828 private ffmpegVersion = '' ;
29- private ffmpegPath = 'ffmpeg ' ;
29+ private ffmpegPath = '' ;
3030 private customFFmpegPath : string ;
3131 private globalTask : ServiceTask ;
3232 public notifications : Notification [ ] = [ ] ;
@@ -66,7 +66,8 @@ export class FFBoxService extends (EventEmitter as new () => TypedEventEmitter<F
6666 this . maxThreads = currentMaxThreads ;
6767 log . info ( `设定最大同时运行任务数为 ${ this . maxThreads } ` ) ;
6868 const customFFmpegPath = await localConfig . get ( 'service.customFFmpegPath' ) ;
69- if ( this . customFFmpegPath !== customFFmpegPath ) {
69+ // 发生了变更,或者初始化时 ffmpegPath 为空(如果之前已经初始化过,那么 customFFmpegPath 两者之一不为空)
70+ if ( this . customFFmpegPath !== customFFmpegPath || ! this . ffmpegPath && ! customFFmpegPath ) {
7071 this . customFFmpegPath = customFFmpegPath as any || undefined ;
7172 this . initFFmpeg ( ) ;
7273 }
@@ -91,24 +92,25 @@ export class FFBoxService extends (EventEmitter as new () => TypedEventEmitter<F
9192 this . ffmpegPath = this . customFFmpegPath ;
9293 } else {
9394 log . info ( '检查 FFmpeg 路径和版本。' ) ;
94- if ( process . platform === 'win32' ) {
95- this . ffmpegPath = 'ffmpeg' ;
96- }
95+ this . ffmpegPath = 'ffmpeg' ;
9796 if ( process . platform === 'darwin' ) {
9897 await fsPromise . access ( path . join ( process . execPath , '../ffmpeg' ) , fs . constants . X_OK ) . then ( ( result ) => {
99- this . ffmpegPath = path . join ( process . execPath , '../ffmpeg' ) ; // 【程序目录】沙箱运行模式,service 与 ffmpeg 处在同一层级
98+ // 【程序目录】沙箱运行模式,service 与 ffmpeg 处在同一层级(此时 execPath 就是 FFBox.app 所在的绝对路径)
99+ this . ffmpegPath = path . join ( process . execPath , '../ffmpeg' ) ;
100100 } ) . catch ( ( ) => { } ) ;
101101 await fsPromise . access ( '/usr/local/bin/ffmpeg' , fs . constants . X_OK ) . then ( ( result ) => {
102- this . ffmpegPath = '/usr/local/bin/ffmpeg' ; // 【系统目录】macOS 只允许用户往 /usr/local/bin/ 放东西(而不能是 /usr/bin/),且此种情况下需要完整路径才能引用
102+ // 【系统目录】macOS 只允许用户往 /usr/local/bin/ 放东西(而不能是 /usr/bin/),且此种情况下需要完整路径才能引用
103+ this . ffmpegPath = '/usr/local/bin/ffmpeg' ;
103104 } ) . catch ( ( ) => { } ) ;
104105 }
105106 if ( process . platform === 'linux' ) {
106107 await fsPromise . access ( path . join ( process . execPath , '../ffmpeg' ) , fs . constants . X_OK ) . then ( ( result ) => {
107- // 【程序目录】deb 沙箱运行模式。service 与 ffmpeg 处在同一目录(/opt/FFBox/)
108+ // 【程序目录】deb 沙箱运行模式。service 与 ffmpeg 处在同一目录(此时 execPath 是 /opt/FFBox/FFBoxService,cwd 是 /home/[用户名] )
108109 this . ffmpegPath = path . join ( process . execPath , '../ffmpeg' ) ;
109110 } ) . catch ( ( ) => { } ) ;
110111 await fsPromise . access ( path . join ( process . cwd ( ) , 'ffmpeg' ) , fs . constants . X_OK ) . then ( ( result ) => {
111- this . ffmpegPath = path . join ( process . cwd ( ) , 'ffmpeg' ) ; // 【程序目录】AppImage 沙箱运行模式,读取 .AppImage 同级目录
112+ // 【程序目录】AppImage 沙箱运行模式,读取 .AppImage 同级目录(此时 execPath 是 /tmp/.mount_FFBox_[hash]/FFBoxService,cwd 就是终端的 pwd)
113+ this . ffmpegPath = path . join ( process . cwd ( ) , 'ffmpeg' ) ;
112114 } ) . catch ( ( ) => { } ) ;
113115 // 【系统目录】Linux 下 /usr/local/bin/ 和 /usr/bin/ 里的东西均能被直接引用,包括终端执行和沙箱执行,因此此处不需要进行处理
114116 // console.log('路径', process.execPath, process.cwd(), __dirname, this.ffmpegPath);
0 commit comments