Skip to content

Commit

Permalink
Merge pull request #134 from lifeomic/upgrade-pkg-and-double-click-su…
Browse files Browse the repository at this point in the history
…pport

Improve double-click support on macos.
  • Loading branch information
hemp authored Feb 28, 2020
2 parents e387257 + f8e03ed commit 8dc82b4
Show file tree
Hide file tree
Showing 5 changed files with 303 additions and 231 deletions.
7 changes: 5 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ node_modules/.bin/pkg --target node12-linux-x64 --output target/linux-x64/life-e
node_modules/.bin/pkg --target node12-win-x64 --output target/windows-x64/life-export.exe life-export.js
node_modules/.bin/pkg --target node12-macos-x64 --output target/macos-x64/life-export life-export.js

(cd target/linux-x64 && zip -q -9 ../lo-linux-x64.zip lo life-export)
cp node_modules/open/xdg-open target/linux-x64/.
cp node_modules/open/xdg-open target/macos-x64/.

(cd target/linux-x64 && zip -q -9 ../lo-linux-x64.zip lo life-export xdg-open)
(cd target/windows-x64 && zip -q -9 ../lo-windows-x64.zip lo.exe life-export.exe)
(cd target/macos-x64 && zip -q -9 ../lo-macos-x64.zip lo life-export)
(cd target/macos-x64 && zip -q -9 ../lo-macos-x64.zip lo life-export xdg-open)
9 changes: 1 addition & 8 deletions lib/oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,7 @@ function showLogin (environment, state, verifier) {
const url = `${config.get(`${environment}.apiUrl`)}/v1/oauth/authorize?${querystring.stringify(opts)}`;
debug(`opening ${url}`);

const openOptions = {};
// This is a hack to make open work on Linux when bundling lo as an EXE.
// The xdg-open embedded in the EXE does not work:
if (process.argv[0].endsWith('lo') && process.platform === 'linux') {
openOptions.app = 'xdg-open';
}

open(url, openOptions).then(() => {
open(url).then(() => {
console.log(chalk.green('Opened browser for auth...'));
}).catch((e) => {
console.log(chalk.red('Failed to open browser.', e));
Expand Down
13 changes: 13 additions & 0 deletions life-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,24 @@ const fs = require('fs');
const mkdirp = require('mkdirp');
const os = require('os');

const CMD = process.argv[0];
const DATA_DIR = 'life-data';
const FILENAME = 'life-export';
const LIFE_PROJECT = 'f82a69fb-3f0c-4405-9b7f-8df05aaec159';
const LO = os.platform() === 'win32' ? 'lo.exe' : './lo';

(async () => {
console.log(chalk.green('Launched arguments:'), chalk.bold(process.argv));
console.log(chalk.green('Launched directory:'), chalk.bold(process.cwd()));

// On Mac, when `life-export` is double clicked, it is launched in the home diretory of the user.
// Attempt to locate the life-export executable and make that the working directory.
if (CMD.endsWith(FILENAME)) {
const workingDir = CMD.substring(0, CMD.length - FILENAME.length);
console.log(chalk.green('Changing directory to:'), chalk.bold(workingDir));
process.chdir(workingDir);
}

await mkdirp(DATA_DIR);
console.log(chalk.green('LIFE data will be exported into directory named:'), chalk.bold(DATA_DIR));

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"ava": "^0.25.0",
"eslint": "^4.19.1",
"memory-streams": "^0.1.3",
"pkg": "^4.3.7",
"pkg": "^4.4.3",
"proxyquire": "^2.1.0",
"sinon": "^4.5.0"
},
Expand Down
Loading

0 comments on commit 8dc82b4

Please sign in to comment.