Skip to content

Commit

Permalink
fix: make alarms and identity features optional
Browse files Browse the repository at this point in the history
fixes #103
  • Loading branch information
Thomas Parisot committed Aug 27, 2020
1 parent 32e183c commit 501952c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ env:
jest/globals: true
parserOptions:
sourceType: module
ecmaVersion: 2020
globals:
process: true
rules:
Expand Down
2 changes: 1 addition & 1 deletion src/background/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export default class Background {
//workaround due to the `browser.alarms.get` uncatchable exception bug
//@see https://code.google.com/p/chromium/issues/detail?id=265800
browser.alarms.getAll().then(alarms => {
const exists = alarms.some(alarm => alarm.name === alarmName);
const exists = (alarms ?? []).some(alarm => alarm.name === alarmName);

if (!exists){
browser.alarms.create(alarmName, { periodInMinutes: 0.5 });
Expand Down
12 changes: 11 additions & 1 deletion src/lib/angular/chrome-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import browser from 'webextension-polyfill';

import Preferences from '../preferences.js';

/**
* Indicates if the browser has a certain API available, or not
* Not all WebExtension APIs are available at a given time (Safari 14 does not have browser.identity for instance).
*
* @param {String} cap
* @returns {Boolean}
*/
const hasCapability = (cap) => cap in browser;

/**
* Chrome API Abstraction.
* Especially used to enables unit/function tests without relying on Chrome API direct access.
Expand All @@ -28,7 +37,8 @@ export default angular.module('ChromeService', [])
const port = browser.runtime.connect();
port.postMessage({ [channel]: data });
},
getRedirectURL: browser.identity.getRedirectURL.bind(browser.identity),
hasCapability,
getRedirectURL: (...args) => hasCapability('identity') && browser.identity.getRedirectURL(...args),
getUrl: path => browser.runtime.getURL(path),
};
});
2 changes: 1 addition & 1 deletion src/now-playing/broadcast-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function BroadcastController($scope, chrome, preferences, $timeou

$scope.stations = stations;
$scope.currentStation = preferences.get('playback.station', 'fip-paris');
$scope.lastfm_enabled = lastFm.isEnabled() && preferences.get("lastfm.scrobbling") && preferences.get("lastfm.username");
$scope.lastfm_enabled = lastFm.isEnabled() && chrome.hasCapability("identity") && preferences.get("lastfm.scrobbling") && preferences.get("lastfm.username");

$scope.broadcasts = preferences.get('broadcasts', []);
$scope.current_index = getPosition($scope.broadcasts, $scope.broadcasts.length - 1);
Expand Down
2 changes: 1 addition & 1 deletion src/now-playing/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ <h2 class="title" ng-show="!broadcast.authors">{{broadcast.title || ('no_informa
</optgroup>
</select>
</li>
<li>
<li ng-if="lastfm_enabled">
<span class="icon-lastfm" aria-label="Last.fm Status" ng-class="{'icon-activated': lastfm_enabled, 'icon-deactivated': !lastfm_enabled}"></span>
<a href="#settings">{{ 'change_settings' | i18n }}</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion src/options/options-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function OptionsController($scope, chrome, preferences, $timeout)
$scope.currentStation = preferences.get('playback.station', 'fip-paris');
$scope.quality = preferences.get('playback.quality', 'hd');
$scope.saveStatus = 'idle';
$scope.lastfm_enabled = lastFm.isEnabled();
$scope.lastfm_enabled = lastFm.isEnabled() && chrome.hasCapability("identity");

$scope.save = function(){
const prevStation = preferences.get('playback.station', 'fip-paris');
Expand Down

0 comments on commit 501952c

Please sign in to comment.