Skip to content
This repository has been archived by the owner on Feb 4, 2021. It is now read-only.

Commit

Permalink
Fix #319
Browse files Browse the repository at this point in the history
  • Loading branch information
freaktechnik committed Sep 7, 2017
1 parent 9cf4f63 commit 3a219f2
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 14 deletions.
8 changes: 8 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -540,5 +540,13 @@
"queue_concurrentRequests_title": {
"message": "Concurrent request count",
"description": "Title of the concurrent request count setting."
},
"cookies_disabled": {
"message": "Could not read your channel list, because cookies are disabled for the extension",
"description": "Error message shown, when cookies are not enabled for the extension and it thus can't open the database."
},
"enable_cookies": {
"message": "Help me fix this",
"description": "Button label to resolve the cookies problem. Links to a website with a guide."
}
}
25 changes: 19 additions & 6 deletions src/background/channel/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import providers from "../providers";
import ChannelsManager from "./manager";
import ChannelList from "./list";
import EventSink from '../providers/events';
import { emit, invokeOnce } from "../../utils";
import { emit } from "../../utils";
import ParentalControls from "../parental-controls";
import { flatten, partial, debounce } from "underscore";
import * as debugDump from "./dump";
Expand All @@ -16,6 +16,7 @@ import * as logins from "../logins";
import EventTarget from 'event-target-shim';
import ErrorState from '../error-state';
import { formatChannel, formatChannels } from './utils';
import { CantOpenListError } from '../../read-channel-list';

/**
* @event module:channel/controller.ChannelController#channelsadded
Expand All @@ -31,6 +32,7 @@ import { formatChannel, formatChannels } from './utils';
*/

const REFRESH_PROFILE_URL = "https://support.mozilla.org/kb/refresh-firefox-reset-add-ons-and-settings",
ACCEPT_COOKIES_URL = "http://streamnotifier.ch/help/accept-cookies",
/**
* Filters mature channels if parental controls are activated.
*
Expand Down Expand Up @@ -181,11 +183,22 @@ export default class ChannelController extends EventTarget {
});
}
});
this._list.addEventListener("unfixableerror", () => {
const es = new ErrorState(browser.i18n.getMessage("restore_failed"), ErrorState.UNRECOVERABLE, [
browser.i18n.getMessage("restore_action")
]);
es.addEventListener("action", () => browser.tabs.create({ url: REFRESH_PROFILE_URL }));
this._list.addEventListener("unfixableerror", ({ detail: e }) => {
let message,
actions = [],
actionsListener;
if(e instanceof CantOpenListError) {
message = browser.i18n.getMessage("cookies_disabled");
actions.push(browser.i18n.getMessage("enable_cookies"));
actionsListener = () => browser.tabs.create({ url: ACCEPT_COOKIES_URL });
}
else {
message = browser.i18n.getMessage("restore_failed");
actions.push(browser.i18n.getMessage("restore_action"));
actionsListener = () => browser.tabs.create({ url: REFRESH_PROFILE_URL })
}
const es = new ErrorState(message, ErrorState.UNRECOVERABLE, actions);
es.addEventListener("action", actionsListener);
});
// Provider update events

Expand Down
20 changes: 13 additions & 7 deletions src/background/channel/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import prefs from "../../preferences";
import { Channel } from "./core";
import LiveState from "../../live-state";
import ReadChannelList from './read-list';
import { FixListError } from '../../read-channel-list';
import { FixListError, CantOpenListError } from '../../read-channel-list';
import SerializedReadChannelList from '../../read-channel-list';

/**
Expand Down Expand Up @@ -63,6 +63,7 @@ import SerializedReadChannelList from '../../read-channel-list';
* The database could not be repaired.
*
* @event module:channel/list.ChannelList#unfixableerror
* @type {Error}
*/

const eventTargets = new Set();
Expand Down Expand Up @@ -133,12 +134,17 @@ export default class ChannelList extends ReadChannelList {
}
});
}).then(() => emit(this, "ready")).catch((error) => {
if(typeof error === "object" && error instanceof FixListError) {
return this.clear().catch((e) => {
console.error("Couldn't delete the DB");
emit(this, "unfixableerror");
throw e;
});
if(typeof error === "object") {
if(error instanceof FixListError) {
return this.clear().catch((e) => {
console.error("Couldn't delete the DB");
emit(this, "unfixableerror", error);
throw e;
});
}
else if(error instanceof CantOpenListError) {
emit(this, "unfixableerror", error);
}
}
throw error;
});
Expand Down
16 changes: 15 additions & 1 deletion src/read-channel-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export class FixListError extends Error {
}
}

export class CantOpenListError extends Error {
constructor() {
super("Can not open list due to security settings");
}
}

/**
* @class module:read-channel-list.ReadChannelList
* @extends external:EventTarget
Expand Down Expand Up @@ -168,7 +174,15 @@ export default class ReadChannelList extends EventTarget {

this._openingDB = new Promise((resolve, reject) => {
// Try to open the DB
const request = window.indexedDB.open(name, VERSION);
let request;
try {
request = window.indexedDB.open(name, VERSION);
}
catch(e) {
reject(new CantOpenListError());
return;
}

request.onupgradeneeded = (e) => {
this.db = e.target.result;

Expand Down

0 comments on commit 3a219f2

Please sign in to comment.