Skip to content

Commit

Permalink
Add sanity checks for permissions (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
mabrikan committed Mar 10, 2023
1 parent 31d7e11 commit 0f20955
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions source/lib/notifications-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {makeApiRequest, getNotifications, getTabUrl, getGitHubOrigin} from './ap
import {getNotificationReasonText} from './defaults.js';
import {openTab} from './tabs-service.js';
import localStore from './local-store.js';
import {queryPermission} from './permissions-service.js';

function getLastReadForNotification(notification) {
// Extract the specific fragment URL for a notification
Expand Down Expand Up @@ -107,6 +108,11 @@ export function getNotificationObject(notificationInfo) {
}

export async function showNotifications(notifications) {
const permissionGranted = await queryPermission('notifications');
if (!permissionGranted) {
return;
}

for (const notification of notifications) {
const notificationId = `github-notifier-${notification.id}`;
const notificationObject = getNotificationObject(notification);
Expand Down
5 changes: 3 additions & 2 deletions source/lib/tabs-service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import browser from 'webextension-polyfill';
import optionsStorage from '../options-storage.js';
import {isChrome} from '../util.js';
import {queryPermission} from './permissions-service.js';

export const emptyTabUrls = isChrome() ? [
'chrome://newtab/',
Expand All @@ -22,8 +23,8 @@ export async function queryTabs(urlList) {

export async function openTab(url) {
const {reuseTabs} = await optionsStorage.getAll();

if (reuseTabs) {
const permissionGranted = await queryPermission('tabs');
if (reuseTabs && permissionGranted) {
const matchingUrls = [url];
if (url.endsWith('/notifications')) {
matchingUrls.push(url + '?query=is%3Aunread');
Expand Down

0 comments on commit 0f20955

Please sign in to comment.