From f007f583c7f3c1ef61a3d1e4d6b5a5d4011f9099 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Fri, 16 Oct 2020 00:43:33 +0200 Subject: [PATCH] Add WSL detection for linux hosts --- openurl.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/openurl.js b/openurl.js index d8c17a0..ec042bc 100644 --- a/openurl.js +++ b/openurl.js @@ -2,6 +2,17 @@ var spawn = require('child_process').spawn; var command; +function isWSL() { + const fs = require('fs'); + try { + const contents = fs.readFileSync('/proc/version', 'utf-8'); + return Boolean(contents.match(/.*microsoft|wsl.*/i)); + } catch (err) { + /* swallow */ + return false; + } +} + switch(process.platform) { case 'darwin': command = 'open'; @@ -10,7 +21,7 @@ switch(process.platform) { command = 'explorer.exe'; break; case 'linux': - command = 'xdg-open'; + command = isWSL() ? 'explorer.exe' : 'xdg-open'; break; default: throw new Error('Unsupported platform: ' + process.platform); @@ -65,4 +76,4 @@ function mailto(recipients, fields, recipientsSeparator, callback) { } exports.open = open; -exports.mailto = mailto; \ No newline at end of file +exports.mailto = mailto;