Skip to content

Commit 42c1add

Browse files
authored
Merge pull request #2974 from ethereum/remixddeactivate
fix deactivating plugins
2 parents b679f7f + 2917589 commit 42c1add

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed

apps/remix-ide/src/app/plugins/remixd-handle.tsx

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,18 @@ export class RemixdHandle extends WebsocketPlugin {
3535
localhostProvider: any
3636
appManager: PluginManager
3737
dependentPlugins: Array<string>
38-
constructor (localhostProvider, appManager) {
38+
constructor(localhostProvider, appManager) {
3939
super(profile)
4040
this.localhostProvider = localhostProvider
4141
this.appManager = appManager
4242
this.dependentPlugins = ['hardhat', 'truffle', 'slither', 'foundry']
4343
}
4444

45-
async deactivate () {
45+
async deactivate() {
4646
for (const plugin of this.dependentPlugins) {
47-
await this.appManager.deactivatePlugin(plugin)
47+
if (await this.appManager.isActive(plugin)) {
48+
await this.appManager.deactivatePlugin(plugin)
49+
}
4850
}
4951
if (super.socket) super.deactivate()
5052
// this.appManager.deactivatePlugin('git') // plugin call doesn't work.. see issue https://github.com/ethereum/remix-plugin/issues/342
@@ -53,16 +55,20 @@ export class RemixdHandle extends WebsocketPlugin {
5355
})
5456
}
5557

56-
async activate () {
58+
async activate() {
5759
this.connectToLocalhost()
5860
return true
5961
}
6062

61-
async canceled () {
63+
async canceled() {
6264
for (const plugin of this.dependentPlugins) {
63-
await this.appManager.deactivatePlugin(plugin)
65+
if (await this.appManager.isActive(plugin)) {
66+
await this.appManager.deactivatePlugin(plugin)
67+
}
6468
}
69+
6570
await this.appManager.deactivatePlugin('remixd')
71+
6672
}
6773

6874
/**
@@ -71,11 +77,11 @@ export class RemixdHandle extends WebsocketPlugin {
7177
*
7278
* @param {String} txHash - hash of the transaction
7379
*/
74-
async connectToLocalhost () {
75-
const connection = async (error?:any) => {
80+
async connectToLocalhost() {
81+
const connection = async (error?: any) => {
7682
if (error) {
7783
console.log(error)
78-
const alert:AlertModal = {
84+
const alert: AlertModal = {
7985
id: 'connectionAlert',
8086
message: 'Cannot connect to the remixd daemon. Please make sure you have the remixd running in the background.'
8187
}
@@ -85,7 +91,7 @@ export class RemixdHandle extends WebsocketPlugin {
8591
const intervalId = setInterval(() => {
8692
if (!this.socket || (this.socket && this.socket.readyState === 3)) { // 3 means connection closed
8793
clearInterval(intervalId)
88-
const alert:AlertModal = {
94+
const alert: AlertModal = {
8995
id: 'connectionAlert',
9096
message: 'Connection to remixd terminated. Please make sure remixd is still running in the background.'
9197
}
@@ -105,28 +111,28 @@ export class RemixdHandle extends WebsocketPlugin {
105111
this.deactivate()
106112
} else if (!isElectron()) {
107113
// warn the user only if he/she is in the browser context
108-
const mod:AppModal = {
114+
const mod: AppModal = {
109115
id: 'remixdConnect',
110116
title: 'Connect to localhost',
111117
message: remixdDialog(),
112118
okLabel: 'Connect',
113119
cancelLabel: 'Cancel',
114120
}
115-
const result = await this.call('notification', 'modal', mod)
116-
if(result) {
117-
try {
118-
this.localhostProvider.preInit()
119-
super.activate()
120-
setTimeout(() => {
121-
if (!this.socket || (this.socket && this.socket.readyState === 3)) { // 3 means connection closed
122-
connection(new Error('Connection with daemon failed.'))
123-
} else {
124-
connection()
125-
}
126-
}, 3000)
127-
} catch (error) {
128-
connection(error)
129-
}
121+
const result = await this.call('notification', 'modal', mod)
122+
if (result) {
123+
try {
124+
this.localhostProvider.preInit()
125+
super.activate()
126+
setTimeout(() => {
127+
if (!this.socket || (this.socket && this.socket.readyState === 3)) { // 3 means connection closed
128+
connection(new Error('Connection with daemon failed.'))
129+
} else {
130+
connection()
131+
}
132+
}, 3000)
133+
} catch (error) {
134+
connection(error)
135+
}
130136
}
131137
else {
132138
await this.canceled()
@@ -142,7 +148,7 @@ export class RemixdHandle extends WebsocketPlugin {
142148
}
143149
}
144150

145-
function remixdDialog () {
151+
function remixdDialog() {
146152
const commandText = 'remixd'
147153
const fullCommandText = 'remixd -s <path-to-the-shared-folder> -u <remix-ide-instance-URL>'
148154
return (<>
@@ -155,13 +161,13 @@ function remixdDialog () {
155161
</div>
156162
<div className='mb-2 text-break'>
157163
The remixd command is:
158-
<br/><b>{commandText}</b>
164+
<br /><b>{commandText}</b>
159165
</div>
160166
<div className='mb-2 text-break'>
161167
The remixd command without options uses the terminal's current directory as the shared directory and the shared Remix domain can only be https://remix.ethereum.org, https://remix-alpha.ethereum.org, or https://remix-beta.ethereum.org
162168
</div>
163169
<div className='mb-2 text-break'>
164-
Example command with flags: <br/>
170+
Example command with flags: <br />
165171
<b>{fullCommandText}</b>
166172
</div>
167173
<div className='mb-2 text-break'>

0 commit comments

Comments
 (0)