mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-01 13:14:16 +08:00
fix(mailto): Linux support for mailto links
Summary: Mailto link handling for ubuntu and other linux platforms Test Plan: A few new tests Reviewers: dillon, evan Reviewed By: dillon, evan Differential Revision: https://phab.nylas.com/D2023
This commit is contained in:
parent
9c7259227d
commit
43e9b4cf49
3 changed files with 59 additions and 13 deletions
|
@ -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;
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue