@@ -12,6 +12,7 @@ import {
1212 getAddonVersionDir ,
1313 hasDependentLibs ,
1414 isAddonInstalled ,
15+ getCustomAddonPath ,
1516} from './addonManager' ;
1617
1718export const getPath = ( key ?: string ) => {
@@ -288,34 +289,58 @@ export async function loadWhisperAddon(model: string) {
288289
289290 // 检查是否是可能支持 CUDA 的平台
290291 if ( isPlatformCudaCapable ( ) && useCuda ) {
291- // 获取用户选择的加速包版本
292- const selectedVersion = getSelectedAddonVersion ( ) ;
293-
294- if ( selectedVersion && isAddonInstalled ( selectedVersion ) ) {
295- // 从用户数据目录加载
296- const versionDir = getAddonVersionDir ( selectedVersion ) ;
297- const userAddonPath = path . join ( versionDir , 'addon.node' ) ;
298-
299- if ( fs . existsSync ( userAddonPath ) ) {
300- // 检查并设置依赖库路径(必须在 dlopen 之前)
301- if ( hasDependentLibs ( versionDir ) ) {
302- setupLibraryPath ( versionDir ) ;
303- }
292+ // 优先检查自定义 addon.node 路径
293+ const customPath = getCustomAddonPath ( ) ;
294+
295+ if ( customPath && fs . existsSync ( customPath ) ) {
296+ // 使用自定义路径
297+ const customDir = path . dirname ( customPath ) ;
298+ if ( hasDependentLibs ( customDir ) ) {
299+ setupLibraryPath ( customDir ) ;
300+ }
301+ addonPath = customPath ;
302+ logMessage ( `Loading custom addon from: ${ addonPath } ` , 'info' ) ;
303+ } else if ( customPath ) {
304+ // 自定义路径已设置但文件不存在
305+ logMessage (
306+ `Custom addon path not found: ${ customPath } , falling back to default` ,
307+ 'warning' ,
308+ ) ;
309+ addonPath = path . join ( getExtraResourcesPath ( ) , 'addons' , 'addon.node' ) ;
310+ } else {
311+ // 获取用户选择的加速包版本
312+ const selectedVersion = getSelectedAddonVersion ( ) ;
313+
314+ if ( selectedVersion && isAddonInstalled ( selectedVersion ) ) {
315+ // 从用户数据目录加载
316+ const versionDir = getAddonVersionDir ( selectedVersion ) ;
317+ const userAddonPath = path . join ( versionDir , 'addon.node' ) ;
318+
319+ if ( fs . existsSync ( userAddonPath ) ) {
320+ // 检查并设置依赖库路径(必须在 dlopen 之前)
321+ if ( hasDependentLibs ( versionDir ) ) {
322+ setupLibraryPath ( versionDir ) ;
323+ }
304324
305- addonPath = userAddonPath ;
306- logMessage ( `Loading CUDA addon from userData: ${ addonPath } ` , 'info' ) ;
325+ addonPath = userAddonPath ;
326+ logMessage ( `Loading CUDA addon from userData: ${ addonPath } ` , 'info' ) ;
327+ } else {
328+ // 用户数据目录的 addon 不存在,回退到默认版本
329+ logMessage (
330+ `Selected addon version ${ selectedVersion } not found, falling back to default` ,
331+ 'warning' ,
332+ ) ;
333+ addonPath = path . join (
334+ getExtraResourcesPath ( ) ,
335+ 'addons' ,
336+ 'addon.node' ,
337+ ) ;
338+ }
307339 } else {
308- // 用户数据目录的 addon 不存在,回退到默认版本
309- logMessage (
310- `Selected addon version ${ selectedVersion } not found, falling back to default` ,
311- 'warning' ,
312- ) ;
340+ // 没有安装加速包,使用默认的 no-cuda 版本
313341 addonPath = path . join ( getExtraResourcesPath ( ) , 'addons' , 'addon.node' ) ;
342+ logMessage ( 'No CUDA addon installed, using default addon' , 'info' ) ;
314343 }
315- } else {
316- // 没有安装加速包,使用默认的 no-cuda 版本
317- addonPath = path . join ( getExtraResourcesPath ( ) , 'addons' , 'addon.node' ) ;
318- logMessage ( 'No CUDA addon installed, using default addon' , 'info' ) ;
319344 }
320345 } else if (
321346 platform === 'darwin' &&
0 commit comments