Skip to content

Commit

Permalink
Update to Manifest v3 and release v0.7
Browse files Browse the repository at this point in the history
Note: Does not work on Firefox. Chromium-only release.
  • Loading branch information
violine1101 committed Nov 6, 2022
1 parent f346206 commit 26b1f2f
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 106 deletions.
11 changes: 6 additions & 5 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"manifest_version": 2,
"manifest_version": 3,
"name": "Mojira Plus",
"version": "0.6",
"version": "0.7",

"description": "Enables various additional features on Mojang's bug tracker Mojira for helpers, moderators, and other Mojira power users.",

"browser_specific_settings": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "68.0"
"strict_min_version": "101.0"
}
},

Expand All @@ -18,15 +18,16 @@
},

"background": {
"page": "src/background/background.html"
"service_worker": "src/background.js",
"type": "module"
},

"options_ui": {
"page": "src/options/options.html",
"browser_style": true
},

"browser_action": {
"action": {
"default_icon": "icons/mojira-logo-32.png",
"default_title": "Mojira Plus",
"browser_style": true
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"copylibs": "(rm -rf lib || rmdir /Q /S lib || echo>NUL) && mkdir lib && (cp -r node_modules/webextension-polyfill/dist/* ./lib || copy node_modules\\webextension-polyfill\\dist\\* .\\lib)",
"build": "npm run copylibs && web-ext build -o",
"lint": "npm run copylibs && web-ext lint"
"lint": "npm run copylibs && web-ext lint --firefox-preview"
},
"author": "violine1101",
"license": "GPL-3.0",
Expand Down
14 changes: 8 additions & 6 deletions src/background/background.js → src/background.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { initAutoupdate } from '../util/autoupdate.js';
import { showErrorBadge } from '../util/badge.js';
import { reportError } from '../util/errorReporting.js';
import { getMessages, triggerMessageUpdate } from '../util/messages.js';
import { getCustomSortIndex, getPostponeAction, getPrefix, setCustomSortIndex, setPopupMessage } from '../util/storage.js';
import '../lib/browser-polyfill.js';

import { initAutoupdate } from './util/autoupdate.js';
import { showErrorBadge } from './util/badge.js';
import { reportError } from './util/errorReporting.js';
import { getMessages, triggerMessageUpdate } from './util/messages.js';
import { getCustomSortIndex, getPostponeAction, getPrefix, setCustomSortIndex, setPopupMessage } from './util/storage.js';

/**
* @type {{
Expand All @@ -18,7 +20,7 @@ let permissionCache = {
(async () => {
await setPopupMessage(undefined);

browser.browserAction.onClicked.addListener(() => {
browser.action.onClicked.addListener(() => {
browser.runtime.openOptionsPage();
});

Expand Down
10 changes: 0 additions & 10 deletions src/background/background.html

This file was deleted.

33 changes: 14 additions & 19 deletions src/content/permissionCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,24 @@ function parsePermissionResponse(response) {
*/
function queryPermissions() {
return new Promise(async (resolve, reject) => {
const httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = async () => {
if (httpRequest.readyState === XMLHttpRequest.DONE) {
if (httpRequest.status === 200) {
try {
const perm = parsePermissionResponse(httpRequest.responseText);
resolve(perm);
} catch (error) {
reject(error);
}
} else if (httpRequest.status === 401) {
// User is not logged in
resolve(false);
try {
const response = await fetch('https://bugs.mojang.com/rest/api/2/myself?expand=groups');
const text = await response.text();

if (response.ok) {
try {
const perm = parsePermissionResponse(text);
resolve(perm);
} catch (error) {
reject(error);
}
} else if (response.status === 401) {
resolve(false);
} else {
reject(
new Error(`${permissionCheckError}The server returned status code ${httpRequest.status} ${httpRequest.statusText}.`)
new Error(`${permissionCheckError}The server returned status code ${response.status} ${text}.`)
);
}
}

try {
httpRequest.open('GET', 'https://bugs.mojang.com/rest/api/2/myself?expand=groups');
httpRequest.send();
} catch (error) {
reject(`${permissionCheckError}${error}`);
}
Expand Down
33 changes: 16 additions & 17 deletions src/util/badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ let currentBadge = 'none';
* @param {string} message The message that should be shown on the popup
*/
export async function showSuccessBadge(message) {
browser.browserAction.setPopup({ popup: '/src/popup/popup.html' });
browser.action.setPopup({ popup: '/src/popup/popup.html' });
await setPopupMessage(message);

browser.browserAction.setBadgeBackgroundColor({ color: '#222288' });
if (browser.browserAction.setBadgeTextColor) {
browser.browserAction.setBadgeTextColor({ color: '#ffffff' });
browser.action.setBadgeBackgroundColor({ color: '#222288' });
if (browser.action.setBadgeTextColor) {
browser.action.setBadgeTextColor({ color: '#ffffff' });
}
browser.browserAction.setBadgeText({ text: 'i' });
browser.action.setBadgeText({ text: 'i' });

currentBadge = 'success';
}
Expand All @@ -28,11 +28,11 @@ export async function showSuccessBadge(message) {
export async function showLoadingBadge() {
if (currentBadge === 'error') return;

browser.browserAction.setBadgeBackgroundColor({ color: '#228822' });
if (browser.browserAction.setBadgeTextColor) {
browser.browserAction.setBadgeTextColor({ color: '#ffffff' });
browser.action.setBadgeBackgroundColor({ color: '#228822' });
if (browser.action.setBadgeTextColor) {
browser.action.setBadgeTextColor({ color: '#ffffff' });
}
browser.browserAction.setBadgeText({ text: '?' });
browser.action.setBadgeText({ text: '?' });

currentBadge = 'loading';
}
Expand All @@ -42,14 +42,14 @@ export async function showLoadingBadge() {
* @param {string} message The message that should be shown on the popup
*/
export async function showErrorBadge(message) {
browser.browserAction.setPopup({ popup: '/src/popup/popup.html' });
browser.action.setPopup({ popup: '/src/popup/popup.html' });
await setPopupMessage(message);

browser.browserAction.setBadgeBackgroundColor({ color: '#882222' });
if (browser.browserAction.setBadgeTextColor) {
browser.browserAction.setBadgeTextColor({ color: '#ffffff' });
browser.action.setBadgeBackgroundColor({ color: '#882222' });
if (browser.action.setBadgeTextColor) {
browser.action.setBadgeTextColor({ color: '#ffffff' });
}
browser.browserAction.setBadgeText({ text: '!' });
browser.action.setBadgeText({ text: '!' });

currentBadge = 'error';
}
Expand All @@ -59,9 +59,8 @@ export async function hideBadge(delay = false) {
await new Promise(resolve => setTimeout(resolve, 1000));
}

browser.browserAction.setPopup({ popup: '' });

browser.browserAction.setBadgeText({ text: '' });
browser.action.setPopup({ popup: '' });
browser.action.setBadgeText({ text: '' });

currentBadge = 'none';
}
34 changes: 12 additions & 22 deletions src/util/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,19 @@ async function updateLastCommits(response, lastKnownSha) {
/**
* Updates the commits since the last update
*/
export function updateChangelog() {
return new Promise(async resolve => {
const lastKnownSha = await getLastCommit();
export async function updateChangelog() {
const lastKnownSha = await getLastCommit();

if (!(await getCommitUpdatesEnabled())) {
await setLastCommit('none');
return;
}

const httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = async () => {
if (httpRequest.readyState === XMLHttpRequest.DONE) {
if (httpRequest.status === 200) {
await updateLastCommits(httpRequest.responseText, lastKnownSha);
} else {
console.error(httpRequest);
}
if (!(await getCommitUpdatesEnabled())) {
await setLastCommit('none');
return;
}

resolve();
}
};
const response = await fetch(await getCommitUrl());

httpRequest.open('GET', await getCommitUrl());
httpRequest.send();
});
if (response.ok) {
await updateLastCommits(await response.text(), lastKnownSha);
} else {
console.error(response);
}
}
44 changes: 18 additions & 26 deletions src/util/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,26 @@ async function processMessageUpdate(response) {
* Check for updated messages
* @param {boolean} silent Whether the update should be executed silently (without a badge)
*/
function checkForMessageUpdates(silent = false) {
return new Promise(async resolve => {
await setLastUpdateCheck();
async function checkForMessageUpdates(silent = false) {
await setLastUpdateCheck();

if (!silent) await showLoadingBadge();
if (!silent) await showLoadingBadge();

const httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = async () => {
if (httpRequest.readyState === XMLHttpRequest.DONE) {
if (httpRequest.status === 200) {
if (httpRequest.responseText !== await getLastCachedMessages()) {
await processMessageUpdate(httpRequest.responseText);
} else {
await hideBadge(!silent);
}
} else {
await showErrorBadge(
'An error occurred while trying to check whether the helper messages were updated.\n'
+ `The server returned status code ${httpRequest.status} ${httpRequest.statusText}.`
);
}
resolve();
}
};

httpRequest.open('GET', await getUrl());
httpRequest.send();
});
const response = await fetch(await getUrl());
const text = await response.text();

if (response.ok) {
if (text !== await getLastCachedMessages()) {
await processMessageUpdate(text);
} else {
await hideBadge(!silent);
}
} else {
await showErrorBadge(
'An error occurred while trying to check whether the helper messages were updated.\n'
+ `The server returned status code ${response.status} ${text}.`
);
}
}

/**
Expand Down

0 comments on commit 26b1f2f

Please sign in to comment.