Skip to content

Commit b1a283c

Browse files
authored
Merge pull request #22 from cdifino/nbansal/connectedMode3
indentation changes for build
2 parents 41aa535 + 3e97aac commit b1a283c

File tree

2 files changed

+93
-118
lines changed

2 files changed

+93
-118
lines changed

packages/selenium-ide/src/api/v1/index.js

Lines changed: 89 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -33,38 +33,37 @@ const router = new Router()
3333
const errors = {
3434
cannotAccessInControlMode: {
3535
errorCode: 'CannotAccessInControlMode',
36-
error: 'Selenium IDE is controlled by a different extension.'
36+
error: 'Selenium IDE is controlled by a different extension.',
3737
},
3838
missingPlugin: {
3939
errorCode: 'MissingPlugin',
40-
error: 'Plugin is not registered'
40+
error: 'Plugin is not registered',
4141
},
4242
missingConnectionId: {
4343
errorCode: 'MissingConnectionId',
44-
error: 'No connection Id specified'
44+
error: 'No connection Id specified',
4545
},
4646
missingProject: {
4747
errorCode: 'MissingProject',
48-
error: 'Plugin is not registered'
49-
}
48+
error: 'Plugin is not registered',
49+
},
5050
}
5151

5252
function checkControl(req) {
53-
return Manager.controller && Manager.controller.connectionId != req.connectionId
53+
return Manager.controller &&
54+
Manager.controller.connectionId != req.connectionId
5455
? Promise.reject()
5556
: Promise.resolve()
5657
}
5758

5859
function controlledOnly(req, res) {
59-
return checkControl(req)
60-
.catch(() => {
61-
res(errors.cannotAccessInControlMode)
62-
return errors.cannotAccessInControlMode
63-
})
60+
return checkControl(req).catch(() => {
61+
res(errors.cannotAccessInControlMode)
62+
return errors.cannotAccessInControlMode
63+
})
6464
}
6565

66-
function tryOverrideControl(req)
67-
{
66+
function tryOverrideControl(req) {
6867
if (!req.connectionId) return
6968
if (!ModalState.welcomeState.completed) {
7069
ModalState.hideWelcome()
@@ -75,8 +74,7 @@ function tryOverrideControl(req)
7574
description: `${req.name} is trying to control Selenium IDE`,
7675
confirmLabel: 'Restart and Allow access',
7776
cancelLabel: 'Deny access',
78-
})
79-
.then(r => {
77+
}).then(r => {
8078
if (r) {
8179
const plugin = {
8280
id: req.sender,
@@ -97,87 +95,74 @@ router.get('/health', (req, res) => {
9795
res(Manager.hasPlugin(req.sender))
9896
})
9997

100-
router.post(
101-
'/register',
102-
(req, res) => {
103-
controlledOnly(req, res).then(() => {
104-
const plugin = {
105-
id: req.sender,
106-
name: req.name,
107-
version: req.version,
108-
commands: req.commands,
109-
dependencies: req.dependencies,
110-
jest: req.jest,
111-
exports: req.exports,
112-
}
113-
Manager.registerPlugin(plugin)
114-
res(true)
115-
});
116-
}
117-
)
98+
router.post('/register', (req, res) => {
99+
controlledOnly(req, res).then(() => {
100+
const plugin = {
101+
id: req.sender,
102+
name: req.name,
103+
version: req.version,
104+
commands: req.commands,
105+
dependencies: req.dependencies,
106+
jest: req.jest,
107+
exports: req.exports,
108+
}
109+
Manager.registerPlugin(plugin)
110+
res(true)
111+
})
112+
})
118113

119-
router.post(
120-
'/log',
121-
(req, res) => {
122-
controlledOnly(req, res).then(() => {
123-
if (req.type === LogTypes.Error) {
124-
logger.error(`${Manager.getPlugin(req.sender).name}: ${req.message}`)
125-
} else if (req.type === LogTypes.Warning) {
126-
logger.warn(`${Manager.getPlugin(req.sender).name}: ${req.message}`)
127-
} else {
128-
logger.log(`${Manager.getPlugin(req.sender).name}: ${req.message}`)
129-
}
130-
res(true)
131-
})
132-
}
133-
)
114+
router.post('/log', (req, res) => {
115+
controlledOnly(req, res).then(() => {
116+
if (req.type === LogTypes.Error) {
117+
logger.error(`${Manager.getPlugin(req.sender).name}: ${req.message}`)
118+
} else if (req.type === LogTypes.Warning) {
119+
logger.warn(`${Manager.getPlugin(req.sender).name}: ${req.message}`)
120+
} else {
121+
logger.log(`${Manager.getPlugin(req.sender).name}: ${req.message}`)
122+
}
123+
res(true)
124+
})
125+
})
134126

135-
router.get(
136-
'/project',
137-
(_req, res) => {
138-
controlledOnly(_req, res).then(() => {
139-
res({ id: UiState.project.id, name: UiState.project.name })
140-
})
141-
}
142-
)
127+
router.get('/project', (_req, res) => {
128+
controlledOnly(_req, res).then(() => {
129+
res({ id: UiState.project.id, name: UiState.project.name })
130+
})
131+
})
143132

144133
router.post('/control', (req, res) => {
145-
checkControl(req).then(() =>{
146-
if(UiState.isControlled)
147-
{
148-
// Already in control mode with the same connection id.
149-
res(true)
150-
}
151-
else
152-
{
153-
// Already in non-control mode.
134+
checkControl(req)
135+
.then(() => {
136+
if (UiState.isControlled) {
137+
// Already in control mode with the same connection id.
138+
res(true)
139+
} else {
140+
// Already in non-control mode.
141+
tryOverrideControl(req)
142+
.then(() => res(true))
143+
.catch(() => res(false))
144+
}
145+
})
146+
.catch(() => {
147+
// Already in control mode but another connection come.
154148
tryOverrideControl(req)
155149
.then(() => res(true))
156150
.catch(() => res(false))
157-
}
158-
})
159-
.catch(() => {
160-
// Already in control mode but another connection come.
161-
tryOverrideControl(req)
162-
.then(() => res(true))
163-
.catch(() => res(false))
164-
})
151+
})
165152
})
166153

167154
router.post('/close', (req, res) => {
168-
controlledOnly(req, res).then(() =>{
155+
controlledOnly(req, res).then(() => {
169156
// Not allow close if is not control mode.
170-
if(!UiState.isControlled) {
157+
if (!UiState.isControlled) {
171158
return res(false)
172159
}
173160
const plugin = Manager.getPlugin(req.sender)
174161
if (!plugin) return res(errors.missingPlugin)
175162
if (!UiState.isSaved()) {
176163
ModalState.showAlert({
177164
title: 'Close project without saving',
178-
description: `${
179-
plugin.name
180-
} is trying to close a project, are you sure you want to load this project and lose all unsaved changes?`,
165+
description: `${plugin.name} is trying to close a project, are you sure you want to load this project and lose all unsaved changes?`,
181166
confirmLabel: 'proceed',
182167
cancelLabel: 'cancel',
183168
}).then(result => {
@@ -188,9 +173,7 @@ router.post('/close', (req, res) => {
188173
})
189174

190175
res(false)
191-
}
192-
else
193-
{
176+
} else {
194177
window.close()
195178
res(true)
196179
}
@@ -213,42 +196,35 @@ router.post('/_connect', (req, res) => {
213196
}
214197
})
215198

216-
router.post(
217-
'/project',
218-
(req, res) => {
219-
controlledOnly(req, res).then(() => {
220-
const plugin = Manager.getPlugin(req.sender)
221-
if (!plugin) return res(errors.missingPlugin)
222-
if (!req.project) return res(errors.missingProject)
223-
if (req.project) {
224-
if (!UiState.isSaved()) {
225-
WindowSession.focusIDEWindow()
226-
ModalState.showAlert({
227-
title: 'Open project without saving',
228-
description: `${
229-
plugin.name
230-
} is trying to load a project, are you sure you want to load this project and lose all unsaved changes?`,
231-
confirmLabel: 'proceed',
232-
cancelLabel: 'cancel',
233-
})
234-
.then(result => {
235-
if (result) {
236-
loadJSProject(UiState.project, req.project)
237-
ModalState.completeWelcome()
238-
res(true)
239-
}
240-
})
241-
} else {
242-
WindowSession.focusIDEWindow()
199+
router.post('/project', (req, res) => {
200+
controlledOnly(req, res).then(() => {
201+
const plugin = Manager.getPlugin(req.sender)
202+
if (!plugin) return res(errors.missingPlugin)
203+
if (!req.project) return res(errors.missingProject)
204+
205+
if (!UiState.isSaved()) {
206+
WindowSession.focusIDEWindow()
207+
ModalState.showAlert({
208+
title: 'Open project without saving',
209+
description: `${plugin.name} is trying to load a project, are you sure you want to load this project and lose all unsaved changes?`,
210+
confirmLabel: 'proceed',
211+
cancelLabel: 'cancel',
212+
}).then(result => {
213+
if (result) {
243214
loadJSProject(UiState.project, req.project)
244215
ModalState.completeWelcome()
245216
res(true)
246217
}
247-
}
248-
res(false)
249-
})
250-
}
251-
)
218+
})
219+
} else {
220+
WindowSession.focusIDEWindow()
221+
loadJSProject(UiState.project, req.project)
222+
ModalState.completeWelcome()
223+
res(true)
224+
}
225+
res(false)
226+
})
227+
})
252228

253229
router.use('/playback', playbackRouter)
254230
router.use('/record', recordRouter)

packages/selenium-ide/src/background/background.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ function handleInternalMessage(message) {
199199
})
200200
.then(() => {
201201
openPanel({ windowId: 0 }).then(() => {
202-
var payload = { ...message };
203-
delete payload.restart;
202+
var payload = { ...message }
203+
delete payload.restart
204204

205205
const newMessage = {
206206
uri: '/_connect',
@@ -234,9 +234,8 @@ browser.runtime.onMessageExternal.addListener(
234234
let payload = message.payload
235235

236236
payload.sender = sender.id
237-
if (message.uri === '/_connect' || message.uri === '/_close')
238-
{
239-
return sendResponse(false);
237+
if (message.uri === '/_connect' || message.uri === '/_close') {
238+
return sendResponse(false)
240239
}
241240
browser.runtime
242241
.sendMessage(message)

0 commit comments

Comments
 (0)