How to open file in Mozilla Add-on SDK using system default application

落爺英雄遲暮 提交于 2020-05-01 07:23:08

问题


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.


回答1:


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();


来源:https://stackoverflow.com/questions/26314232/how-to-open-file-in-mozilla-add-on-sdk-using-system-default-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!