Skip to content

Commit 952cc33

Browse files
committed
chore: demo
1 parent adff148 commit 952cc33

File tree

11 files changed

+4607
-431
lines changed

11 files changed

+4607
-431
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,6 @@ packages/*.metadata.json
5353
packages/angular
5454
packages/typings
5555

56-
/blueprint.md
56+
/blueprint.md
57+
58+
demo/platforms
Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,11 @@
1-
<<<<<<< HEAD
2-
// Add your native dependencies here:
3-
4-
// Uncomment to add recyclerview-v7 dependency
5-
//dependencies {
6-
// compile 'com.android.support:recyclerview-v7:+'
7-
//}
81

92
android {
103
defaultConfig {
4+
minSdkVersion 17
115
generatedDensities = []
126
applicationId = "org.nativescript.bluetoothdemo"
137
}
148
aaptOptions {
159
additionalParameters "--no-version-vectors"
1610
}
17-
}
18-
=======
19-
android {
20-
defaultConfig {
21-
minSdkVersion 17
22-
generatedDensities = []
23-
}
24-
aaptOptions {
25-
additionalParameters "--no-version-vectors"
26-
}
2711
}
28-
>>>>>>> c604db08cd8769f11fdb1180cf509fd0bb877e13

demo/app/App_Resources/Android/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
android:name="com.tns.NativeScriptActivity"
2626
android:label="@string/title_activity_kimera"
2727
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|locale|uiMode"
28-
android:theme="@style/LaunchScreenTheme">
28+
android:theme="@style/LaunchScreenTheme" android:exported="true">
2929

3030
<meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />
3131

@@ -34,6 +34,6 @@
3434
<category android:name="android.intent.category.LAUNCHER" />
3535
</intent-filter>
3636
</activity>
37-
<activity android:name="com.tns.ErrorReportActivity"/>
37+
<activity android:name="com.tns.ErrorReportActivity" android:exported="false"/>
3838
</application>
3939
</manifest>

demo/app/app.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
2-
import * as app from '@nativescript/core/application';
3-
import { BleTraceCategory } from '@nativescript-community/ble/bluetooth.common';
4-
import { Trace } from '@nativescript/core';
1+
import { BleTraceCategory } from '@nativescript-community/ble';
2+
import { Application, Trace } from '@nativescript/core';
53
Trace.addCategories(BleTraceCategory);
64
Trace.enable();
7-
app.run({ moduleName: 'app-root' });
5+
Application.run({ moduleName: 'app-root' });

demo/app/main-view-model.ts

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { ObservableArray } from '@nativescript/core/data/observable-array';
44
import { Prop } from './utils/obs-prop';
55
import { Bluetooth, Peripheral, getBluetoothInstance } from '@nativescript-community/ble';
66
import { Frame } from '@nativescript/core/ui/frame';
7+
import { check, request } from '@nativescript-community/perms';
8+
import { Application } from '@nativescript/core';
79

810
export class DemoAppModel extends Observable {
911
@Prop() public isLoading = false;
@@ -37,7 +39,7 @@ export class DemoAppModel extends Observable {
3739

3840
public doIsBluetoothEnabled() {
3941
console.log('doIsBluetoothEnabled tap');
40-
this._bluetooth.isBluetoothEnabled().then(enabled => {
42+
this._bluetooth.isBluetoothEnabled().then((enabled) => {
4143
if (enabled === false) {
4244
dialogs.alert('Bluetooth is DISABLED.');
4345
} else {
@@ -47,7 +49,7 @@ export class DemoAppModel extends Observable {
4749
}
4850

4951
public doEnableBluetooth() {
50-
this._bluetooth.enable().then(enabled => {
52+
this._bluetooth.enable().then((enabled) => {
5153
setTimeout(() => {
5254
dialogs.alert({
5355
title: 'Did the user allow enabling Bluetooth by our app?',
@@ -91,11 +93,11 @@ export class DemoAppModel extends Observable {
9193

9294
// this one 'manually' checks for permissions
9395
public doScanForHeartrateMontitor() {
94-
this._bluetooth.hasLocationPermission().then(granted => {
96+
this._bluetooth.hasLocationPermission().then((granted) => {
9597
if (!granted) {
9698
this._bluetooth.requestLocationPermission().then(
9799
// doing it like this for demo / testing purposes.. better usage is demonstrated in 'doStartScanning' below
98-
granted2 => {
100+
(granted2) => {
99101
dialogs.alert({
100102
title: 'Granted?',
101103
message: granted2 ? 'Yep - now invoke that button again' : 'Nope',
@@ -121,11 +123,11 @@ export class DemoAppModel extends Observable {
121123
skipPermissionCheck: true // we can skip permissions as we use filters: https://developer.android.com/guide/topics/connectivity/bluetooth-le
122124
})
123125
.then(
124-
p => {
126+
(p) => {
125127
this.isLoading = false;
126128
console.log('p', p);
127129
},
128-
err => {
130+
(err) => {
129131
this.isLoading = false;
130132
dialogs.alert({
131133
title: 'Whoops!',
@@ -140,11 +142,11 @@ export class DemoAppModel extends Observable {
140142

141143
// this one 'manually' checks for permissions
142144
public doScanForBeacon() {
143-
this._bluetooth.hasLocationPermission().then(granted => {
145+
this._bluetooth.hasLocationPermission().then((granted) => {
144146
if (!granted) {
145147
this._bluetooth.requestLocationPermission().then(
146148
// doing it like this for demo / testing purposes.. better usage is demonstrated in 'doStartScanning' below
147-
granted2 => {
149+
(granted2) => {
148150
dialogs.alert({
149151
title: 'Granted?',
150152
message: granted2 ? 'Yep - now invoke that button again' : 'Nope',
@@ -170,11 +172,11 @@ export class DemoAppModel extends Observable {
170172
skipPermissionCheck: true // we can skip permissions as we use filters: https://developer.android.com/guide/topics/connectivity/bluetooth-le
171173
})
172174
.then(
173-
p => {
175+
(p) => {
174176
this.isLoading = false;
175177
console.log('p', p);
176178
},
177-
err => {
179+
(err) => {
178180
this.isLoading = false;
179181
dialogs.alert({
180182
title: 'Whoops!',
@@ -187,37 +189,52 @@ export class DemoAppModel extends Observable {
187189
});
188190
}
189191

192+
190193
// this one uses automatic permission handling
191-
public doStartScanning() {
192-
this.isLoading = true;
193-
// reset the array
194-
this.peripherals.length = 0;
195-
this._bluetooth
196-
.startScanning({
194+
public async doStartScanning() {
195+
try {
196+
// this._bluetooth.hasLocationPermission().then((granted) => {
197+
// if (!granted) {
198+
const r = await request({ bluetoothConnect: {}, bluetoothScan: {} });
199+
// this._bluetooth.requestLocationPermission().then(
200+
// // doing it like this for demo / testing purposes.. better usage is demonstrated in 'doStartScanning' below
201+
// (granted2) => {
202+
// dialogs.alert({
203+
// title: 'Granted?',
204+
// message: granted2 ? 'Yep - now invoke that button again' : 'Nope',
205+
// okButtonText: 'OK!'
206+
// });
207+
// }
208+
// );
209+
// } else {
210+
this.isLoading = true;
211+
// reset the array
212+
this.peripherals.length = 0;
213+
await this._bluetooth.startScanning({
197214
seconds: 50, // passing in seconds makes the plugin stop scanning after <seconds> seconds
198-
// onDiscovered: peripheral => {
199-
// console.log("peripheral discovered. Not adding it here because we're using a listener.");
200-
// // this.peripherals.push(peripheral);
201-
// },
202-
skipPermissionCheck: false // we can't skip permissions and we need enabled location as we dont use filters: https://developer.android.com/guide/topics/connectivity/bluetooth-le
203-
})
204-
.then(() => (this.isLoading = false))
205-
.catch(err => {
206-
this.isLoading = false;
207-
dialogs.alert({
208-
title: 'Whoops!',
209-
message: err ? err : 'Unknown error',
210-
okButtonText: 'OK, got it'
211-
});
215+
onDiscovered: peripheral => {
216+
console.log("peripheral discovered. Not adding it here because we're using a listener.");
217+
},
218+
});
219+
// }
220+
// });
221+
} catch (error) {
222+
dialogs.alert({
223+
title: 'Whoops!',
224+
message: error ? error : 'Unknown error',
225+
okButtonText: 'OK, got it'
212226
});
227+
} finally {
228+
this.isLoading = false;
229+
}
213230
}
214231

215232
public doStopScanning() {
216233
this._bluetooth.stopScanning().then(
217234
() => {
218235
this.isLoading = false;
219236
},
220-
err => {
237+
(err) => {
221238
dialogs.alert({
222239
title: 'Whoops!',
223240
message: err,

demo/package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"dependencies": {
3-
"@nativescript-community/ble": "file:../plugin",
4-
"@nativescript/core": "7.2.1"
3+
"@nativescript-community/ble": "*",
4+
"@nativescript/core": "8.5.7"
55
},
66
"devDependencies": {
7-
"@nativescript/ios": "7.2.0",
8-
"@nativescript/types": "7.2.0",
9-
"@nativescript/webpack": "4.1.0",
10-
"typescript": "4.1.3"
7+
"@nativescript/android": "8.5.0",
8+
"@nativescript/ios": "8.5.2",
9+
"@nativescript/types": "8.5.0",
10+
"@nativescript/webpack": "5.0.16",
11+
"typescript": "5.2.0-dev.20230717"
1112
},
12-
"main": "app.js"
13+
"main": "app/app"
1314
}

demo/tsconfig.json

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,22 @@
11
{
22
"compilerOptions": {
3-
"target": "es2017",
3+
"target": "es2020",
44
"module": "esnext",
55
"declaration": false,
66
"noImplicitAny": false,
77
"removeComments": false,
8-
"watch": false,
98
"noLib": false,
109
"noEmitHelpers": true,
1110
"preserveConstEnums": true,
1211
"emitDecoratorMetadata": true,
13-
"suppressImplicitAnyIndexErrors": true,
14-
"noImplicitUseStrict": true,
1512
"experimentalDecorators": true,
16-
"lib": [
17-
"es6",
18-
"dom",
19-
"es2015.iterable",
20-
"es2017"
21-
],
13+
"lib": ["es6", "dom", "es2015.iterable", "es2020"],
2214
"baseUrl": ".",
2315
"paths": {
24-
"~/*": [
25-
"app/*"
26-
],
27-
"*": [
28-
"./node_modules/tns-core-modules/*",
29-
"./node_modules/*"
30-
]
16+
"~/*": ["app/*"],
3117
},
3218
"moduleResolution": "node"
3319
},
34-
"include": [
35-
"app/**/*",
36-
"references.d.ts"
37-
],
38-
"exclude": [
39-
"node_modules",
40-
"platforms"
41-
]
42-
}
20+
"include": ["app/**/*", "references.d.ts"],
21+
"exclude": ["node_modules", "platforms"]
22+
}

0 commit comments

Comments
 (0)