Skip to content

Commit

Permalink
fix: Don't break if browser doesn't implement permissions API
Browse files Browse the repository at this point in the history
see #1643

Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Oct 6, 2024
1 parent f7bc4ed commit 2f8e853
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/lib/adapters/Git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ export default class GitAdapter extends CachingAdapter {

if (Capacitor.getPlatform() === 'web') {
const browser = (await import('../browser-api')).default
let hasPermissions
let hasPermissions, error = false
try {
hasPermissions = await browser.permissions.contains({ origins: [this.server.url + '/'] })
} catch (e) {
error = true
console.warn(e)
}
if (!hasPermissions) {
if (!error && !hasPermissions) {
throw new MissingPermissionsError()
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/lib/adapters/GoogleDrive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,14 @@ export default class GoogleDriveAdapter extends CachingAdapter {
if (Capacitor.getPlatform() === 'web') {
const browser = (await import('../browser-api')).default
const origins = ['https://oauth2.googleapis.com/', 'https://www.googleapis.com/']
let hasPermissions
let hasPermissions, error = false
try {
hasPermissions = await browser.permissions.contains({ origins })
} catch (e) {
error = true
console.warn(e)
}
if (!hasPermissions) {
if (!error && !hasPermissions) {
throw new MissingPermissionsError()
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/lib/adapters/NextcloudBookmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,14 @@ export default class NextcloudBookmarksAdapter implements Adapter, BulkImportRes
async onSyncStart(needLock = true, forceLock = false): Promise<void> {
if (Capacitor.getPlatform() === 'web') {
const browser = (await import('../browser-api')).default
let hasPermissions
let hasPermissions, error = false
try {
hasPermissions = await browser.permissions.contains({ origins: [this.server.url + '/'] })
} catch (e) {
error = true
console.warn(e)
}
if (!hasPermissions) {
if (!error && !hasPermissions) {
throw new MissingPermissionsError()
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/lib/adapters/WebDav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,14 @@ export default class WebDavAdapter extends CachingAdapter {

if (Capacitor.getPlatform() === 'web') {
const browser = (await import('../browser-api')).default
let hasPermissions
let hasPermissions, error = false
try {
hasPermissions = await browser.permissions.contains({ origins: [this.server.url + '/'] })
} catch (e) {
error = true
console.warn(e)
}
if (!hasPermissions) {
if (!error && !hasPermissions) {
throw new MissingPermissionsError()
}
}
Expand Down

0 comments on commit 2f8e853

Please sign in to comment.