mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-10 17:48:50 +08:00
feat(mailto): Allow N1 to be default client on windows
This commit is contained in:
parent
e637f6871c
commit
a08eb3e175
4 changed files with 25 additions and 53 deletions
|
@ -9,9 +9,6 @@ module.exports =
|
|||
activate: (@state) ->
|
||||
@services = new LaunchServices()
|
||||
|
||||
# We can't do anything unless they're on Mac OS X
|
||||
return unless @services.available()
|
||||
|
||||
# We shouldn't ask if they've already said No
|
||||
return if NylasEnv.config.get(NOTIF_SETTINGS_KEY) is true
|
||||
|
||||
|
|
|
@ -8,11 +8,9 @@ class DefaultMailClientItem extends React.Component {
|
|||
super();
|
||||
this.state = {defaultClient: false};
|
||||
this._services = new LaunchServices();
|
||||
if (this._services.available()) {
|
||||
this._services.isRegisteredForURLScheme('mailto', (registered) => {
|
||||
if (this._mounted) this.setState({defaultClient: registered});
|
||||
});
|
||||
}
|
||||
this._services.isRegisteredForURLScheme('mailto', (registered) => {
|
||||
if (this._mounted) this.setState({defaultClient: registered});
|
||||
});
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
|
|
@ -125,10 +125,6 @@ describe "LaunchServices", ->
|
|||
execHitory = []
|
||||
@services = new LaunchServices.LaunchServicesMac()
|
||||
|
||||
describe "available", ->
|
||||
it "should return true", ->
|
||||
expect(@services.available()).toEqual(true)
|
||||
|
||||
describe "readDefaults", ->
|
||||
|
||||
describe "writeDefaults", ->
|
||||
|
@ -213,19 +209,3 @@ describe "LaunchServices", ->
|
|||
spyOn(@services, 'writeDefaults')
|
||||
@services.registerForURLScheme('mailto')
|
||||
expect(@services.writeDefaults).toHaveBeenCalled()
|
||||
|
||||
describe "LaunchServicesLinux", ->
|
||||
describe "available", ->
|
||||
beforeEach ->
|
||||
@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)
|
||||
|
|
|
@ -1,26 +1,9 @@
|
|||
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) ->
|
||||
|
@ -30,20 +13,17 @@ class LaunchServicesLinux
|
|||
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)
|
||||
callback(null, null) if callback
|
||||
|
||||
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)
|
||||
callback(null, null) if callback
|
||||
|
||||
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"
|
||||
|
@ -118,7 +98,24 @@ class LaunchServicesMac
|
|||
@writeDefaults(defaults, callback)
|
||||
|
||||
|
||||
module.exports = LaunchServicesUnavailable
|
||||
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
|
||||
if process.platform is 'darwin'
|
||||
module.exports = LaunchServicesMac
|
||||
else if process.platform is 'linux'
|
||||
|
@ -126,4 +123,4 @@ else if process.platform is 'linux'
|
|||
|
||||
module.exports.LaunchServicesMac = LaunchServicesMac
|
||||
module.exports.LaunchServicesLinux = LaunchServicesLinux
|
||||
module.exports.LaunchServicesUnavailable = LaunchServicesUnavailable
|
||||
module.exports.LaunchServicesElectron = LaunchServicesElectron
|
||||
|
|
Loading…
Reference in a new issue