| 115 | | |
|---|
| 116 | | var mimeInfoService = Components |
|---|
| 117 | | .classes["@mozilla.org/uriloader/external-helper-app-service;1"] |
|---|
| 118 | | .getService(Components.interfaces.nsIMIMEService); |
|---|
| 119 | | var mimeInfo = mimeInfoService |
|---|
| 120 | | .getFromTypeAndExtension( "application/x-userscript+javascript", "user.js" ); |
|---|
| 121 | | mimeInfo.preferredAction = mimeInfo.useHelperApp |
|---|
| 122 | | mimeInfo.preferredApplicationHandler = editor; |
|---|
| 123 | | mimeInfo.launchWithFile( aFile ); |
|---|
| | 115 | launchApplicationWithDoc(editor, aFile); |
|---|
| | 126 | } |
|---|
| | 127 | |
|---|
| | 128 | function launchApplicationWithDoc(appFile, docFile) { |
|---|
| | 129 | var xulRuntime = Components.classes["@mozilla.org/xre/app-info;1"] |
|---|
| | 130 | .getService(Components.interfaces.nsIXULRuntime); |
|---|
| | 131 | // See Mozilla bug: https://bugzilla.mozilla.org/show_bug.cgi?id=411819 |
|---|
| | 132 | // TODO: remove this when nsIMIMEInfo works on windows again. |
|---|
| | 133 | if (xulRuntime.OS.toLowerCase().substring(0, 3) == "win") { |
|---|
| | 134 | var process = Components.classes["@mozilla.org/process/util;1"] |
|---|
| | 135 | .createInstance(Components.interfaces.nsIProcess); |
|---|
| | 136 | process.init(appFile); |
|---|
| | 137 | process.run(false, // blocking |
|---|
| | 138 | [docFile.path], // args |
|---|
| | 139 | 1); // number of args |
|---|
| | 140 | } else { |
|---|
| | 141 | var mimeInfoService = |
|---|
| | 142 | Components.classes["@mozilla.org/uriloader/external-helper-app-service;1"] |
|---|
| | 143 | .getService(Components.interfaces.nsIMIMEService); |
|---|
| | 144 | var mimeInfo = mimeInfoService.getFromTypeAndExtension( |
|---|
| | 145 | "application/x-userscript+javascript", "user.js" ); |
|---|
| | 146 | mimeInfo.preferredAction = mimeInfo.useHelperApp; |
|---|
| | 147 | mimeInfo.preferredApplicationHandler = appFile; |
|---|
| | 148 | mimeInfo.launchWithFile(docFile); |
|---|
| | 149 | } |
|---|