Skip to content

Commit

Permalink
fix: close method fix
Browse files Browse the repository at this point in the history
  • Loading branch information
farfromrefug committed Apr 23, 2024
1 parent 698fabf commit b8c1c43
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 17 deletions.
35 changes: 23 additions & 12 deletions demo-snippets/vue/Basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ export default {
<Page>
<ActionBar title="Sentry Demo">
</ActionBar>
<StackLayout>
<Button text="leaveBreadcrumb" @tap="leaveBreadcrumb"/>
<Button text="message" @tap="message"/>
<Button text="attachment" @tap="attachment"/>
<Button text="attachmentFile" @tap="attachmentFile"/>
<Button text="throwError" @tap="throwError"/>
<Button text="crashTest" @tap="crashTest"/>
<Button text="nativeCrashTest" @tap="nativeCrashTest"/>
<Button text="androidNativeCrashTest" @tap="androidNativeCrashTest"/>
<Button text="androidNativeCrashCatchedTest" @tap="androidNativeCrashCatchedTest"/>
<Button text="flush" @tap="flush"/>
</StackLayout>
<ScrollView>
<StackLayout>
<Button text="leaveBreadcrumb" @tap="leaveBreadcrumb"/>
<Button text="message" @tap="message"/>
<Button text="attachment" @tap="attachment"/>
<Button text="attachmentFile" @tap="attachmentFile"/>
<Button text="throwError" @tap="throwError"/>
<Button text="crashTest" @tap="crashTest"/>
<Button text="nativeCrashTest" @tap="nativeCrashTest"/>
<Button text="androidNativeCrashTest" @tap="androidNativeCrashTest"/>
<Button text="androidNativeCrashCatchedTest" @tap="androidNativeCrashCatchedTest"/>
<Button text="flush" @tap="flush"/>
<Button text="close" @tap="close"/>
</StackLayout>
</ScrollView>
</Page>
`,
// data() {
Expand Down Expand Up @@ -126,6 +129,14 @@ export default {
},
flush() {
Sentry.flush();
},
async close() {
try {
await Sentry.close();

} catch (error) {
console.error(error, error.stack)
}
}
}
};
2 changes: 1 addition & 1 deletion packages/sentry/wrapper.android.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export declare namespace NATIVE {
version: string;
};
function fetchNativeRelease(): any;
function closeNativeSdk(): void;
function closeNativeSdk(): Promise<void>;
function nativeCrash(): void;
function fetchNativeDeviceContexts(): Promise<any>;
function captureScreenshot(fileName?: string): {
Expand Down
6 changes: 4 additions & 2 deletions src/sentry/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,11 @@ export class NativescriptClient extends BaseClient<NativescriptClientOptions> {
/**
* @inheritDoc
*/
public close(): PromiseLike<boolean> {
public async close() {
// As super.close() flushes queued events, we wait for that to finish before closing the native SDK.
return super.close().then((result: boolean) => NATIVE.closeNativeSdk().then(() => result) as PromiseLike<boolean>);
const result = await super.close();
await NATIVE.closeNativeSdk();
return result;
}

public async flush(timeout?: number): Promise<boolean> {
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/wrapper.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ export namespace NATIVE {
return nativeRelease;
}

export function closeNativeSdk() {
export async function closeNativeSdk() {
io.sentry.Sentry.close();
}

Expand Down
2 changes: 1 addition & 1 deletion src/sentry/wrapper.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export namespace NATIVE {
}
return nativeRelease;
}
export function closeNativeSdk() {
export async function closeNativeSdk() {
NSSentrySDK.close();
}

Expand Down

0 comments on commit b8c1c43

Please sign in to comment.