"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/open/lib/open.js" (7 Feb 2017, 1580 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 var exec = require('child_process').exec
    2   , path = require('path')
    3   ;
    4 
    5 
    6 /**
    7  * open a file or uri using the default application for the file type.
    8  *
    9  * @return {ChildProcess} - the child process object.
   10  * @param {string} target - the file/uri to open.
   11  * @param {string} appName - (optional) the application to be used to open the
   12  *      file (for example, "chrome", "firefox")
   13  * @param {function(Error)} callback - called with null on success, or
   14  *      an error object that contains a property 'code' with the exit
   15  *      code of the process.
   16  */
   17 
   18 module.exports = open;
   19 
   20 function open(target, appName, callback) {
   21   var opener;
   22 
   23   if (typeof(appName) === 'function') {
   24     callback = appName;
   25     appName = null;
   26   }
   27 
   28   switch (process.platform) {
   29   case 'darwin':
   30     if (appName) {
   31       opener = 'open -a "' + escape(appName) + '"';
   32     } else {
   33       opener = 'open';
   34     }
   35     break;
   36   case 'win32':
   37     // if the first parameter to start is quoted, it uses that as the title
   38     // so we pass a blank title so we can quote the file we are opening
   39     if (appName) {
   40       opener = 'start "" "' + escape(appName) + '"';
   41     } else {
   42       opener = 'start ""';
   43     }
   44     break;
   45   default:
   46     if (appName) {
   47       opener = escape(appName);
   48     } else {
   49       // use Portlands xdg-open everywhere else
   50       opener = path.join(__dirname, '../vendor/xdg-open');
   51     }
   52     break;
   53   }
   54 
   55   return exec(opener + ' "' + escape(target) + '"', callback);
   56 }
   57 
   58 function escape(s) {
   59   return s.replace(/"/g, '\\\"');
   60 }