Skip to content

Commit

Permalink
Merge pull request #2 from emanuel-braz/develop
Browse files Browse the repository at this point in the history
fix: deep linking only gets first query parameter
  • Loading branch information
emanuel-braz committed Oct 20, 2021
2 parents 36d93a4 + d91b825 commit 86a156d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 36 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
## [0.0.5] 2021-10-20
#### Fixed
- deep linking only gets first query parameter

## [0.0.4]
#### Added
- increase list length to 30 items
- QuickPick stay open even when loosing UI focus
#### Fixed
- android deeplink fails

## [0.0.1]
- Initial release
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "deeplink",
"displayName": "Deep link (Android / iOS)",
"description": "Open deeplink in mobile emulators",
"version": "0.0.4",
"version": "0.0.5",
"publisher": "emanuel-braz",
"repository": {
"type": "git",
Expand Down
40 changes: 23 additions & 17 deletions src/core/runners/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,31 @@ const { exec } = require("child_process");

export class Runner {

static runAndroid(route: string = "") {
return run(`adb shell am start -W -a android.intent.action.VIEW -d ${route}`);
runAndroid(route: string = "") {
return this.run(`adb shell am start -W -a android.intent.action.VIEW -d ${route}`);
}

static runIos(route: string) {
return run(`xcrun simctl openurl booted ${route}`);
runIos(route: string) {
return this.run(`xcrun simctl openurl booted ${route}`);
}
}

function run(command: string) {
return exec(command, (error: any, stdout: any, stderr: any) => {
if (stderr) {
Dialogs.snackbar.error(stderr);
} else if (error) {
Dialogs.snackbar.error(error);
}

if (stdout) {
console.log(`${stdout}`);
}
});
run(command: string) {
command = this.encodeAmpersandChars(command);
return exec(command, (error: any, stdout: any, stderr: any) => {
if (stderr) {
Dialogs.snackbar.error(stderr);
} else if (error) {
Dialogs.snackbar.error(error);
}

if (stdout) {
console.log(`${stdout}`);
}
});
}

encodeAmpersandChars(command: string): string {
let ampersand = /&/gi;
return command.replace(ampersand, "\\" + "&");
}
}
5 changes: 3 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ async function runPlatformCommand(context: ExtensionContext, isAndroid: Boolean,
}

function runCommand(route: string, isAndroid: Boolean) {
const runner = new Runner();
if (route.length > 0){
if (isAndroid) {
console.log(`${APP_DEEPLINK_ANDROID} ${route}`);
Runner.runAndroid(route);
runner.runAndroid(route);
} else {
console.log(`${APP_DEEPLINK_IOS} ${route}`);
Runner.runIos(route);
runner.runIos(route);
}
}
}
23 changes: 7 additions & 16 deletions src/test/extension.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
//
// Note: This example test is leveraging the Mocha test framework.
// Please refer to their documentation on https://mochajs.org/ for help.
//

// The module 'assert' provides assertion methods from node
import * as assert from 'assert';
import * as myExtension from '../core/runners/runner';

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
// import * as vscode from 'vscode';
// import * as myExtension from '../extension';

// Defines a Mocha test suite to group tests of similar kind together
suite("Extension Tests", function () {

// Defines a Mocha unit test
test("Something 1", function() {
assert.equal(-1, [1, 2, 3].indexOf(5));
assert.equal(-1, [1, 2, 3].indexOf(0));
test("Should encode command with & character correctly", function() {
const command = "myScheme://domain?paramA=1&paramB=2&paramC=3";
const resultExpected = "myScheme://domain?paramA=1\\&paramB=2\\&paramC=3";
const runner = new myExtension.Runner();
const commandEncoded = runner.encodeAmpersandChars(command);
assert.strictEqual(commandEncoded, resultExpected);
});
});

0 comments on commit 86a156d

Please sign in to comment.