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

Safari Extension #104

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
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
25,725 changes: 17,964 additions & 7,761 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "webextension-fip",
"version": "1.6.0",
"description": "FIP Radio WebExtension for an in-browser radio playback and scrobbling experience.",
"main": "index.js",
"main": "src/manifest.json",
"type": "module",
"private": true,
"engines": {
Expand Down Expand Up @@ -58,20 +58,20 @@
"@babel/preset-env": "^7.8.3",
"@babel/runtime": "^7.8.3",
"babel-plugin-transform-inline-environment-variables": "^0.4.3",
"eslint": "^6.8.0",
"eslint": "^7.7.0",
"eslint-plugin-jest": "^23.6.0",
"eslint-plugin-promise": "^4.2.1",
"jest": "^24.9.0",
"jest": "^26.4.2",
"node-static": "^0.7.11",
"npm-run-all": "^4.1.5",
"rollup": "^1.29.0",
"rollup": "^2.26.6",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-globals": "^1.4.0",
"rollup-plugin-node-resolve": "^5.2.0",
"sinon": "^8.0.4",
"sinon": "^9.0.3",
"xvfb-maybe": "^0.2.1"
},
"dependencies": {
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