From b1e20d7798e0bff097dd818a67fb3e98c8cb6bdc Mon Sep 17 00:00:00 2001 From: brrd Date: Mon, 4 Apr 2016 23:06:31 +0200 Subject: [PATCH] Handle OSX open-file event Should fix #41 (test needed) --- app/abr-application.js | 4 ++-- app/index.js | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/abr-application.js b/app/abr-application.js index add484e..c6d5936 100644 --- a/app/abr-application.js +++ b/app/abr-application.js @@ -11,13 +11,13 @@ var AbrWindow = require.main.require("./abr-window.js"), parsePath = require("parse-filepath"), themeLoader = require.main.require("./theme-loader.js"); -function AbrApplication () { +function AbrApplication (osxOpenFilePath) { // Windows reference this.windows = []; // IPC get & set this.ipcServer = new ipcServer(this); // Compile LESS theme then open windows - themeLoader.load("abricotine", this.run.bind(this, null)); + themeLoader.load("abricotine", this.run.bind(this, osxOpenFilePath)); } AbrApplication.prototype = { diff --git a/app/index.js b/app/index.js index d1876f2..514ebc5 100644 --- a/app/index.js +++ b/app/index.js @@ -8,9 +8,11 @@ var AbrApplication = require.main.require("./abr-application.js"), app = require("app"), creator = require("./creator.js"); -// Check app is single instance var abrApp = null, - isSecondaryInstance = app.makeSingleInstance(function(argv, workingDir) { + osxOpenFilePath = null; + +// Check app is single instance +var isSecondaryInstance = app.makeSingleInstance(function(argv, workingDir) { process.chdir(workingDir); if (abrApp == null) { console.error("Error when trying to reach primary Abricotine instance"); @@ -25,6 +27,12 @@ if (isSecondaryInstance) { return; } +// OSX open-file +app.on("open-file", function(event, path) { + event.preventDefault(); + osxOpenFilePath = path; +}); + // Quit app when all windows are closed app.on("window-all-closed", function() { if (process.platform != "darwin") { @@ -38,6 +46,6 @@ app.on("ready", function () { creatorFunc() .then(creator.check) .then(function () { - abrApp = new AbrApplication(); + abrApp = new AbrApplication(osxOpenFilePath); }); });