Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Deactivate correctly, take 2 #1036

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ let settingsView = null

let statusView = null

const {CompositeDisposable} = require('atom')

const PackageManager = require('./package-manager')
let packageManager = null

Expand Down Expand Up @@ -42,7 +44,9 @@ module.exports = {
},

activate() {
atom.workspace.addOpener(uri => {
this.disposables = new CompositeDisposable()

this.disposables.add(atom.workspace.addOpener(uri => {
if (uri.startsWith(CONFIG_URI)) {
if (settingsView == null || settingsView.destroyed) {
settingsView = this.createSettingsView({uri})
Expand All @@ -56,9 +60,9 @@ module.exports = {
}
return settingsView
}
})
}))

atom.commands.add('atom-workspace', {
this.disposables.add(atom.commands.add('atom-workspace', {
'settings-view:open'() { atom.workspace.open(CONFIG_URI) },
'settings-view:core'() { atom.workspace.open(`${CONFIG_URI}/core`) },
'settings-view:editor'() { atom.workspace.open(`${CONFIG_URI}/editor`) },
Expand All @@ -70,10 +74,10 @@ module.exports = {
'settings-view:view-installed-packages'() { atom.workspace.open(`${CONFIG_URI}/packages`) },
'settings-view:uninstall-packages'() { atom.workspace.open(`${CONFIG_URI}/packages`) },
'settings-view:check-for-package-updates'() { atom.workspace.open(`${CONFIG_URI}/updates`) }
})
}))

if (process.platform === 'win32' && require('atom').WinShell != null) {
atom.commands.add('atom-workspace', {'settings-view:system'() { atom.workspace.open(`${CONFIG_URI}/system`) }})
this.disposables.add(atom.commands.add('atom-workspace', {'settings-view:system'() { atom.workspace.open(`${CONFIG_URI}/system`) }}))
}

if (!localStorage.getItem('hasSeenDeprecatedNotification')) {
Expand All @@ -85,8 +89,11 @@ module.exports = {
},

deactivate() {
if (this.disposables) this.disposables.dispose()
if (settingsView) settingsView.destroy()
if (packageManager) packageManager.destroy()
if (statusView) statusView.destroy()
this.disposables = null
settingsView = null
packageManager = null
statusView = null
Expand Down
3 changes: 3 additions & 0 deletions lib/package-manager.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class PackageManager

@emitter = new Emitter

destroy: ->
@emitter.dispose()

getClient: ->
@client ?= new Client(this)

Expand Down
158 changes: 76 additions & 82 deletions spec/settings-view-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -199,106 +199,100 @@ describe "SettingsView", ->
expect(atom.workspace.getActivePaneItem().activePanel)
.toEqual name: 'Updates', options: uri: 'atom://config/updates'

describe "when atom.workspace.open() is used with a config URI", ->
focusIsWithinActivePanel = ->
activePanel = settingsView.panelsByName[settingsView.activePanel.name]
activePanel.element is document.activeElement or activePanel.element.contains(document.activeElement)

expectActivePanelToBeKeyboardScrollable = ->
activePanel = settingsView.panelsByName[settingsView.activePanel.name]
spyOn(activePanel, 'pageDown')
atom.commands.dispatch(activePanel.element, 'core:page-down')
expect(activePanel.pageDown).toHaveBeenCalled()
spyOn(activePanel, 'pageUp')
atom.commands.dispatch(activePanel.element, 'core:page-up')
expect(activePanel.pageUp).toHaveBeenCalled()

beforeEach ->
settingsView = null

it "opens the settings to the correct panel with atom://config/<panel-name> and that panel is keyboard-scrollable", ->
waitsForPromise ->
atom.workspace.open('atom://config').then (s) -> settingsView = s

waitsFor (done) -> process.nextTick(done)
runs ->
expect(settingsView.activePanel)
.toEqual name: 'Core', options: {}
expect(focusIsWithinActivePanel()).toBe true
expectActivePanelToBeKeyboardScrollable()

waitsForPromise ->
atom.workspace.open('atom://config/editor').then (s) -> settingsView = s
for i in [1..5]
describe "when atom.workspace.open() is used with a config URI #{i}", ->
focusIsWithinActivePanel = ->
activePanel = settingsView.panelsByName[settingsView.activePanel.name]
process.stdout.write(document.activeElement.outerHTML)
activePanel.element.contains(document.activeElement)

expectActivePanelToBeKeyboardScrollable = ->
activePanel = settingsView.panelsByName[settingsView.activePanel.name]
spyOn(activePanel, 'pageDown')
atom.commands.dispatch(activePanel.element, 'core:page-down')
expect(activePanel.pageDown).toHaveBeenCalled()
spyOn(activePanel, 'pageUp')
atom.commands.dispatch(activePanel.element, 'core:page-up')
expect(activePanel.pageUp).toHaveBeenCalled()

beforeEach ->
settingsView = null

it "opens the settings to the correct panel with atom://config/<panel-name> and that panel is keyboard-scrollable", ->
waitsForPromise ->
atom.workspace.open('atom://config').then (s) -> settingsView = s

waits 1
runs ->
expect(settingsView.activePanel)
.toEqual name: 'Editor', options: uri: 'atom://config/editor'
expect(focusIsWithinActivePanel()).toBe true
expectActivePanelToBeKeyboardScrollable()
runs ->
expect(settingsView.activePanel)
.toEqual name: 'Core', options: {}
expect(focusIsWithinActivePanel()).toBe true
expectActivePanelToBeKeyboardScrollable()

waitsForPromise ->
atom.workspace.open('atom://config/keybindings').then (s) -> settingsView = s
waitsForPromise ->
atom.workspace.open('atom://config/editor').then (s) -> settingsView = s

waits 1
runs ->
expect(settingsView.activePanel)
.toEqual name: 'Keybindings', options: uri: 'atom://config/keybindings'
expect(focusIsWithinActivePanel()).toBe true
expectActivePanelToBeKeyboardScrollable()
runs ->
expect(settingsView.activePanel)
.toEqual name: 'Editor', options: uri: 'atom://config/editor'
expect(focusIsWithinActivePanel()).toBe true
expectActivePanelToBeKeyboardScrollable()

waitsForPromise ->
atom.workspace.open('atom://config/packages').then (s) -> settingsView = s
waitsForPromise ->
atom.workspace.open('atom://config/keybindings').then (s) -> settingsView = s

waits 1
runs ->
expect(settingsView.activePanel)
.toEqual name: 'Packages', options: uri: 'atom://config/packages'
expect(focusIsWithinActivePanel()).toBe true
expectActivePanelToBeKeyboardScrollable()
runs ->
expect(settingsView.activePanel)
.toEqual name: 'Keybindings', options: uri: 'atom://config/keybindings'
expect(focusIsWithinActivePanel()).toBe true
expectActivePanelToBeKeyboardScrollable()

waitsForPromise ->
atom.workspace.open('atom://config/themes').then (s) -> settingsView = s
waitsForPromise ->
atom.workspace.open('atom://config/packages').then (s) -> settingsView = s

waits 1
runs ->
expect(settingsView.activePanel)
.toEqual name: 'Themes', options: uri: 'atom://config/themes'
expect(focusIsWithinActivePanel()).toBe true
expectActivePanelToBeKeyboardScrollable()
runs ->
expect(settingsView.activePanel)
.toEqual name: 'Packages', options: uri: 'atom://config/packages'
expect(focusIsWithinActivePanel()).toBe true
expectActivePanelToBeKeyboardScrollable()

waitsForPromise ->
atom.workspace.open('atom://config/updates').then (s) -> settingsView = s
waitsForPromise ->
atom.workspace.open('atom://config/themes').then (s) -> settingsView = s

waits 1
runs ->
expect(settingsView.activePanel)
.toEqual name: 'Updates', options: uri: 'atom://config/updates'
expect(focusIsWithinActivePanel()).toBe true
expectActivePanelToBeKeyboardScrollable()
runs ->
expect(settingsView.activePanel)
.toEqual name: 'Themes', options: uri: 'atom://config/themes'
expect(focusIsWithinActivePanel()).toBe true
expectActivePanelToBeKeyboardScrollable()

waitsForPromise ->
atom.workspace.open('atom://config/install').then (s) -> settingsView = s
waitsForPromise ->
atom.workspace.open('atom://config/updates').then (s) -> settingsView = s

hasSystemPanel = false
waits 1
runs ->
expect(settingsView.activePanel)
.toEqual name: 'Install', options: uri: 'atom://config/install'
expect(focusIsWithinActivePanel()).toBe true
expectActivePanelToBeKeyboardScrollable()
hasSystemPanel = settingsView.panelsByName['System']?
runs ->
expect(settingsView.activePanel)
.toEqual name: 'Updates', options: uri: 'atom://config/updates'
expect(focusIsWithinActivePanel()).toBe true
expectActivePanelToBeKeyboardScrollable()

if hasSystemPanel
waitsForPromise ->
atom.workspace.open('atom://config/system').then (s) -> settingsView = s
atom.workspace.open('atom://config/install').then (s) -> settingsView = s

waits 1
hasSystemPanel = false
runs ->
expect(settingsView.activePanel)
.toEqual name: 'System', options: uri: 'atom://config/system'
.toEqual name: 'Install', options: uri: 'atom://config/install'
expect(focusIsWithinActivePanel()).toBe true
expectActivePanelToBeKeyboardScrollable()
hasSystemPanel = settingsView.panelsByName['System']?

if hasSystemPanel
waitsForPromise ->
atom.workspace.open('atom://config/system').then (s) -> settingsView = s

runs ->
expect(settingsView.activePanel)
.toEqual name: 'System', options: uri: 'atom://config/system'
expect(focusIsWithinActivePanel()).toBe true
expectActivePanelToBeKeyboardScrollable()

it "opens the package settings view with atom://config/packages/<package-name>", ->
waitsForPromise ->
Expand Down