Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
fox: do not throw for notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
jkoenig134 committed Sep 19, 2023
1 parent fe69477 commit 5fd5ed0
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions packages/cordova/src/CordovaNotificationAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,23 @@ import { Result } from "@js-soft/ts-utils";
export class CordovaNotificationAccess implements INativeNotificationAccess {
public constructor(private readonly logger: ILogger, private readonly config: INativeConfigAccess) {}

public init(): Promise<Result<void>> {
return new Promise((resolve, reject) => {
cordova.plugins.permissions.requestPermission(cordova.plugins.permissions.POST_NOTIFICATIONS, resolve, reject);
});
public async init(): Promise<Result<void>> {
try {
await new Promise<void>((resolve) => {
cordova.plugins.permissions.requestPermission(
cordova.plugins.permissions.POST_NOTIFICATIONS,
() => resolve(),
() => {
this.logger.info("Permission for notifications not granted");
resolve();
}
);
});
} catch (err) {
this.logger.error("Error while requesting notification permission", err);
}

return await Promise.resolve(Result.ok(undefined));
}

public async schedule(title: string, body: string, options?: INativeNotificationScheduleOptions): Promise<Result<number>> {
Expand Down

0 comments on commit 5fd5ed0

Please sign in to comment.