Skip to content

Commit

Permalink
Merge pull request #1913 from ubports/fix-windows-macos
Browse files Browse the repository at this point in the history
Fix "Internet connection lost" errors
  • Loading branch information
mariogrip authored Apr 21, 2021
2 parents 31f330b + 63dab24 commit 5d31f45
Show file tree
Hide file tree
Showing 15 changed files with 406 additions and 179 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ jobs:
${{ runner.os }}-build-
${{ runner.os }}-
- name: npm install
run: npm install
- name: npm ci
run: npm ci
- name: npm audit
run: npm audit --production
- name: npm run lint
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
- name: test
run: |
npm install
npm ci
npm run test
- name: codecov.io
Expand Down Expand Up @@ -112,7 +112,7 @@ jobs:
- name: prepare build
run: |
npm install
npm ci
npm run prerender
- name: build linux
Expand Down
63 changes: 20 additions & 43 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"open-cuts-reporter": "^1.0.1",
"popper.js": "^1.16.0",
"progressive-downloader": "^1.0.6",
"promise-android-tools": "^4.0.5",
"promise-android-tools": "^4.0.6",
"ps-tree": "^1.2.0",
"sudo-prompt": "^9.2.1",
"systeminformation": "^5.5.0",
Expand Down
68 changes: 35 additions & 33 deletions src/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,40 +66,42 @@ class Core {
* @returns {Promise}
*/
prepare(file) {
return Promise.all([this.readConfigFile(file), this.plugins.init()]).then(
() => {
if (this.props.config) {
this.selectOs();
} else {
const wait = this.plugins
.wait()
.then(device => api.resolveAlias(device))
.catch(
e =>
new Promise(() => {
log.debug(`failed to resolve device name: ${e}`);
mainEvent.emit("user:no-network");
})
)
.then(device => {
if (device) {
log.info(`device detected: ${device}`);
this.setDevice(device);
}
});
ipcMain.once("device:selected", () => (wait ? wait.cancel() : null));
api
.getDeviceSelects()
.then(out => {
window.send("device:wait:device-selects-ready", out);
})
.catch(e => {
log.error("getDeviceSelects error: " + e);
window.send("user:no-network");
});
}
return Promise.all([
this.readConfigFile(file),
this.plugins.init().catch(e => errors.toUser(e, "initializing plugins"))
]).then(() => {
if (this.props.config) {
this.selectOs();
} else {
const wait = this.plugins
.wait()
.catch(e => errors.toUser(e, "plugin wait()"))
.then(device => api.resolveAlias(device))
.catch(
e =>
new Promise(() => {
log.debug(`failed to resolve device name: ${e}`);
mainEvent.emit("user:no-network");
})
)
.then(device => {
if (device) {
log.info(`device detected: ${device}`);
this.setDevice(device);
}
});
ipcMain.once("device:selected", () => (wait ? wait.cancel() : null));
api
.getDeviceSelects()
.then(out => {
window.send("device:wait:device-selects-ready", out);
})
.catch(e => {
log.error("getDeviceSelects error: " + e);
window.send("user:no-network");
});
}
);
});
}

/**
Expand Down
40 changes: 22 additions & 18 deletions src/core/core.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,23 @@ describe("Core module", () => {
jest.spyOn(core, "readConfigFile").mockResolvedValueOnce();
jest.spyOn(core.plugins, "init").mockResolvedValueOnce();
jest.spyOn(core.plugins, "wait").mockReturnValueOnce({
then: () => ({
catch: () => ({
then: () => ({
cancel: () => {
expect(core.readConfigFile).toHaveBeenCalledWith("a");
expect(core.readConfigFile).toHaveBeenCalledTimes(1);
core.readConfigFile.mockRestore();
expect(core.plugins.init).toHaveBeenCalledTimes(1);
core.plugins.init.mockRestore();
expect(core.plugins.wait).toHaveBeenCalledTimes(1);
core.plugins.wait.mockRestore();
core.setDevice.mockRestore();
core.props.config = { user_actions, handlers };
done();
}
catch: () => ({
then: () => ({
catch: () => ({
then: () => ({
cancel: () => {
expect(core.readConfigFile).toHaveBeenCalledWith("a");
expect(core.readConfigFile).toHaveBeenCalledTimes(1);
core.readConfigFile.mockRestore();
expect(core.plugins.init).toHaveBeenCalledTimes(1);
core.plugins.init.mockRestore();
expect(core.plugins.wait).toHaveBeenCalledTimes(1);
core.plugins.wait.mockRestore();
core.setDevice.mockRestore();
core.props.config = { user_actions, handlers };
done();
}
})
})
})
})
Expand All @@ -157,9 +159,11 @@ describe("Core module", () => {
jest.spyOn(core, "readConfigFile").mockResolvedValueOnce();
jest.spyOn(core.plugins, "init").mockResolvedValueOnce();
jest.spyOn(core.plugins, "wait").mockReturnValueOnce({
then: () => ({
catch: () => ({
then: () => null
catch: () => ({
then: () => ({
catch: () => ({
then: () => null
})
})
})
});
Expand Down
4 changes: 2 additions & 2 deletions src/core/plugins/adb/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class AdbPlugin extends Plugin {

/**
* initialize adb server
* @returns {Promise}
* @returns {Promise<Boolean>}
*/
init() {
return this.adb.startServer();
return this.adb.startServer().then(() => true);
}

/**
Expand Down
Loading

0 comments on commit 5d31f45

Please sign in to comment.