Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sanity checks for permissions #279

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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