diff --git a/build/resources/linux/nylas.desktop.in b/build/resources/linux/nylas.desktop.in index 5c63e5038..a4db42e88 100644 --- a/build/resources/linux/nylas.desktop.in +++ b/build/resources/linux/nylas.desktop.in @@ -7,4 +7,4 @@ Icon=<%= iconName %> Type=Application StartupNotify=true Categories=GNOME;GTK;Utility;EmailClient;Development; -MimeType=text/plain; +MimeType=text/plain;x-scheme-handler/mailto;x-scheme-handler/nylas; \ No newline at end of file diff --git a/spec-nylas/launch-services-spec.coffee b/spec-nylas/launch-services-spec.coffee index c3768675f..d31ffd51c 100644 --- a/spec-nylas/launch-services-spec.coffee +++ b/spec-nylas/launch-services-spec.coffee @@ -120,11 +120,10 @@ describe "LaunchServices", -> ] - describe "when the platform is darwin", -> + describe "LaunchServicesMac", -> beforeEach -> execHitory = [] - @services = new LaunchServices() - @services.getPlatform = -> 'darwin' + @services = new LaunchServices.LaunchServicesMac() describe "available", -> it "should return true", -> @@ -215,11 +214,18 @@ describe "LaunchServices", -> @services.registerForURLScheme('mailto') expect(@services.writeDefaults).toHaveBeenCalled() - describe "on other platforms", -> + describe "LaunchServicesLinux", -> describe "available", -> beforeEach -> - @services = new LaunchServices() - @services.getPlatform = -> 'win32' + @services = new LaunchServices.LaunchServicesLinux() + + it "should return true", -> + expect(@services.available()).toEqual(true) + + describe "LaunchServicesUnavailable", -> + describe "available", -> + beforeEach -> + @services = new LaunchServices.LaunchServicesUnavailable() it "should return false", -> expect(@services.available()).toEqual(false) diff --git a/src/launch-services.coffee b/src/launch-services.coffee index 9069ee57d..af0e2e565 100644 --- a/src/launch-services.coffee +++ b/src/launch-services.coffee @@ -3,17 +3,46 @@ fs = require('fs') bundleIdentifier = 'com.nylas.nylas-mail' -module.exports = -class LaunchServices +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) -> + return callback(err) if callback and err + callback(null, stdout is 'nylas.desktop') + + resetURLScheme: (scheme, callback) -> + exec "xdg-mime default thunderbird.desktop x-scheme-handler/#{scheme}", (err, stdout, stderr) -> + return callback(err) if callback and err + callback(null, null) + + registerForURLScheme: (scheme, callback) -> + exec "xdg-mime default nylas.desktop x-scheme-handler/#{scheme}", (err, stdout, stderr) -> + return callback(err) if callback and err + callback(null, null) + +class LaunchServicesMac constructor: -> @secure = false - getPlatform: -> - process.platform - available: -> - @getPlatform() is 'darwin' + true getLaunchServicesPlistPath: (callback) -> secure = "#{process.env.HOME}/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist" @@ -87,3 +116,14 @@ class LaunchServices LSHandlerRoleAll: bundleIdentifier @writeDefaults(defaults, callback) + + +module.exports = LaunchServicesUnavailable +if process.platform is 'darwin' + module.exports = LaunchServicesMac +else if process.platform is 'linux' + module.exports = LaunchServicesLinux + +module.exports.LaunchServicesMac = LaunchServicesMac +module.exports.LaunchServicesLinux = LaunchServicesLinux +module.exports.LaunchServicesUnavailable = LaunchServicesUnavailable