Skip to content

Commit 6060ff9

Browse files
committed
chore: link&prettier
1 parent 75e2f01 commit 6060ff9

File tree

10 files changed

+446
-73
lines changed

10 files changed

+446
-73
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Outline React Native Android & iOS Client
77
```sh
88
npm install react-native-outline-vpn
99
```
10+
1011
or
12+
1113
```sh
1214
yarn add react-native-outline-vpn
1315
```

example/src/App.tsx

Lines changed: 0 additions & 31 deletions
This file was deleted.

lefthook.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ pre-commit:
33
commands:
44
lint:
55
files: git diff --name-only @{push}
6-
glob: "*.{js,ts,jsx,tsx}"
6+
glob: '*.{js,ts,jsx,tsx}'
77
run: npx eslint {files}
88
types:
99
files: git diff --name-only @{push}
10-
glob: "*.{js,ts, jsx, tsx}"
10+
glob: '*.{js,ts, jsx, tsx}'
1111
run: npx tsc --noEmit
1212
commit-msg:
1313
parallel: true

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,8 @@
154154
}
155155
]
156156
]
157+
},
158+
"dependencies": {
159+
"metro-react-native-babel-preset": "^0.77.0"
157160
}
158161
}

src/__tests__/index.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
'use strict';
2+
it.todo('write a test');

src/index.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { NativeModules, Platform } from 'react-native';
2+
import {} from './types';
3+
const LINKING_ERROR =
4+
`The package 'react-native-outline-vpn' doesn't seem to be linked. Make sure: \n\n` +
5+
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
6+
'- You rebuilt the app after installing the package\n' +
7+
'- You are not using Expo Go\n';
8+
const OutlineVpn = NativeModules.OutlineVpn
9+
? NativeModules.OutlineVpn
10+
: new Proxy(
11+
{},
12+
{
13+
get() {
14+
throw new Error(LINKING_ERROR);
15+
},
16+
}
17+
);
18+
export const startOutlineVPN = function startOutlineVPN(
19+
host,
20+
port,
21+
password,
22+
method,
23+
providerBundleIdentifier,
24+
prefix,
25+
serverAddress,
26+
tunnelId,
27+
localizedDescription
28+
) {
29+
return new Promise((resolve, reject) => {
30+
if (Platform.OS === 'ios') {
31+
OutlineVpn.startVpn(
32+
host,
33+
port,
34+
password,
35+
method,
36+
prefix,
37+
providerBundleIdentifier,
38+
serverAddress,
39+
tunnelId,
40+
localizedDescription
41+
);
42+
} else {
43+
OutlineVpn.saveCredential(host, port, password, method, prefix).then(
44+
(credentialResult) => {
45+
if (credentialResult) {
46+
OutlineVpn.getCredential().then(() => {
47+
OutlineVpn.prepareLocalVPN().then(() => {
48+
OutlineVpn.connectLocalVPN()
49+
.then((vpnResult) => resolve(vpnResult))
50+
.catch((e) => reject(e));
51+
});
52+
});
53+
}
54+
}
55+
);
56+
}
57+
});
58+
};

src/index.tsx

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NativeModules, Platform } from 'react-native';
2-
import { type startVPN } from './types'
2+
import { type startVPN } from './types';
33

44
const LINKING_ERROR =
55
`The package 'react-native-outline-vpn' doesn't seem to be linked. Make sure: \n\n` +
@@ -18,7 +18,8 @@ const OutlineVpn = NativeModules.OutlineVpn
1818
}
1919
);
2020

21-
export const startOutlineVPN : startVPN = function startOutlineVPN ( host: string,
21+
export const startOutlineVPN: startVPN = function startOutlineVPN(
22+
host: string,
2223
port: number,
2324
password: string,
2425
method: string,
@@ -28,8 +29,8 @@ export const startOutlineVPN : startVPN = function startOutlineVPN ( host: stri
2829
tunnelId?: string,
2930
localizedDescription?: string
3031
) {
31-
return new Promise((resolve, reject) => {
32-
if (Platform.OS === "ios") {
32+
return new Promise((resolve, reject) => {
33+
if (Platform.OS === 'ios') {
3334
OutlineVpn.startVpn(
3435
host,
3536
port,
@@ -40,29 +41,21 @@ export const startOutlineVPN : startVPN = function startOutlineVPN ( host: stri
4041
serverAddress,
4142
tunnelId,
4243
localizedDescription
43-
)
44+
);
4445
} else {
45-
OutlineVpn.saveCredential(
46-
host,
47-
port,
48-
password,
49-
method,
50-
prefix,
51-
).then((credentialResult: any) => {
52-
if (credentialResult) {
53-
OutlineVpn.getCredential().then((cr: any) => {
54-
OutlineVpn.prepareLocalVPN().then((prepareRes: any) => {
55-
OutlineVpn.connectLocalVPN()
56-
.then((vpnResult: any) => {})
57-
.catch((e: any) => {});
46+
OutlineVpn.saveCredential(host, port, password, method, prefix).then(
47+
(credentialResult: any) => {
48+
if (credentialResult) {
49+
OutlineVpn.getCredential().then(() => {
50+
OutlineVpn.prepareLocalVPN().then(() => {
51+
OutlineVpn.connectLocalVPN()
52+
.then((vpnResult: string) => resolve(vpnResult))
53+
.catch((e: any) => reject(e));
54+
});
5855
});
59-
});
56+
}
6057
}
61-
});
58+
);
6259
}
63-
64-
65-
})
66-
67-
68-
}
60+
});
61+
};

src/types.d.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
2-
* Start Outline VPN
3-
* @param callback A callback function that will receive the result of the suppression.
4-
* - result: A number representing the result of the suppression.
5-
* 0: Not Supported
6-
* 1: Already suppressed
7-
* 2: Denied
8-
* 3: Cancelled
9-
* 4: Success
10-
*/
2+
* Start Outline VPN
3+
* @param callback A callback function that will receive the result of the suppression.
4+
* - result: A number representing the result of the suppression.
5+
* 0: Not Supported
6+
* 1: Already suppressed
7+
* 2: Denied
8+
* 3: Cancelled
9+
* 4: Success
10+
*/
1111
export type startVPN = (
1212
host: string,
1313
port: number,

tsconfig.build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
{
32
"extends": "./tsconfig",
43
"exclude": ["example"]

0 commit comments

Comments
 (0)