如何使用系统默认应用程序在Mozilla Add-on SDK中打开文件 [英] How to open file in Mozilla Add-on SDK using system default application
问题描述
有没有办法在加载项中的系统默认应用程序中启动打开文件SDK 的环境,或者至少在Firefox插件一般?
我正在寻找多平台的解决方案,所以我宁愿避免像< exec() +( open ,平台检测+
require(sdk / system / child_process code> xdg-open
, RUNDLL32.EXE SHELL32.DLL,OpenAs_RunDLL
)。
类似于 Desktop#open from Java world would be ideal。
解决方法是 nsIFile#launch()。基于文件路径的nsIFile实例可以使用 FileUtils#File 构造函数。
下面的代码演示了如何使用 launch
方法在附加SDK代码中的默认文件浏览器中打开主目录。
var homeDir = require('sdk / system')。
require('chrome').Cu.import('resource://gre/modules/FileUtils.jsm');
new FileUtils.File(homeDir).launch();
Is there any way to initiate opening file in system default application in Add-on SDK environment, or at least in Firefox plugin in general?
I'm looking for multi-platform solution, so I'd rather avoid things like platform detection + require("sdk/system/child_process").exec()
+ (open
, xdg-open
, RUNDLL32.EXE SHELL32.DLL,OpenAs_RunDLL
).
Something like Desktop#open from Java world would be ideal.
The solution is method nsIFile#launch(). Instance of nsIFile based on file path can be obtained using FileUtils#File constructor.
Following code demonstrates usage of launch
method to open home directory in default file browser in Add-on SDK code.
var homeDir = require('sdk/system').pathFor('Home');
require('chrome').Cu.import('resource://gre/modules/FileUtils.jsm');
new FileUtils.File(homeDir).launch();
这篇关于如何使用系统默认应用程序在Mozilla Add-on SDK中打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!