Allow for set contexts

This commit is contained in:
Idrees Hassan
2025-11-16 09:25:48 -05:00
parent 76e55a3caa
commit a5e81e4265
9 changed files with 2953 additions and 15 deletions

22
dist/birb.js vendored
View File

@@ -847,6 +847,7 @@
const SAVE_KEY = "birbSaveData";
const ROOT_PATH = "";
const SET_CONTEXT = "__CONTEXT__";
/**
* @typedef {import('./application.js').BirbSaveData} BirbSaveData
@@ -1033,7 +1034,7 @@
*/
isContextActive() {
// @ts-expect-error
return typeof chrome !== "undefined";
return typeof chrome !== "undefined" && typeof chrome.storage !== "undefined" && typeof chrome.storage.sync !== "undefined";
}
/**
@@ -1077,6 +1078,7 @@
}
class ObsidianContext extends Context {
/**
* @override
* @returns {boolean}
@@ -1164,15 +1166,29 @@
}
}
const CONTEXTS = [
const contextProcessingOrder = [
new UserScriptContext(),
new ObsidianContext(),
new BrowserExtensionContext(),
new LocalContext()
];
const CONTEXTS_BY_KEY = {
"local": LocalContext,
"userscript": UserScriptContext,
"browser-extension": BrowserExtensionContext,
"obsidian": ObsidianContext
};
/**
* Determines and returns the current context
* @returns {Context}
*/
function getContext() {
for (const context of CONTEXTS) {
if (CONTEXTS_BY_KEY[SET_CONTEXT]) {
return new CONTEXTS_BY_KEY[SET_CONTEXT]();
}
for (const context of contextProcessingOrder) {
if (context.isContextActive()) {
return context;
}

BIN
dist/extension.zip vendored

Binary file not shown.

View File

@@ -847,6 +847,7 @@
const SAVE_KEY = "birbSaveData";
const ROOT_PATH = "";
const SET_CONTEXT = "__CONTEXT__";
/**
* @typedef {import('./application.js').BirbSaveData} BirbSaveData
@@ -1033,7 +1034,7 @@
*/
isContextActive() {
// @ts-expect-error
return typeof chrome !== "undefined";
return typeof chrome !== "undefined" && typeof chrome.storage !== "undefined" && typeof chrome.storage.sync !== "undefined";
}
/**
@@ -1077,6 +1078,7 @@
}
class ObsidianContext extends Context {
/**
* @override
* @returns {boolean}
@@ -1164,15 +1166,29 @@
}
}
const CONTEXTS = [
const contextProcessingOrder = [
new UserScriptContext(),
new ObsidianContext(),
new BrowserExtensionContext(),
new LocalContext()
];
const CONTEXTS_BY_KEY = {
"local": LocalContext,
"userscript": UserScriptContext,
"browser-extension": BrowserExtensionContext,
"obsidian": ObsidianContext
};
/**
* Determines and returns the current context
* @returns {Context}
*/
function getContext() {
for (const context of CONTEXTS) {
if (CONTEXTS_BY_KEY[SET_CONTEXT]) {
return new CONTEXTS_BY_KEY[SET_CONTEXT]();
}
for (const context of contextProcessingOrder) {
if (context.isContextActive()) {
return context;
}

22
dist/obsidian/main.js vendored
View File

@@ -852,6 +852,7 @@ module.exports = class PocketBird extends Plugin {
const SAVE_KEY = "birbSaveData";
const ROOT_PATH = "";
const SET_CONTEXT = "__CONTEXT__";
/**
* @typedef {import('./application.js').BirbSaveData} BirbSaveData
@@ -1038,7 +1039,7 @@ module.exports = class PocketBird extends Plugin {
*/
isContextActive() {
// @ts-expect-error
return typeof chrome !== "undefined";
return typeof chrome !== "undefined" && typeof chrome.storage !== "undefined" && typeof chrome.storage.sync !== "undefined";
}
/**
@@ -1082,6 +1083,7 @@ module.exports = class PocketBird extends Plugin {
}
class ObsidianContext extends Context {
/**
* @override
* @returns {boolean}
@@ -1169,15 +1171,29 @@ module.exports = class PocketBird extends Plugin {
}
}
const CONTEXTS = [
const contextProcessingOrder = [
new UserScriptContext(),
new ObsidianContext(),
new BrowserExtensionContext(),
new LocalContext()
];
const CONTEXTS_BY_KEY = {
"local": LocalContext,
"userscript": UserScriptContext,
"browser-extension": BrowserExtensionContext,
"obsidian": ObsidianContext
};
/**
* Determines and returns the current context
* @returns {Context}
*/
function getContext() {
for (const context of CONTEXTS) {
if (CONTEXTS_BY_KEY[SET_CONTEXT]) {
return new CONTEXTS_BY_KEY[SET_CONTEXT]();
}
for (const context of contextProcessingOrder) {
if (context.isContextActive()) {
return context;
}

View File

@@ -861,6 +861,7 @@
const SAVE_KEY = "birbSaveData";
const ROOT_PATH = "";
const SET_CONTEXT = "__CONTEXT__";
/**
* @typedef {import('./application.js').BirbSaveData} BirbSaveData
@@ -1047,7 +1048,7 @@
*/
isContextActive() {
// @ts-expect-error
return typeof chrome !== "undefined";
return typeof chrome !== "undefined" && typeof chrome.storage !== "undefined" && typeof chrome.storage.sync !== "undefined";
}
/**
@@ -1091,6 +1092,7 @@
}
class ObsidianContext extends Context {
/**
* @override
* @returns {boolean}
@@ -1178,15 +1180,29 @@
}
}
const CONTEXTS = [
const contextProcessingOrder = [
new UserScriptContext(),
new ObsidianContext(),
new BrowserExtensionContext(),
new LocalContext()
];
const CONTEXTS_BY_KEY = {
"local": LocalContext,
"userscript": UserScriptContext,
"browser-extension": BrowserExtensionContext,
"obsidian": ObsidianContext
};
/**
* Determines and returns the current context
* @returns {Context}
*/
function getContext() {
for (const context of CONTEXTS) {
if (CONTEXTS_BY_KEY[SET_CONTEXT]) {
return new CONTEXTS_BY_KEY[SET_CONTEXT]();
}
for (const context of contextProcessingOrder) {
if (context.isContextActive()) {
return context;
}

2837
dist/vencord/birb.export.js vendored Normal file

File diff suppressed because it is too large Load Diff