From 239e54631a4a91eb47fe10bf39a75cd4a9e487d3 Mon Sep 17 00:00:00 2001
From: Wliu <50Wliu@users.noreply.github.com>
Date: Fri, 17 Nov 2017 12:21:21 +0100
Subject: [PATCH 01/20] Heavily defer requires for faster activation time
---
lib/popover-component.js | 12 +++--
lib/portal-status-bar-indicator.js | 48 ++++++++++-------
lib/teletype-package.js | 83 +++++++++++++++++-------------
3 files changed, 85 insertions(+), 58 deletions(-)
diff --git a/lib/popover-component.js b/lib/popover-component.js
index bee307f1..14e9f619 100644
--- a/lib/popover-component.js
+++ b/lib/popover-component.js
@@ -1,9 +1,9 @@
const etch = require('etch')
const $ = etch.dom
-const PortalListComponent = require('./portal-list-component')
-const SignInComponent = require('./sign-in-component')
-const PackageOutdatedComponent = require('./package-outdated-component')
-const PackageInitializationErrorComponent = require('./package-initialization-error-component')
+let PortalListComponent = null
+let SignInComponent = null
+let PackageOutdatedComponent = null
+let PackageInitializationErrorComponent = null
module.exports =
class PopoverComponent {
@@ -28,15 +28,18 @@ class PopoverComponent {
let activeComponent
if (isClientOutdated) {
+ if (!PackageOutdatedComponent) PackageOutdatedComponent = require('./package-outdated-component')
activeComponent = $(PackageOutdatedComponent, {
ref: 'packageOutdatedComponent',
workspace
})
} else if (initializationError) {
+ if (!PackageInitializationErrorComponent) PackageInitializationErrorComponent = require('./package-initialization-error-component')
activeComponent = $(PackageInitializationErrorComponent, {
ref: 'packageInitializationErrorComponent'
})
} else if (this.props.authenticationProvider.isSignedIn()) {
+ if (!PortalListComponent) PortalListComponent = require('./portal-list-component')
activeComponent = $(PortalListComponent, {
ref: 'portalListComponent',
localUserIdentity: authenticationProvider.getIdentity(),
@@ -46,6 +49,7 @@ class PopoverComponent {
notificationManager
})
} else {
+ if (!SignInComponent) SignInComponent = require('./sign-in-component')
activeComponent = $(SignInComponent, {
ref: 'signInComponent',
authenticationProvider,
diff --git a/lib/portal-status-bar-indicator.js b/lib/portal-status-bar-indicator.js
index e21fbb94..57fe47c9 100644
--- a/lib/portal-status-bar-indicator.js
+++ b/lib/portal-status-bar-indicator.js
@@ -1,5 +1,5 @@
const {CompositeDisposable} = require('atom')
-const PopoverComponent = require('./popover-component')
+let PopoverComponent = null
module.exports =
class PortalStatusBarIndicator {
@@ -7,14 +7,7 @@ class PortalStatusBarIndicator {
this.props = props
this.subscriptions = new CompositeDisposable()
this.element = buildElement(props)
- this.popoverComponent = new PopoverComponent(props)
-
- if (props.portalBindingManager) {
- this.portalBindingManager = props.portalBindingManager
- this.subscriptions.add(this.portalBindingManager.onDidChange(() => {
- this.updatePortalStatus()
- }))
- }
+ this.element.onclick = this.handleInitialClick.bind(this)
}
attach () {
@@ -23,15 +16,6 @@ class PortalStatusBarIndicator {
item: this,
priority: PRIORITY_BETWEEN_BRANCH_NAME_AND_GRAMMAR
})
- this.tooltip = this.props.tooltipManager.add(
- this.element,
- {
- item: this.popoverComponent,
- class: 'TeletypePopoverTooltip',
- trigger: 'click',
- placement: 'top'
- }
- )
}
destroy () {
@@ -60,6 +44,34 @@ class PortalStatusBarIndicator {
this.element.classList.remove('transmitting')
}
}
+
+ async handleInitialClick () {
+ this.element.onclick = null
+ this.portalBindingManager = await this.props.getPortalBindingManager()
+ this.subscriptions.add(this.portalBindingManager.onDidChange(() => {
+ this.updatePortalStatus()
+ }))
+
+ this.authenticationProvider = await this.props.getAuthenticationProvider()
+ await this.authenticationProvider.signInUsingSavedToken()
+
+ if (!PopoverComponent) PopoverComponent = require('./popover-component')
+ this.popoverComponent = new PopoverComponent(Object.assign(
+ {portalBindingManager: this.portalBindingManager},
+ {authenticationProvider: this.authenticationProvider},
+ this.props
+ ))
+ this.tooltip = this.props.tooltipManager.add(
+ this.element,
+ {
+ item: this.popoverComponent,
+ class: 'TeletypePopoverTooltip',
+ trigger: 'click',
+ placement: 'top'
+ }
+ )
+ this.element.click()
+ }
}
function buildElement (props) {
diff --git a/lib/teletype-package.js b/lib/teletype-package.js
index 45a55246..27e6faee 100644
--- a/lib/teletype-package.js
+++ b/lib/teletype-package.js
@@ -1,9 +1,9 @@
-const {TeletypeClient, Errors} = require('@atom/teletype-client')
const {CompositeDisposable} = require('atom')
-const PortalBindingManager = require('./portal-binding-manager')
-const PortalStatusBarIndicator = require('./portal-status-bar-indicator')
-const AuthenticationProvider = require('./authentication-provider')
-const CredentialCache = require('./credential-cache')
+let [TeletypeClient, Errors] = []
+let PortalBindingManager = null
+let PortalStatusBarIndicator = null
+let AuthenticationProvider = null
+let CredentialCache = null
module.exports =
class TeletypePackage {
@@ -23,21 +23,13 @@ class TeletypePackage {
this.pusherOptions = pusherOptions
this.baseURL = baseURL
this.tetherDisconnectWindow = tetherDisconnectWindow
- this.credentialCache = credentialCache || new CredentialCache()
- this.client = new TeletypeClient({
- pusherKey: this.pusherKey,
- pusherOptions: this.pusherOptions,
- baseURL: this.baseURL,
- pubSubGateway: this.pubSubGateway,
- tetherDisconnectWindow: this.tetherDisconnectWindow
- })
- this.client.onConnectionError(this.handleConnectionError.bind(this))
+ this.credentialCache = credentialCache
this.portalBindingManagerPromise = null
}
activate () {
- console.log('teletype: Using pusher key:', this.pusherKey)
- console.log('teletype: Using base URL:', this.baseURL)
+ // console.log('teletype: Using pusher key:', this.pusherKey)
+ // console.log('teletype: Using base URL:', this.baseURL)
this.subscriptions = new CompositeDisposable()
@@ -53,10 +45,6 @@ class TeletypePackage {
this.subscriptions.add(this.commandRegistry.add('atom-workspace.teletype-Host', {
'teletype:close-portal': () => this.closeHostPortal()
}))
-
- // Initiate sign-in, which will continue asynchronously, since we don't want
- // to block here.
- this.signInUsingSavedToken()
}
async deactivate () {
@@ -65,11 +53,12 @@ class TeletypePackage {
if (this.portalBindingManagerPromise) {
const manager = await this.portalBindingManagerPromise
- await manager.dispose()
+ if (manager) await manager.dispose()
}
}
async sharePortal () {
+ await this.signInUsingSavedToken()
this.showPopover()
if (await this.isSignedIn()) {
@@ -80,6 +69,7 @@ class TeletypePackage {
}
async joinPortal (id) {
+ await this.signInUsingSavedToken()
this.showPopover()
if (await this.isSignedIn()) {
@@ -102,16 +92,14 @@ class TeletypePackage {
}
async consumeStatusBar (statusBar) {
- const teletypeClient = await this.getClient()
- const portalBindingManager = await this.getPortalBindingManager()
- const authenticationProvider = await this.getAuthenticationProvider()
+ const getPortalBindingManager = async () => await this.getPortalBindingManager()
+ const getAuthenticationProvider = async () => await this.getAuthenticationProvider()
+ if (!PortalStatusBarIndicator) PortalStatusBarIndicator = require('./portal-status-bar-indicator')
this.portalStatusBarIndicator = new PortalStatusBarIndicator({
statusBar,
- teletypeClient,
- portalBindingManager,
- authenticationProvider,
+ getPortalBindingManager,
+ getAuthenticationProvider,
isClientOutdated: this.isClientOutdated,
- initializationError: this.initializationError,
tooltipManager: this.tooltipManager,
commandRegistry: this.commandRegistry,
clipboard: this.clipboard,
@@ -172,16 +160,24 @@ class TeletypePackage {
}
getAuthenticationProvider () {
+ if (this.authenticationProvider) return Promise.resolve(this.authenticationProvider)
+
if (!this.authenticationProviderPromise) {
this.authenticationProviderPromise = new Promise(async (resolve, reject) => {
const client = await this.getClient()
if (client) {
- resolve(new AuthenticationProvider({
+ if (!AuthenticationProvider) AuthenticationProvider = require('./authentication-provider')
+ if (!this.credentialCache) {
+ if (!CredentialCache) CredentialCache = require('./credential-cache')
+ this.credentialCache = new CredentialCache()
+ }
+ this.authenticationProvider = new AuthenticationProvider({
client,
credentialCache: this.credentialCache,
notificationManager: this.notificationManager,
workspace: this.workspace
- }))
+ })
+ resolve(this.authenticationProvider)
} else {
this.authenticationProviderPromise = null
resolve(null)
@@ -193,15 +189,19 @@ class TeletypePackage {
}
getPortalBindingManager () {
+ if (this.portalBindingManager) return Promise.resolve(this.portalBindingManager)
+
if (!this.portalBindingManagerPromise) {
this.portalBindingManagerPromise = new Promise(async (resolve, reject) => {
const client = await this.getClient()
if (client) {
- resolve(new PortalBindingManager({
+ if (!PortalBindingManager) PortalBindingManager = require('./portal-binding-manager')
+ this.portalBindingManager = new PortalBindingManager({
client,
workspace: this.workspace,
notificationManager: this.notificationManager
- }))
+ })
+ resolve(this.portalBindingManager)
} else {
this.portalBindingManagerPromise = null
resolve(null)
@@ -213,17 +213,28 @@ class TeletypePackage {
}
async getClient () {
- if (this.initializationError) return null
- if (this.isClientOutdated) return null
-
try {
+ if(!TeletypeClient) ({TeletypeClient, Errors} = require('@atom/teletype-client'))
+ if (this.client) {
+ await this.client.initialize()
+ return this.client
+ }
+
+ this.client = new TeletypeClient({
+ pusherKey: this.pusherKey,
+ pusherOptions: this.pusherOptions,
+ baseURL: this.baseURL,
+ pubSubGateway: this.pubSubGateway,
+ tetherDisconnectWindow: this.tetherDisconnectWindow
+ })
+ this.client.onConnectionError(this.handleConnectionError.bind(this))
+
await this.client.initialize()
return this.client
} catch (error) {
if (error instanceof Errors.ClientOutOfDateError) {
this.isClientOutdated = true
} else {
- this.initializationError = error
this.notificationManager.addError('Failed to initialize the teletype package', {
description: `Establishing a teletype connection failed with error: ${error.message}`,
dismissable: true
From 257c18420fe58da60b7da278bbc22f40db0c04ba Mon Sep 17 00:00:00 2001
From: Wliu <50Wliu@users.noreply.github.com>
Date: Fri, 17 Nov 2017 12:49:15 +0100
Subject: [PATCH 02/20] Update tests to take into account deferred requires
---
lib/portal-status-bar-indicator.js | 1 +
test/teletype-package.test.js | 3 +++
2 files changed, 4 insertions(+)
diff --git a/lib/portal-status-bar-indicator.js b/lib/portal-status-bar-indicator.js
index 57fe47c9..2fea0120 100644
--- a/lib/portal-status-bar-indicator.js
+++ b/lib/portal-status-bar-indicator.js
@@ -33,6 +33,7 @@ class PortalStatusBarIndicator {
}
isPopoverVisible () {
+ if (!this.popoverComponent) return false
return document.contains(this.popoverComponent.element)
}
diff --git a/test/teletype-package.test.js b/test/teletype-package.test.js
index 8ef6683a..17366017 100644
--- a/test/teletype-package.test.js
+++ b/test/teletype-package.test.js
@@ -988,6 +988,9 @@ suite('TeletypePackage', function () {
if (options.signIn == null || options.signIn) {
await credentialCache.set('oauth-token', 'token-' + nextTokenId++)
await pack.signInUsingSavedToken()
+ } else {
+ // We still need to activate the client for some tests
+ await pack.getClient()
}
packages.push(pack)
return pack
From 053cd9767490e734244a0ae3951b855f2326e719 Mon Sep 17 00:00:00 2001
From: Wliu <50Wliu@users.noreply.github.com>
Date: Fri, 17 Nov 2017 13:18:20 +0100
Subject: [PATCH 03/20] Wait for popover to finish initializing before showing
join prompt
---
lib/portal-status-bar-indicator.js | 2 ++
lib/teletype-package.js | 3 ++-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/portal-status-bar-indicator.js b/lib/portal-status-bar-indicator.js
index 2fea0120..1af3b0f6 100644
--- a/lib/portal-status-bar-indicator.js
+++ b/lib/portal-status-bar-indicator.js
@@ -47,6 +47,7 @@ class PortalStatusBarIndicator {
}
async handleInitialClick () {
+ this.initialOpenPromise = new Promise((resolve, reject) => this.resolveInitialOpenPromise = resolve)
this.element.onclick = null
this.portalBindingManager = await this.props.getPortalBindingManager()
this.subscriptions.add(this.portalBindingManager.onDidChange(() => {
@@ -72,6 +73,7 @@ class PortalStatusBarIndicator {
}
)
this.element.click()
+ this.resolveInitialOpenPromise(this.popoverComponent)
}
}
diff --git a/lib/teletype-package.js b/lib/teletype-package.js
index 27e6faee..7898c172 100644
--- a/lib/teletype-package.js
+++ b/lib/teletype-package.js
@@ -145,7 +145,8 @@ class TeletypePackage {
async showJoinPortalPrompt () {
if (!this.portalStatusBarIndicator) return
- const {popoverComponent} = this.portalStatusBarIndicator
+ let {popoverComponent} = this.portalStatusBarIndicator
+ if (!popoverComponent) popoverComponent = await this.portalStatusBarIndicator.initialOpenPromise
const {portalListComponent} = popoverComponent.refs
await portalListComponent.showJoinPortalPrompt()
}
From 3c3b61392d6204a1f3b76eec3120c170b0a428f9 Mon Sep 17 00:00:00 2001
From: Wliu <50Wliu@users.noreply.github.com>
Date: Fri, 17 Nov 2017 13:23:13 +0100
Subject: [PATCH 04/20] Initialize popover component in tests
---
test/teletype-package.test.js | 2 ++
1 file changed, 2 insertions(+)
diff --git a/test/teletype-package.test.js b/test/teletype-package.test.js
index 17366017..1fb63145 100644
--- a/test/teletype-package.test.js
+++ b/test/teletype-package.test.js
@@ -863,6 +863,7 @@ suite('TeletypePackage', function () {
await pack.consumeStatusBar(new FakeStatusBar())
const {portalStatusBarIndicator} = pack
+ await portalStatusBarIndicator.handleInitialClick() // Initialize popover component
const {popoverComponent} = portalStatusBarIndicator
const {packageOutdatedComponent} = popoverComponent.refs
@@ -944,6 +945,7 @@ suite('TeletypePackage', function () {
}
const {popoverComponent} = pack.portalStatusBarIndicator
+ await portalStatusBarIndicator.handleInitialClick() // Initialize popover component
popoverComponent.refs.signInComponent.refs.editor.setText('some-token')
await popoverComponent.refs.signInComponent.signIn()
From 4d959f0b396a780d796c3c660d5be6bd1ac906dd Mon Sep 17 00:00:00 2001
From: Wliu <50Wliu@users.noreply.github.com>
Date: Fri, 17 Nov 2017 13:36:20 +0100
Subject: [PATCH 05/20] PortalBindingManager may not exist
---
lib/portal-status-bar-indicator.js | 8 +++++---
test/teletype-package.test.js | 2 +-
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/lib/portal-status-bar-indicator.js b/lib/portal-status-bar-indicator.js
index 1af3b0f6..ce37f4e6 100644
--- a/lib/portal-status-bar-indicator.js
+++ b/lib/portal-status-bar-indicator.js
@@ -50,9 +50,11 @@ class PortalStatusBarIndicator {
this.initialOpenPromise = new Promise((resolve, reject) => this.resolveInitialOpenPromise = resolve)
this.element.onclick = null
this.portalBindingManager = await this.props.getPortalBindingManager()
- this.subscriptions.add(this.portalBindingManager.onDidChange(() => {
- this.updatePortalStatus()
- }))
+ if (this.portalBindingManager) {
+ this.subscriptions.add(this.portalBindingManager.onDidChange(() => {
+ this.updatePortalStatus()
+ }))
+ }
this.authenticationProvider = await this.props.getAuthenticationProvider()
await this.authenticationProvider.signInUsingSavedToken()
diff --git a/test/teletype-package.test.js b/test/teletype-package.test.js
index 1fb63145..fd34ea81 100644
--- a/test/teletype-package.test.js
+++ b/test/teletype-package.test.js
@@ -945,7 +945,7 @@ suite('TeletypePackage', function () {
}
const {popoverComponent} = pack.portalStatusBarIndicator
- await portalStatusBarIndicator.handleInitialClick() // Initialize popover component
+ await pack.portalStatusBarIndicator.handleInitialClick() // Initialize popover component
popoverComponent.refs.signInComponent.refs.editor.setText('some-token')
await popoverComponent.refs.signInComponent.signIn()
From d29e59953083a1cece919237848e8e5241b52cd7 Mon Sep 17 00:00:00 2001
From: Wliu <50Wliu@users.noreply.github.com>
Date: Fri, 17 Nov 2017 13:38:18 +0100
Subject: [PATCH 06/20] Wait for initial open promise
---
test/teletype-package.test.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/test/teletype-package.test.js b/test/teletype-package.test.js
index fd34ea81..9144e8e4 100644
--- a/test/teletype-package.test.js
+++ b/test/teletype-package.test.js
@@ -214,6 +214,7 @@ suite('TeletypePackage', function () {
// Show popover when running the "Share Portal" command, but prevent sharing unless user is authenticated.
assert(!pack.portalStatusBarIndicator.isPopoverVisible())
assert(!await pack.sharePortal())
+ await pack1.portalStatusBarIndicator.initialOpenPromise
assert(pack.portalStatusBarIndicator.isPopoverVisible())
// Show popover when running the "Join Portal" command, but prevent sharing unless user is authenticated.
From dc0bb5749d215ee4e12255953cabe7fcea0d4c7c Mon Sep 17 00:00:00 2001
From: Wliu <50Wliu@users.noreply.github.com>
Date: Fri, 17 Nov 2017 13:42:03 +0100
Subject: [PATCH 07/20] AuthenticationProvider may not exist
---
lib/portal-status-bar-indicator.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/portal-status-bar-indicator.js b/lib/portal-status-bar-indicator.js
index ce37f4e6..9462c13b 100644
--- a/lib/portal-status-bar-indicator.js
+++ b/lib/portal-status-bar-indicator.js
@@ -57,7 +57,7 @@ class PortalStatusBarIndicator {
}
this.authenticationProvider = await this.props.getAuthenticationProvider()
- await this.authenticationProvider.signInUsingSavedToken()
+ if (this.authenticationProvider) await this.authenticationProvider.signInUsingSavedToken()
if (!PopoverComponent) PopoverComponent = require('./popover-component')
this.popoverComponent = new PopoverComponent(Object.assign(
From eed6912e3272c3dafb0497931728f23c3b734358 Mon Sep 17 00:00:00 2001
From: Wliu <50Wliu@users.noreply.github.com>
Date: Fri, 17 Nov 2017 13:50:20 +0100
Subject: [PATCH 08/20] More null checks
---
lib/popover-component.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/popover-component.js b/lib/popover-component.js
index 14e9f619..75116b26 100644
--- a/lib/popover-component.js
+++ b/lib/popover-component.js
@@ -38,7 +38,7 @@ class PopoverComponent {
activeComponent = $(PackageInitializationErrorComponent, {
ref: 'packageInitializationErrorComponent'
})
- } else if (this.props.authenticationProvider.isSignedIn()) {
+ } else if (this.props.authenticationProvider && this.props.authenticationProvider.isSignedIn()) {
if (!PortalListComponent) PortalListComponent = require('./portal-list-component')
activeComponent = $(PortalListComponent, {
ref: 'portalListComponent',
From 3958837f341cf677c13f56d90bf4d0f28153a564 Mon Sep 17 00:00:00 2001
From: Wliu <50Wliu@users.noreply.github.com>
Date: Fri, 17 Nov 2017 14:00:44 +0100
Subject: [PATCH 09/20] Fix missing props
---
lib/popover-component.js | 8 ++++----
lib/portal-status-bar-indicator.js | 4 ++--
lib/teletype-package.js | 5 ++++-
3 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/lib/popover-component.js b/lib/popover-component.js
index 75116b26..557ca4ec 100644
--- a/lib/popover-component.js
+++ b/lib/popover-component.js
@@ -21,24 +21,24 @@ class PopoverComponent {
render () {
const {
- isClientOutdated, initializationError,
+ isClientOutdated, hasInitializationError,
authenticationProvider, portalBindingManager,
commandRegistry, credentialCache, clipboard, workspace, notificationManager
} = this.props
let activeComponent
- if (isClientOutdated) {
+ if (isClientOutdated()) {
if (!PackageOutdatedComponent) PackageOutdatedComponent = require('./package-outdated-component')
activeComponent = $(PackageOutdatedComponent, {
ref: 'packageOutdatedComponent',
workspace
})
- } else if (initializationError) {
+ } else if (hasInitializationError()) {
if (!PackageInitializationErrorComponent) PackageInitializationErrorComponent = require('./package-initialization-error-component')
activeComponent = $(PackageInitializationErrorComponent, {
ref: 'packageInitializationErrorComponent'
})
- } else if (this.props.authenticationProvider && this.props.authenticationProvider.isSignedIn()) {
+ } else if (authenticationProvider.isSignedIn()) {
if (!PortalListComponent) PortalListComponent = require('./portal-list-component')
activeComponent = $(PortalListComponent, {
ref: 'portalListComponent',
diff --git a/lib/portal-status-bar-indicator.js b/lib/portal-status-bar-indicator.js
index 9462c13b..a3ea6542 100644
--- a/lib/portal-status-bar-indicator.js
+++ b/lib/portal-status-bar-indicator.js
@@ -82,8 +82,8 @@ class PortalStatusBarIndicator {
function buildElement (props) {
const anchor = document.createElement('a')
anchor.classList.add('PortalStatusBarIndicator', 'inline-block')
- if (props.isClientOutdated) anchor.classList.add('outdated')
- if (props.initializationError) anchor.classList.add('initialization-error')
+ if (props.isClientOutdated()) anchor.classList.add('outdated')
+ if (props.hasInitializationError()) anchor.classList.add('initialization-error')
const icon = document.createElement('span')
icon.classList.add('icon', 'icon-radio-tower')
diff --git a/lib/teletype-package.js b/lib/teletype-package.js
index 7898c172..d6501b6f 100644
--- a/lib/teletype-package.js
+++ b/lib/teletype-package.js
@@ -94,12 +94,15 @@ class TeletypePackage {
async consumeStatusBar (statusBar) {
const getPortalBindingManager = async () => await this.getPortalBindingManager()
const getAuthenticationProvider = async () => await this.getAuthenticationProvider()
+ const isClientOutdated = () => this.isClientOutdated
+ const hasInitializationError = () => this.initializationError
if (!PortalStatusBarIndicator) PortalStatusBarIndicator = require('./portal-status-bar-indicator')
this.portalStatusBarIndicator = new PortalStatusBarIndicator({
statusBar,
getPortalBindingManager,
getAuthenticationProvider,
- isClientOutdated: this.isClientOutdated,
+ isClientOutdated,
+ hasInitializationError,
tooltipManager: this.tooltipManager,
commandRegistry: this.commandRegistry,
clipboard: this.clipboard,
From b90bd8046a5d829bd43949c9b1d5f1a05d026019 Mon Sep 17 00:00:00 2001
From: Wliu <50Wliu@users.noreply.github.com>
Date: Fri, 17 Nov 2017 14:13:20 +0100
Subject: [PATCH 10/20] Add error classes after client is initialized
---
lib/portal-status-bar-indicator.js | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/lib/portal-status-bar-indicator.js b/lib/portal-status-bar-indicator.js
index a3ea6542..600d0c26 100644
--- a/lib/portal-status-bar-indicator.js
+++ b/lib/portal-status-bar-indicator.js
@@ -74,16 +74,18 @@ class PortalStatusBarIndicator {
placement: 'top'
}
)
+
+ if (this.props.isClientOutdated()) this.element.classList.add('outdated')
+ if (this.props.hasInitializationError()) this.element.classList.add('initialization-error')
+
this.element.click()
this.resolveInitialOpenPromise(this.popoverComponent)
}
}
-function buildElement (props) {
+function buildElement () {
const anchor = document.createElement('a')
anchor.classList.add('PortalStatusBarIndicator', 'inline-block')
- if (props.isClientOutdated()) anchor.classList.add('outdated')
- if (props.hasInitializationError()) anchor.classList.add('initialization-error')
const icon = document.createElement('span')
icon.classList.add('icon', 'icon-radio-tower')
From 347f4835ebc9934508347404c123c0e5edab2d2b Mon Sep 17 00:00:00 2001
From: Wliu <50Wliu@users.noreply.github.com>
Date: Fri, 17 Nov 2017 14:13:30 +0100
Subject: [PATCH 11/20] Debug extra notification
---
test/teletype-package.test.js | 2 ++
1 file changed, 2 insertions(+)
diff --git a/test/teletype-package.test.js b/test/teletype-package.test.js
index 9144e8e4..e592be61 100644
--- a/test/teletype-package.test.js
+++ b/test/teletype-package.test.js
@@ -913,6 +913,8 @@ suite('TeletypePackage', function () {
assert.equal(type, 'error')
assert.equal(message, 'Failed to initialize the teletype package')
assert(description.includes('an error'))
+
+ console.log(env.notifications.getNotifications()[1].message)
}
{
From 69041f42bca3130d1b0e392da08d3e849ffb67c8 Mon Sep 17 00:00:00 2001
From: Wliu <50Wliu@users.noreply.github.com>
Date: Fri, 17 Nov 2017 15:04:23 +0100
Subject: [PATCH 12/20] ...process.stdout.write?
---
test/teletype-package.test.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/teletype-package.test.js b/test/teletype-package.test.js
index e592be61..3cc0e68a 100644
--- a/test/teletype-package.test.js
+++ b/test/teletype-package.test.js
@@ -914,7 +914,7 @@ suite('TeletypePackage', function () {
assert.equal(message, 'Failed to initialize the teletype package')
assert(description.includes('an error'))
- console.log(env.notifications.getNotifications()[1].message)
+ process.stdout.write(env.notifications.getNotifications()[1].message)
}
{
From 2bd427358974e8483c36a3c5149d11aa16778d94 Mon Sep 17 00:00:00 2001
From: Wliu <50Wliu@users.noreply.github.com>
Date: Fri, 17 Nov 2017 15:06:08 +0100
Subject: [PATCH 13/20] Duh
---
test/teletype-package.test.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/teletype-package.test.js b/test/teletype-package.test.js
index 3cc0e68a..643ed3b2 100644
--- a/test/teletype-package.test.js
+++ b/test/teletype-package.test.js
@@ -947,8 +947,8 @@ suite('TeletypePackage', function () {
throw new Error('some error')
}
- const {popoverComponent} = pack.portalStatusBarIndicator
await pack.portalStatusBarIndicator.handleInitialClick() // Initialize popover component
+ const {popoverComponent} = pack.portalStatusBarIndicator
popoverComponent.refs.signInComponent.refs.editor.setText('some-token')
await popoverComponent.refs.signInComponent.signIn()
From 88082ec4ed0967cb8fba978f6c5c99e3ae4d3598 Mon Sep 17 00:00:00 2001
From: Wliu <50Wliu@users.noreply.github.com>
Date: Fri, 17 Nov 2017 15:09:26 +0100
Subject: [PATCH 14/20] Maybe move it up and actually assert?
---
test/teletype-package.test.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/test/teletype-package.test.js b/test/teletype-package.test.js
index 643ed3b2..292cb5a3 100644
--- a/test/teletype-package.test.js
+++ b/test/teletype-package.test.js
@@ -907,14 +907,14 @@ suite('TeletypePackage', function () {
await pack.joinPortal()
+ assert.equal(env.notifications.getNotifications()[1].message, '???')
+
assert.equal(env.notifications.getNotifications().length, 1)
const {type, message, options} = env.notifications.getNotifications()[0]
const {description} = options
assert.equal(type, 'error')
assert.equal(message, 'Failed to initialize the teletype package')
assert(description.includes('an error'))
-
- process.stdout.write(env.notifications.getNotifications()[1].message)
}
{
From e19ac2eef7c7a72e2063dc16d0aadaa189b14d9c Mon Sep 17 00:00:00 2001
From: Wliu <50Wliu@users.noreply.github.com>
Date: Fri, 17 Nov 2017 15:13:07 +0100
Subject: [PATCH 15/20] Well it would help if I was debugging the correct
assertion
---
test/teletype-package.test.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/test/teletype-package.test.js b/test/teletype-package.test.js
index 292cb5a3..aa177d70 100644
--- a/test/teletype-package.test.js
+++ b/test/teletype-package.test.js
@@ -890,6 +890,8 @@ suite('TeletypePackage', function () {
await pack.sharePortal()
+ assert.equal(env.notifications.getNotifications()[1].message, '???')
+
assert.equal(env.notifications.getNotifications().length, 1)
const {type, message, options} = env.notifications.getNotifications()[0]
const {description} = options
@@ -907,8 +909,6 @@ suite('TeletypePackage', function () {
await pack.joinPortal()
- assert.equal(env.notifications.getNotifications()[1].message, '???')
-
assert.equal(env.notifications.getNotifications().length, 1)
const {type, message, options} = env.notifications.getNotifications()[0]
const {description} = options
From 0d806c6cc14584e5f794a96abb90381db6234831 Mon Sep 17 00:00:00 2001
From: Wliu <50Wliu@users.noreply.github.com>
Date: Fri, 17 Nov 2017 15:47:40 +0100
Subject: [PATCH 16/20] More debuggening
---
test/teletype-package.test.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/test/teletype-package.test.js b/test/teletype-package.test.js
index aa177d70..ed4196a3 100644
--- a/test/teletype-package.test.js
+++ b/test/teletype-package.test.js
@@ -884,14 +884,14 @@ suite('TeletypePackage', function () {
{
const env = buildAtomEnvironment()
const pack = await buildPackage(env, {signIn: false})
+ assert.equal(env.notifications.getNotifications().length, 1)
+
pack.client.initialize = async function () {
throw new Error('an error')
}
await pack.sharePortal()
- assert.equal(env.notifications.getNotifications()[1].message, '???')
-
assert.equal(env.notifications.getNotifications().length, 1)
const {type, message, options} = env.notifications.getNotifications()[0]
const {description} = options
From 8c83e48b7fcc84c3a4a83db5a020420fe1b9ba27 Mon Sep 17 00:00:00 2001
From: Wliu <50Wliu@users.noreply.github.com>
Date: Fri, 17 Nov 2017 19:51:17 +0100
Subject: [PATCH 17/20] Add back accidentally-deleted code
---
lib/teletype-package.js | 4 ++++
test/teletype-package.test.js | 1 -
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/teletype-package.js b/lib/teletype-package.js
index d6501b6f..80afe1d5 100644
--- a/lib/teletype-package.js
+++ b/lib/teletype-package.js
@@ -217,6 +217,9 @@ class TeletypePackage {
}
async getClient () {
+ if (this.initializationError) return null
+ if (this.isClientOutdated) return null
+
try {
if(!TeletypeClient) ({TeletypeClient, Errors} = require('@atom/teletype-client'))
if (this.client) {
@@ -239,6 +242,7 @@ class TeletypePackage {
if (error instanceof Errors.ClientOutOfDateError) {
this.isClientOutdated = true
} else {
+ this.initializationError = error
this.notificationManager.addError('Failed to initialize the teletype package', {
description: `Establishing a teletype connection failed with error: ${error.message}`,
dismissable: true
diff --git a/test/teletype-package.test.js b/test/teletype-package.test.js
index ed4196a3..5d5d6bfe 100644
--- a/test/teletype-package.test.js
+++ b/test/teletype-package.test.js
@@ -884,7 +884,6 @@ suite('TeletypePackage', function () {
{
const env = buildAtomEnvironment()
const pack = await buildPackage(env, {signIn: false})
- assert.equal(env.notifications.getNotifications().length, 1)
pack.client.initialize = async function () {
throw new Error('an error')
From 65a1ac53b4d3abe5895db758ac9ca713ce48b4b2 Mon Sep 17 00:00:00 2001
From: Wliu <50Wliu@users.noreply.github.com>
Date: Fri, 17 Nov 2017 19:55:32 +0100
Subject: [PATCH 18/20] Progress!
---
test/teletype-package.test.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/test/teletype-package.test.js b/test/teletype-package.test.js
index 5d5d6bfe..6ef0e4a6 100644
--- a/test/teletype-package.test.js
+++ b/test/teletype-package.test.js
@@ -924,6 +924,7 @@ suite('TeletypePackage', function () {
}
await pack.consumeStatusBar(new FakeStatusBar())
+ await pack.portalStatusBarIndicator.handleInitialClick() // Initialize popover component
assert.equal(env.notifications.getNotifications().length, 1)
const {type, message, options} = env.notifications.getNotifications()[0]
From b96c9ed55d91b9887810bf9b3d89340504ce5e08 Mon Sep 17 00:00:00 2001
From: Wliu <50Wliu@users.noreply.github.com>
Date: Fri, 17 Nov 2017 20:04:00 +0100
Subject: [PATCH 19/20] :art:
---
test/teletype-package.test.js | 1 -
1 file changed, 1 deletion(-)
diff --git a/test/teletype-package.test.js b/test/teletype-package.test.js
index 6ef0e4a6..bc88283e 100644
--- a/test/teletype-package.test.js
+++ b/test/teletype-package.test.js
@@ -884,7 +884,6 @@ suite('TeletypePackage', function () {
{
const env = buildAtomEnvironment()
const pack = await buildPackage(env, {signIn: false})
-
pack.client.initialize = async function () {
throw new Error('an error')
}
From b24c4362798967827de9534be209ec9ba11761b4 Mon Sep 17 00:00:00 2001
From: Wliu <50Wliu@users.noreply.github.com>
Date: Mon, 20 Nov 2017 23:53:39 +0100
Subject: [PATCH 20/20] Fix rebase
---
test/teletype-package.test.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/teletype-package.test.js b/test/teletype-package.test.js
index bc88283e..98ac0be1 100644
--- a/test/teletype-package.test.js
+++ b/test/teletype-package.test.js
@@ -214,7 +214,7 @@ suite('TeletypePackage', function () {
// Show popover when running the "Share Portal" command, but prevent sharing unless user is authenticated.
assert(!pack.portalStatusBarIndicator.isPopoverVisible())
assert(!await pack.sharePortal())
- await pack1.portalStatusBarIndicator.initialOpenPromise
+ await pack.portalStatusBarIndicator.initialOpenPromise
assert(pack.portalStatusBarIndicator.isPopoverVisible())
// Show popover when running the "Join Portal" command, but prevent sharing unless user is authenticated.