Skip to content

Commit fdefc2c

Browse files
committed
chore: demo update
1 parent 19ec12a commit fdefc2c

File tree

7 files changed

+514
-27
lines changed

7 files changed

+514
-27
lines changed

demo-vue/app/App_Resources/Android/app.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
android {
22
defaultConfig {
3-
compileSdkVersion 31
3+
compileSdkVersion 33
44
multiDexEnabled true
55
minSdkVersion 18
6-
targetSdkVersion 31
6+
targetSdkVersion 33
77
versionCode 104
88
versionName "2.0"
99
ndk {

demo-vue/app/assets/map.geojson

Lines changed: 393 additions & 0 deletions
Large diffs are not rendered by default.

demo-vue/app/main.ts

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,20 @@ async function startSentry() {
1212
dsn: SENTRY_DSN,
1313
debug: true,
1414
flushSendEvent: true,
15+
enableNativeCrashHandling: false,
1516
enableAutoPerformanceTracking: true
1617
});
17-
console.log('startSentry done ');
1818
setTimeout(()=>{
19-
console.log('timeout');
20-
Sentry.withScope(scope => {
21-
console.log('about to captureMessage ');
22-
try {
23-
24-
scope.setTag('myTag', 'tag-value');
25-
scope.setExtra('myExtra', 'extra-value');
26-
scope.addBreadcrumb({ message: 'test' });
27-
Sentry.captureMessage('Hello Sentry!');
28-
// Sentry.flush();
29-
} catch (error) {
30-
console.error(error);
31-
}
32-
});
19+
// Sentry.withScope(scope => {
20+
// try {
21+
// scope.setTag('myTag', 'tag-value');
22+
// scope.setExtra('myExtra', 'extra-value');
23+
// scope.addBreadcrumb({ message: 'test' });
24+
// Sentry.captureMessage('Hello Sentry!');
25+
// } catch (error) {
26+
// console.error(error);
27+
// }
28+
// });
3329
}, 1000);
3430
} catch(err){console.error(err, err.stack);}
3531

@@ -42,8 +38,44 @@ if (!__ANDROID__ || Application.android.context) {
4238

4339
}
4440

41+
// let typedArray;
42+
// const textDecoder = new TextDecoder();
43+
// const textEncoder = new TextEncoder();
44+
// const strTest = '';
45+
// if (__IOS__){
46+
// let startTime = Date.now();
47+
// const testNSData = NSString.stringWithString(strTest).dataUsingEncoding(NSUTF8StringEncoding);
48+
// typedArray = new Uint8Array(interop.bufferFromData(testNSData));
49+
// console.log('typedArray encoded', Date.now() - startTime, 'ms');
50+
// startTime = Date.now();
51+
// let decoded = NSString.alloc().initWithDataEncoding(typedArray.buffer, NSUTF8StringEncoding) + '';
52+
// console.log('typedArray decoded', decoded === strTest, Date.now() - startTime, 'ms');
4553

54+
// startTime = Date.now();
55+
// typedArray = textEncoder.encode(strTest);
56+
// console.log('textDecoder encoded', Date.now() - startTime, 'ms');
57+
// startTime = Date.now();
58+
// decoded= textDecoder.decode(typedArray);
59+
// console.log('textDecoder decoded', decoded === strTest, Date.now() - startTime, 'ms');
60+
// }
61+
// if (__ANDROID__){
62+
// const charset = java.nio.charset.Charset.forName('UTF-8');
63+
// const nencoder = charset.newEncoder();
64+
// const ndecoder = charset.newDecoder();
65+
// let startTime = Date.now();
66+
// // @ts-ignore
67+
// const testByteArray = new Uint8Array(ArrayBuffer.from(nencoder.encode(java.nio.CharBuffer.wrap(strTest))));
68+
// console.log('typedArray encoded', Date.now() - startTime, 'ms');
69+
// let decoded = ndecoder.decode(testByteArray.buffer as any).toString();
70+
// console.log('typedArray decoded', decoded === strTest, Date.now() - startTime, 'ms');
4671

72+
// startTime = Date.now();
73+
// typedArray = textEncoder.encode(strTest);
74+
// console.log('textDecoder encoded', Date.now() - startTime, 'ms');
75+
// startTime = Date.now();
76+
// decoded= textDecoder.decode(typedArray);
77+
// console.log('textDecoder decoded', decoded === strTest, Date.now() - startTime, 'ms');
78+
// }
4779
new Vue({
4880
render: h => h('frame', [h(Home)])
4981
}).$start();

demo-vue/app/views/Home.ts

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import * as Sentry from '@nativescript-community/sentry';
2+
import { File, knownFolders, path } from '@nativescript/core';
3+
import { TextEncoder } from '@nativescript/core/text';
4+
import { createArrayBuffer } from '@nativescript-community/arraybuffers';
25
declare class TestClass {
36
static someMethod();
47
}
@@ -11,7 +14,9 @@ export default {
1114
</ActionBar>
1215
<StackLayout>
1316
<Button text="leaveBreadcrumb" @tap="leaveBreadcrumb"/>
14-
<Button text="notify" @tap="notify"/>
17+
<Button text="message" @tap="message"/>
18+
<Button text="attachment" @tap="attachment"/>
19+
<Button text="attachmentFile" @tap="attachmentFile"/>
1520
<Button text="throwError" @tap="throwError"/>
1621
<Button text="crashTest" @tap="crashTest"/>
1722
<Button text="nativeCrashTest" @tap="nativeCrashTest"/>
@@ -24,14 +29,64 @@ export default {
2429
// mounted() {
2530
// },
2631
methods: {
27-
notify() {
28-
Sentry.captureException(new Error('test_notify_error' + Date.now()));
32+
message() {
33+
Sentry.withScope(scope => {
34+
try {
35+
scope.setTag('myTag', 'tag-value');
36+
scope.setExtra('myExtra', 'extra-value');
37+
scope.addBreadcrumb({ message: 'local breadcrumb' });
38+
Sentry.captureMessage('Hello Sentry!');
39+
} catch (error) {
40+
console.error(error);
41+
}
42+
});
43+
},
44+
attachment() {
45+
Sentry.withScope(scope => {
46+
try {
47+
scope.addAttachment({
48+
data:'this is a test text file',
49+
filename: 'test.jpg',
50+
});
51+
52+
Sentry.captureMessage('Attachment!');
53+
} catch (error) {
54+
console.error(error);
55+
}
56+
});
57+
},
58+
attachmentFile() {
59+
Sentry.withScope(scope => {
60+
try {
61+
const filePath = path.join(knownFolders.currentApp().path, 'assets/map.geojson');
62+
let typedArray;
63+
if (__ANDROID__) {
64+
const javaFile = new java.io.File(filePath);
65+
const stream = new java.io.FileInputStream(javaFile);
66+
typedArray = createArrayBuffer(stream.available(), true, false);
67+
java.nio.channels.Channels.newChannel(stream).read(typedArray.buffer['nativeObject']);
68+
}
69+
if (__IOS__) {
70+
const data = File.fromPath(filePath).readSync();
71+
console.log('test', data, interop.bufferFromData(data));
72+
typedArray = new Uint8Array(interop.bufferFromData(data));
73+
}
74+
scope.addAttachment({
75+
data: typedArray.buffer,
76+
filename: 'map.geojson',
77+
});
78+
79+
Sentry.captureMessage('Attachment File!');
80+
} catch (error) {
81+
console.error(error);
82+
}
83+
});
2984
},
3085
throwError() {
31-
throw new Error('test_thrown_error');
86+
Sentry.captureException(new Error('test_notify_error' + Date.now()));
3287
},
3388
leaveBreadcrumb() {
34-
Sentry.addBreadcrumb({ category: 'ui', message: 'test', level: 'info' as any });
89+
Sentry.addBreadcrumb({ category: 'ui', message: 'global breadcrumb', level: 'info' as any });
3590
},
3691
crashTest() {
3792
Sentry.nativeCrash();

demo-vue/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"devDependencies": {
1212
"@babel/core": "~7.19.3",
1313
"@babel/preset-env": "~7.19.4",
14-
"@nativescript/android": "8.3.1",
14+
"@nativescript/android": "8.4.0-alpha.4",
1515
"@nativescript/ios": "8.3.3",
1616
"@nativescript/webpack": "~5.0.9",
1717
"@sentry/browser": "7.15.0",

demo-vue/pnpm-lock.yaml

Lines changed: 10 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo-vue/references.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable spaced-comment */
22
/// <reference path="../src/references.d.ts" />
3+
/// <reference path="../references.d.ts" />
34

45
declare module '*.vue' {
56
import Vue from 'vue';

0 commit comments

Comments
 (0)