@@ -36,31 +36,36 @@ class DevGlobeTracker : Disposable {
3636 }
3737
3838 fun start (apiKey : String ) {
39- started.set( true )
39+ if ( ! started.compareAndSet( false , true )) return
4040 currentApiKey = apiKey
4141 val settings = DevGlobeSettings .getInstance()
4242
43- ensureCore()
44- coreClient?.sendInit(apiKey, settings.state.shareRepo, settings.state.anonymousMode, settings.state.statusMessage)
45- coreClient?.sendResume()
46-
47- registerDocumentListener()
43+ ApplicationManager .getApplication().executeOnPooledThread {
44+ ensureCore()
45+ coreClient?.sendInit(apiKey, settings.state.shareRepo, settings.state.anonymousMode, settings.state.statusMessage)
46+ coreClient?.sendResume()
47+ ApplicationManager .getApplication().invokeLater { registerDocumentListener() }
48+ }
4849 }
4950
51+ @Synchronized
5052 fun pause () {
53+ started.set(false )
5154 coreClient?.sendPause()
5255 state = state.copy(tracking = false )
5356 pushState()
5457 }
5558
59+ @Synchronized
5660 fun stop () {
5761 started.set(false )
58- pause()
62+ coreClient?.sendPause()
63+ state = state.copy(tracking = false , connected = false )
5964 currentApiKey = null
60- state = state.copy(connected = false )
6165 pushState()
6266 }
6367
68+ @Synchronized
6469 fun reset () {
6570 started.set(false )
6671 coreClient?.sendShutdown()
@@ -71,6 +76,7 @@ class DevGlobeTracker : Disposable {
7176 pushState()
7277 }
7378
79+ @Synchronized
7480 fun restoreConnected (apiKey : String ) {
7581 currentApiKey = apiKey
7682 val settings = DevGlobeSettings .getInstance()
@@ -84,16 +90,20 @@ class DevGlobeTracker : Disposable {
8490 pushState()
8591 }
8692
93+ @Synchronized
8794 fun setStatusMessage (message : String ) {
8895 state = state.copy(statusMessage = message)
8996 pushState()
9097 }
9198
9299 fun sendSetStatus (message : String ) {
93- ensureCore()
94- coreClient?.sendSetStatus(message)
100+ ApplicationManager .getApplication().executeOnPooledThread {
101+ ensureCore()
102+ coreClient?.sendSetStatus(message)
103+ }
95104 }
96105
106+ @Synchronized
97107 fun updatePreference (key : String , value : Boolean ) {
98108 state = when (key) {
99109 " shareRepo" -> state.copy(shareRepo = value)
@@ -108,6 +118,7 @@ class DevGlobeTracker : Disposable {
108118 }
109119 }
110120
121+ @Synchronized
111122 private fun ensureCore () {
112123 if (coreClient != null ) return
113124
@@ -125,7 +136,7 @@ class DevGlobeTracker : Disposable {
125136
126137 val client = CoreClient (CoreDownloader .getBinaryPath())
127138 client.onState = { newState ->
128- state = newState
139+ synchronized( this ) { state = newState }
129140 pushState()
130141 }
131142 client.onOffline = { msg ->
0 commit comments