From 85c1b030b7e84bfc617299632694aaed72b4e91a Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Tue, 3 May 2016 19:04:04 -0700 Subject: [PATCH] Revert "feat(mailto): Allow N1 to be default client on windows" This reverts commit fad7c1ae86a598c3ebdf2702b6071037068f7ede. --- .../notification-mailto/lib/main.coffee | 2 + .../lib/tabs/workspace-section.jsx | 10 +++-- spec/launch-services-spec.coffee | 4 ++ src/launch-services.coffee | 42 ++++++++++--------- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/internal_packages/notification-mailto/lib/main.coffee b/internal_packages/notification-mailto/lib/main.coffee index e55817494..4e91aa6c2 100644 --- a/internal_packages/notification-mailto/lib/main.coffee +++ b/internal_packages/notification-mailto/lib/main.coffee @@ -9,6 +9,8 @@ module.exports = activate: (@state) -> @services = new LaunchServices() + return unless @services.available() + # We shouldn't ask if they've already said No return if NylasEnv.config.get(NOTIF_SETTINGS_KEY) is true diff --git a/internal_packages/preferences/lib/tabs/workspace-section.jsx b/internal_packages/preferences/lib/tabs/workspace-section.jsx index 84a77e0ec..b6937c6b0 100644 --- a/internal_packages/preferences/lib/tabs/workspace-section.jsx +++ b/internal_packages/preferences/lib/tabs/workspace-section.jsx @@ -8,9 +8,11 @@ class DefaultMailClientItem extends React.Component { super(); this.state = {defaultClient: false}; this._services = new LaunchServices(); - this._services.isRegisteredForURLScheme('mailto', (registered) => { - if (this._mounted) this.setState({defaultClient: registered}); - }); + if (this._services.available()) { + this._services.isRegisteredForURLScheme('mailto', (registered) => { + if (this._mounted) this.setState({defaultClient: registered}); + }); + } } componentDidMount() { @@ -33,7 +35,7 @@ class DefaultMailClientItem extends React.Component { } render() { - if (process.platform !== "darwin") return false; + if (process.platform === "win32") return false; return (
diff --git a/spec/launch-services-spec.coffee b/spec/launch-services-spec.coffee index c9a2ae0f6..5fe606ef2 100644 --- a/spec/launch-services-spec.coffee +++ b/spec/launch-services-spec.coffee @@ -125,6 +125,10 @@ describe "LaunchServices", -> execHitory = [] @services = new LaunchServices.LaunchServicesMac() + describe "available", -> + it "should return true", -> + expect(@services.available()).toEqual(true) + describe "readDefaults", -> describe "writeDefaults", -> diff --git a/src/launch-services.coffee b/src/launch-services.coffee index 1827d63a9..1ae395ccf 100644 --- a/src/launch-services.coffee +++ b/src/launch-services.coffee @@ -1,9 +1,25 @@ exec = require('child_process').exec -app = require('electron').remote.app fs = require('fs') + bundleIdentifier = 'com.nylas.nylas-mail' +class LaunchServicesUnavailable + available: -> + false + + isRegisteredForURLScheme: (scheme, callback) -> + throw new Error "isRegisteredForURLScheme is not available" + + resetURLScheme: (scheme, callback) -> + throw new Error "resetURLScheme is not available" + + registerForURLScheme: (scheme, callback) -> + throw new Error "registerForURLScheme is not available" + class LaunchServicesLinux + available: -> + true + isRegisteredForURLScheme: (scheme, callback) -> throw new Error "isRegisteredForURLScheme is async, provide a callback" unless callback exec "xdg-mime query default x-scheme-handler/#{scheme}", (err, stdout, stderr) -> @@ -24,6 +40,9 @@ class LaunchServicesMac constructor: -> @secure = false + available: -> + true + getLaunchServicesPlistPath: (callback) -> secure = "#{process.env.HOME}/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist" insecure = "#{process.env.HOME}/Library/Preferences/com.apple.LaunchServices.plist" @@ -98,24 +117,7 @@ class LaunchServicesMac @writeDefaults(defaults, callback) -class LaunchServicesElectron - constructor: -> - - isRegisteredForURLScheme: (scheme, callback) -> - process.nextTick => - callback(app.isDefaultProtocolClient(scheme)) - - resetURLScheme: (scheme, callback) -> - process.nextTick => - app.removeAsDefaultProtocolClient(scheme) - callback(null, null) if callback - - registerForURLScheme: (scheme, callback) -> - process.nextTick => - app.setAsDefaultProtocolClient(scheme) - callback(null, null) if callback - -module.exports = LaunchServicesElectron +module.exports = LaunchServicesUnavailable if process.platform is 'darwin' module.exports = LaunchServicesMac else if process.platform is 'linux' @@ -123,4 +125,4 @@ else if process.platform is 'linux' module.exports.LaunchServicesMac = LaunchServicesMac module.exports.LaunchServicesLinux = LaunchServicesLinux -module.exports.LaunchServicesElectron = LaunchServicesElectron +module.exports.LaunchServicesUnavailable = LaunchServicesUnavailable