Skip to content

Commit

Permalink
fix: extension blocked unless installed
Browse files Browse the repository at this point in the history
  • Loading branch information
KL13NT committed Apr 7, 2021
1 parent 6abc0f8 commit 89a84cd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
13 changes: 9 additions & 4 deletions src/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import { Tracker } from "./tracker.js";

const schemaManager = new SchemaManager();

schemaManager.onReady.addListener(() => {
const historyStore = new HistoryStore();
const indexStore = new IndexStore();
const historyStore = new HistoryStore();
const indexStore = new IndexStore();
const tracker = new Tracker({ historyStore, indexStore });

schemaManager.onInstalled.addListener(() => {
tracker.resetTracking();
});

new Tracker({ historyStore, indexStore });
schemaManager.onReady.addListener(() => {
tracker.startTracking();
});
24 changes: 17 additions & 7 deletions src/background/schema-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,31 @@ import { Logger } from "../utils";
import { transformers } from "./transformers";

export class SchemaManager {
listeners = {
ready: [],
};

constructor() {
this.onReady.emit();

browser.runtime.onInstalled.addListener(() => this.onInstalled.emit()); // for stopping tracking until the schema is ready
browser.runtime.onInstalled.addListener(this.updateListener);
browser.runtime.onInstalled.addListener(this.installListener);
}

onReady = {
addListener: (listener) => this.listeners.ready.push(listener),
invoke: () => {
listeners: [],
addListener: (listener) => this.onReady.listeners.push(listener),
emit: () => {
Logger.info("SCHEMA_0004");

this.onReady.listeners.forEach((listener) => listener.call(this));
},
};

onInstalled = {
listeners: [],
addListener: (listener) => this.onInstalled.listeners.push(listener),
emit: () => {
Logger.info("SCHEMA_0004");

this.listeners.ready.forEach((listener) => listener.call(this));
this.onInstalled.listeners.forEach((listener) => listener.call(this));
},
};

Expand Down
3 changes: 0 additions & 3 deletions src/background/tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ export class Tracker {
tabs.onUpdated.addListener(this.onUpdated);
tabs.onRemoved.addListener(this.onRemoved);
windows.onFocusChanged.addListener(this.onFocusChanged);

this.startTracking();
}

/**
Expand Down Expand Up @@ -64,7 +62,6 @@ export class Tracker {
this.state.tracking = true;

this.interval = setInterval(async () => {
//TODO: update index
try {
if (!shouldSync(this.state)) {
if (!this.state.focused) info("TRACKING_0028");
Expand Down

0 comments on commit 89a84cd

Please sign in to comment.