Skip to content

Commit

Permalink
#27 Register context menu click handler on background initialization.…
Browse files Browse the repository at this point in the history
… Provide permanent id for context items.
  • Loading branch information
mishani0x0ef committed Oct 9, 2017
1 parent 6b56863 commit 76a944a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
28 changes: 17 additions & 11 deletions ReportJ.Extension.Chrome/app/js/background.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
import JiraWrapper from "./services/jira";
import UrlService from "./services/urlService";
import config from "~/config";
import { getRandomString } from "./util/string";

class BackgroundWorker {
constructor(browser) {
constructor(browser, urlService) {
this.browser = browser;
this.urlService = urlService;

this.contextMenus = {
addIssueSummaryId: "3956cb0d-9144-468a-a76e-7d67c58f7949",
};

this.browser.runtime.onInstalled.addListener((e) => this.onInstalled(e));
this.urlService = new UrlService(browser);
this.browser.contextMenus.onClicked.addListener((e) => this.onContextMenuClick(e));
}

onInstalled() {
this.initContextMenu();
this.createContextMenu();
}

initContextMenu() {
createContextMenu() {
const context = "editable";
const title = `${config.app.name} add issue summary`;
this.menuItemId = this.browser.contextMenus.create({
this.browser.contextMenus.create({
"title": title,
"contexts": [context],
"id": getRandomString(),
"id": this.contextMenus.addIssueSummaryId,
});
this.browser.contextMenus.onClicked.addListener((e) => this.onContextMenuClick(e));
}

onContextMenuClick(e) {
if (e.menuItemId !== this.menuItemId) {
return;
if (e.menuItemId === this.contextMenus.addIssueSummaryId) {
this.addIssueSummary();
}
}

addIssueSummary() {
this.browser.tabs.getSelected(null, (tab) => {
const baseUrl = this.urlService.getBaseUrl(tab.url);
const jira = new JiraWrapper(baseUrl);
Expand All @@ -44,4 +50,4 @@ class BackgroundWorker {
}
}

export default new BackgroundWorker(chrome);
export default new BackgroundWorker(chrome, new UrlService(chrome));
2 changes: 1 addition & 1 deletion ReportJ.Extension.Chrome/app/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "ReportJ",
"description": "The reporting helper for JIRA system.",
"homepage_url": "https://github.com/mishani0x0ef/reportj",
"version": "2.4",
"version": "2.4.1",
"permissions": [
"storage",
"activeTab",
Expand Down

0 comments on commit 76a944a

Please sign in to comment.