Skip to content

Commit

Permalink
add support for offscreen/headless mode
Browse files Browse the repository at this point in the history
  • Loading branch information
deleolajide committed Dec 9, 2024
1 parent 1f688ca commit 3dd041c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
Binary file not shown.
Binary file not shown.
26 changes: 21 additions & 5 deletions docs/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ self.addEventListener('install', function(event) {
console.debug('activate', event);
});
self.addEventListener('activate', function (event) {
console.debug('activate', event);
openOrinAyoWindow();
console.debug('activate', event);
createOffscreen();
});

self.addEventListener('message', function (event) {
Expand Down Expand Up @@ -53,7 +53,7 @@ if (location.protocol == "chrome-extension:") {
console.debug("onStartup");
});

chrome.action.onClicked.addListener(() => {
chrome.action.onClicked.addListener( () => {
console.debug("action onClicked");
openOrinAyoWindow();
});
Expand All @@ -68,9 +68,10 @@ if (location.protocol == "chrome-extension:") {

chrome.windows.onRemoved.addListener((win) => {
//console.debug("onRemoved", win);
chrome.storage.local.get('orinAyoWin', (data) => {
chrome.storage.local.get('orinAyoWin', async (data) => {
if (data.orinAyoWin && data.orinAyoWin == win) {
chrome.storage.local.remove('orinAyoWin');
createOffscreen();
}
});
});
Expand All @@ -82,11 +83,26 @@ if (location.protocol == "chrome-extension:") {
//
// -------------------------------------------------------

async function createOffscreen() {
try {
if (await chrome.offscreen.hasDocument()) return;

await chrome.offscreen.createDocument({
url: "index.html",
reasons: ["WEB_RTC"],
justification: "testing",
});
} catch (e) {
console.warn("createOffscreen", e);
}
}

const createOrinAyoWindow = () => {
console.debug("createOrinAyoWindow");
const data = {url: chrome.runtime.getURL("index.html"), type: 'popup'};

chrome.windows.create(data, (win) => {
chrome.windows.create(data, async (win) => {
await chrome.offscreen.closeDocument();
chrome.storage.local.set({orinAyoWin: win.id});
chrome.windows.update(win.id, {width: 1050, height: 1040});
});
Expand Down
2 changes: 1 addition & 1 deletion docs/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ function loadMidiSynth() {

async function onloadHandler() {
console.debug("onloadHandler");

let version = "latest";
if (!!chrome.runtime?.getManifest) version = chrome.runtime.getManifest().version;
document.title = "Orin Ayo | " + version;
Expand Down
2 changes: 2 additions & 0 deletions docs/js/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ var chord_loops = [
"assets/chords/power-strum_96_10000_10000_4.chord",
"assets/chords/praise_127_15118.chord",
"assets/chords/praise2_127_7559_7559_4.chord",
"assets/chords/qy-irish-pop_108_8889_8889_2.chord",
"assets/chords/qy-mixture_94_10213_10213_2.chord",
"assets/chords/regaaton_100_9600.chord",
"assets/chords/rock_90_21333.chord",
"assets/chords/rnb_100_19200.chord",
Expand Down
3 changes: 2 additions & 1 deletion docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
"name": "OrinAyo",
"short_name": "OrinAyo",
"description": "The Guitar Arranger",
"version": "0.9.8",
"version": "0.9.9",

"background": {
"service_worker": "./js/background.js"
},
"permissions": [
"offscreen",
"background",
"storage",
"unlimitedStorage"
Expand Down

0 comments on commit 3dd041c

Please sign in to comment.