How to detect current profile for XUL application?

本文提供了一种解决XUL应用在多配置文件模式下获取当前使用配置文件的方法,通过检测配置文件根目录文件夹名称,并利用File API获取当前配置文件路径。
标题: 如何获得XUL应用的当前profile,希望这篇英文日志能够帮到惯用英语搜索的人

When we launch our XUL application in multiple profiles mode, we may need to know which profile it works on.

Mozilla provides the interfaces as [color=blue][b]nsIToolkitProfileService [/b][/color]to get current profile by reading the attribute "[color=blue]selectedProfile[/color]". But in some cases, it doesn't work.

For example, we launch XUL as "
xulrunner.exe -no-remote -profile <profile path or name>
", you can't get the right profile, it always return the default profile configured in file "
//$USERPROFILE\Application Data\$vendor\$appname\Profiles\$random.default
".

I solved this problem by detecting the folder name of the profile root directory. As for the same reason, you can't get the folder from nsIToolkitProfileService. But, we can get current profile root dir, from the File API. For example,

var dirService = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties);
var profDir = dirService.get("ProfD", Components.interfaces.nsIFile);
var profName = profDir.leafName;


Simple, but it works well. ;)
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值