Change package manager to bun and etc
- give scripts their own folder - use bun as a package manager over pnpm - fix some errors in multi-scrobbler
This commit is contained in:
parent
7c810e127b
commit
c46b6a165f
10 changed files with 1609 additions and 232 deletions
66
.github/workflows/deploy.yml
vendored
66
.github/workflows/deploy.yml
vendored
|
|
@ -1,49 +1,39 @@
|
|||
name: Build and deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Prepare environment
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: "18"
|
||||
- name: Setup Bun
|
||||
uses: oven-sh/setup-bun@v2
|
||||
with:
|
||||
bun-version: "latest"
|
||||
|
||||
- run: npm install --global pnpm
|
||||
- name: Install dependencies
|
||||
run: bun install --frozen-lockfile
|
||||
|
||||
- name: Install deps
|
||||
run: pnpm m i
|
||||
- name: Build plugin(s)
|
||||
run: bun run ./build.mjs
|
||||
|
||||
- name: Build plugin(s)
|
||||
run: node ./build.mjs
|
||||
- name: Copy additional files
|
||||
run: |
|
||||
cp README.md dist/README.md
|
||||
printf -- "---\npermalink: /404.html\n---\n" > dist/404.md
|
||||
printf -- "> **Note:** You accessed a link that returned a 404, probably by clicking one of the plugin links. You're supposed to copy the link address and add it into Vendetta.\n\n" >> dist/404.md
|
||||
cat README.md >> dist/404.md
|
||||
|
||||
# Foolproof feature:
|
||||
# - Copies over README so that the root of the deployed website shows it
|
||||
# - Changes 404 page to README so that you don't get lost while clicking links
|
||||
# If you remove this step then you should probably remove the enable_jekyll option in the next one
|
||||
- name: Copy additional files
|
||||
run: |
|
||||
cp README.md dist/README.md
|
||||
printf -- "---\npermalink: /404.html\n---\n" > dist/404.md
|
||||
printf -- "> **Note:** You accessed a link that returned a 404, probably by clicking one of the plugin links. You're supposed to copy the link address and add it into Vendetta.\n\n" >> dist/404.md
|
||||
cat README.md >> dist/404.md
|
||||
|
||||
# Documentation: https://github.com/peaceiris/actions-gh-pages
|
||||
- name: Deploy to GitHub Pages
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./dist
|
||||
# Makes it so the md files in the previous step get processed by GitHub Pages
|
||||
enable_jekyll: true
|
||||
# This creates the CNAME file required to host GitHub Pages on a custom domain
|
||||
# cname: example.com
|
||||
- name: Deploy to GitHub Pages
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./dist
|
||||
enable_jekyll: true
|
||||
|
|
|
|||
35
package.json
35
package.json
|
|
@ -1,25 +1,25 @@
|
|||
{
|
||||
"scripts": {
|
||||
"build": "node build.mjs",
|
||||
"watch": "node build.mjs -w",
|
||||
"build": "node scripts/build.mjs",
|
||||
"watch": "node scripts/build.mjs -w",
|
||||
"lint": "eslint plugins",
|
||||
"make": "node make.mjs",
|
||||
"serve": "node serve.mjs"
|
||||
"serve": "node scripts/serve.mjs"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^28.0.6",
|
||||
"@rollup/plugin-node-resolve": "^16.0.2",
|
||||
"@swc/core": "^1.13.5",
|
||||
"@types/react": "^18.0.37",
|
||||
"@rollup/plugin-commonjs": "^29.0.0",
|
||||
"@rollup/plugin-node-resolve": "^16.0.3",
|
||||
"@swc/core": "^1.15.1",
|
||||
"@types/react": "^19.2.2",
|
||||
"@types/react-native": "^0.70.13",
|
||||
"@typescript-eslint/eslint-plugin": "^8.45.0",
|
||||
"@typescript-eslint/parser": "^8.45.0",
|
||||
"esbuild": "^0.25.10",
|
||||
"eslint": "^9.37.0",
|
||||
"eslint-plugin-react": "^7.32.2",
|
||||
"rollup": "^4.24.4",
|
||||
"rollup-plugin-esbuild": "^6.1.1",
|
||||
"typescript": "^5.7.2",
|
||||
"@typescript-eslint/eslint-plugin": "^8.46.4",
|
||||
"@typescript-eslint/parser": "^8.46.4",
|
||||
"esbuild": "^0.27.0",
|
||||
"eslint": "^9.39.1",
|
||||
"eslint-plugin-react": "^7.37.5",
|
||||
"rollup": "^4.53.2",
|
||||
"rollup-plugin-esbuild": "^6.2.1",
|
||||
"typescript": "^5.9.3",
|
||||
"vendetta-types": "^2.4.21"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
@ -27,6 +27,7 @@
|
|||
"serve": "^14.2.5"
|
||||
},
|
||||
"overrides": {
|
||||
"@types/react": "^18.0.37"
|
||||
}
|
||||
"@types/react": "^19.2.2"
|
||||
},
|
||||
"packageManager": "bun@1.3.2"
|
||||
}
|
||||
|
|
|
|||
24
plugins/defs.d.ts
vendored
24
plugins/defs.d.ts
vendored
|
|
@ -30,21 +30,25 @@ export type ActivityAssets = {
|
|||
export type ServiceType = "lastfm" | "librefm" | "listenbrainz";
|
||||
|
||||
export type LFMSettings = {
|
||||
appName: string;
|
||||
username: string;
|
||||
apiKey: string;
|
||||
showTimestamp: boolean;
|
||||
timeInterval: number | string;
|
||||
listeningTo: boolean;
|
||||
ignoreSpotify: boolean;
|
||||
ignoreYouTubeMusic: boolean;
|
||||
verboseLogging: boolean;
|
||||
service: ServiceType | undefined;
|
||||
// Service-specific settings
|
||||
librefmUsername?: string;
|
||||
librefmApiKey?: string;
|
||||
listenbrainzUsername?: string;
|
||||
listenbrainzToken?: string;
|
||||
appName: string;
|
||||
username: string;
|
||||
apiKey: string;
|
||||
// Display settings
|
||||
showTimestamp: boolean;
|
||||
timeInterval: number | string;
|
||||
listeningTo: boolean;
|
||||
ignoreSpotify: boolean;
|
||||
showLargeText: boolean;
|
||||
ignoreYouTubeMusic: boolean;
|
||||
// Verbose logging settings
|
||||
verboseLogging: boolean;
|
||||
// Main page
|
||||
service: ServiceType | undefined;
|
||||
};
|
||||
|
||||
export type Track = {
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@ import Settings from "./ui/pages/Settings";
|
|||
import patchSidebar from "./sidebar";
|
||||
|
||||
export const pluginState = {
|
||||
pluginStopped: false,
|
||||
lastActivity: undefined,
|
||||
updateInterval: undefined,
|
||||
lastTrackUrl: undefined,
|
||||
pluginStopped: false,
|
||||
lastActivity: undefined,
|
||||
updateInterval: undefined,
|
||||
lastTrackUrl: undefined,
|
||||
} as {
|
||||
pluginStopped: boolean;
|
||||
lastActivity?: any;
|
||||
|
|
@ -28,20 +28,20 @@ let sidebarUnpatch: (() => void) | undefined;
|
|||
// Set up default plugin settings
|
||||
const defaultSettings: LFMSettings = Constants.DEFAULT_SETTINGS;
|
||||
for (const key of Object.keys(defaultSettings)) {
|
||||
plugin.storage[key] =
|
||||
plugin.storage[key] =
|
||||
plugin.storage[key] ?? defaultSettings[key as keyof typeof defaultSettings];
|
||||
}
|
||||
|
||||
plugin.storage.addToSidebar ??= false;
|
||||
|
||||
export const currentSettings = new Proxy(plugin.storage, {
|
||||
get(target, prop) {
|
||||
return target[prop];
|
||||
},
|
||||
set(target, prop, value) {
|
||||
target[prop] = value;
|
||||
return true;
|
||||
},
|
||||
get(target, prop) {
|
||||
return target[prop];
|
||||
},
|
||||
set(target, prop, value) {
|
||||
target[prop] = value;
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
// Keep track of connection attempts
|
||||
|
|
@ -51,182 +51,182 @@ const RECONNECT_DELAY = 5000;
|
|||
|
||||
const log = (...args: any[]) => console.log("[Scrobble Plugin]", ...args);
|
||||
const logError = (...args: any[]) =>
|
||||
console.error("[Scrobble Plugin] Error:", ...args);
|
||||
console.error("[Scrobble Plugin] Error:", ...args);
|
||||
|
||||
async function tryInitialize() {
|
||||
try {
|
||||
await initialize();
|
||||
connectionAttempts = 0;
|
||||
log("Plugin initialized successfully");
|
||||
} catch (error) {
|
||||
logError("Initialization failed:", error);
|
||||
connectionAttempts++;
|
||||
try {
|
||||
await initialize();
|
||||
connectionAttempts = 0;
|
||||
log("Plugin initialized successfully");
|
||||
} catch (error) {
|
||||
logError("Initialization failed:", error);
|
||||
connectionAttempts++;
|
||||
|
||||
if (connectionAttempts < MAX_CONNECTION_ATTEMPTS) {
|
||||
log(
|
||||
`Retrying connection (${connectionAttempts}/${MAX_CONNECTION_ATTEMPTS})...`,
|
||||
);
|
||||
setTimeout(tryInitialize, RECONNECT_DELAY);
|
||||
} else {
|
||||
logError(`Failed to connect after ${MAX_CONNECTION_ATTEMPTS} attempts`);
|
||||
}
|
||||
if (connectionAttempts < MAX_CONNECTION_ATTEMPTS) {
|
||||
log(
|
||||
`Retrying connection (${connectionAttempts}/${MAX_CONNECTION_ATTEMPTS})...`,
|
||||
);
|
||||
setTimeout(tryInitialize, RECONNECT_DELAY);
|
||||
} else {
|
||||
logError(`Failed to connect after ${MAX_CONNECTION_ATTEMPTS} attempts`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function validateAndInitialize() {
|
||||
// Check if user has selected a service first
|
||||
if (!currentSettings.service) {
|
||||
log("No service selected. Please configure a service in plugin settings.");
|
||||
return;
|
||||
}
|
||||
// Check if user has selected a service first
|
||||
if (!currentSettings.service) {
|
||||
log("No service selected. Please configure a service in plugin settings.");
|
||||
return;
|
||||
}
|
||||
|
||||
const serviceName = serviceFactory.getCurrentService().getServiceName();
|
||||
const serviceName = serviceFactory.getCurrentService().getServiceName();
|
||||
|
||||
// Make sure we have credentials for whatever service is selected
|
||||
const service = currentSettings.service;
|
||||
let hasCredentials = false;
|
||||
// Make sure we have credentials for whatever service is selected
|
||||
const service = currentSettings.service;
|
||||
let hasCredentials = false;
|
||||
|
||||
switch (service) {
|
||||
case "lastfm":
|
||||
hasCredentials = !!(currentSettings.username && currentSettings.apiKey);
|
||||
break;
|
||||
case "librefm":
|
||||
hasCredentials = !!(
|
||||
currentSettings.librefmUsername && currentSettings.librefmApiKey
|
||||
);
|
||||
break;
|
||||
case "listenbrainz":
|
||||
hasCredentials = !!currentSettings.listenbrainzUsername;
|
||||
break;
|
||||
}
|
||||
switch (service) {
|
||||
case "lastfm":
|
||||
hasCredentials = !!(currentSettings.username && currentSettings.apiKey);
|
||||
break;
|
||||
case "librefm":
|
||||
hasCredentials = !!(
|
||||
currentSettings.librefmUsername && currentSettings.librefmApiKey
|
||||
);
|
||||
break;
|
||||
case "listenbrainz":
|
||||
hasCredentials = !!currentSettings.listenbrainzUsername;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!hasCredentials) {
|
||||
logError(
|
||||
`Missing credentials for ${serviceName}. Please configure in plugin settings.`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!hasCredentials) {
|
||||
logError(
|
||||
`Missing credentials for ${serviceName}. Please configure in plugin settings.`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
log(`Starting with ${serviceName}...`);
|
||||
log(`Starting with ${serviceName}...`);
|
||||
|
||||
if (UserStore.getCurrentUser()) {
|
||||
log("Discord is already connected, initializing immediately...");
|
||||
await tryInitialize();
|
||||
} else {
|
||||
log("Waiting for Discord connection...");
|
||||
const waitForUser = () => {
|
||||
if (UserStore.getCurrentUser()) {
|
||||
log("Discord connection established");
|
||||
tryInitialize();
|
||||
FluxDispatcher.unsubscribe("CONNECTION_OPEN", waitForUser);
|
||||
}
|
||||
};
|
||||
if (UserStore.getCurrentUser()) {
|
||||
log("Discord is already connected, initializing immediately...");
|
||||
await tryInitialize();
|
||||
} else {
|
||||
log("Waiting for Discord connection...");
|
||||
const waitForUser = () => {
|
||||
if (UserStore.getCurrentUser()) {
|
||||
log("Discord connection established");
|
||||
tryInitialize();
|
||||
FluxDispatcher.unsubscribe("CONNECTION_OPEN", waitForUser);
|
||||
}
|
||||
};
|
||||
|
||||
FluxDispatcher.subscribe("CONNECTION_OPEN", waitForUser);
|
||||
}
|
||||
FluxDispatcher.subscribe("CONNECTION_OPEN", waitForUser);
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
onLoad() {
|
||||
log("Plugin loading...");
|
||||
pluginState.pluginStopped = false;
|
||||
onLoad() {
|
||||
log("Plugin loading...");
|
||||
pluginState.pluginStopped = false;
|
||||
|
||||
// Check if service is configured
|
||||
if (!currentSettings.service) {
|
||||
log("No service configured. Please select a service in plugin settings.");
|
||||
} else {
|
||||
// Show what we're starting with
|
||||
const serviceName = serviceFactory.getCurrentService().getServiceName();
|
||||
log(
|
||||
`Configuration: Service=${serviceName}, Update Interval=${currentSettings.timeInterval}s, Verbose=${currentSettings.verboseLogging}`,
|
||||
);
|
||||
// Check if service is configured
|
||||
if (!currentSettings.service) {
|
||||
log("No service configured. Please select a service in plugin settings.");
|
||||
} else {
|
||||
// Show what we're starting with
|
||||
const serviceName = serviceFactory.getCurrentService().getServiceName();
|
||||
log(
|
||||
`Configuration: Service=${serviceName}, Update Interval=${currentSettings.timeInterval}s, Verbose=${currentSettings.verboseLogging}`,
|
||||
);
|
||||
}
|
||||
|
||||
// Add to sidebar if user wants it
|
||||
try {
|
||||
sidebarUnpatch = patchSidebar();
|
||||
cleanupFunctions.push(() => {
|
||||
if (sidebarUnpatch) {
|
||||
sidebarUnpatch();
|
||||
sidebarUnpatch = undefined;
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
log("Sidebar setup failed:", error);
|
||||
}
|
||||
|
||||
// Add to sidebar if user wants it
|
||||
validateAndInitialize();
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
log("Plugin unloading...");
|
||||
pluginState.pluginStopped = true;
|
||||
|
||||
// Run all cleanup functions
|
||||
cleanupFunctions.forEach((cleanup) => {
|
||||
try {
|
||||
cleanup();
|
||||
} catch (error) {
|
||||
// ignore cleanup errors
|
||||
}
|
||||
});
|
||||
cleanupFunctions.length = 0;
|
||||
|
||||
stop();
|
||||
log("Plugin unloaded");
|
||||
},
|
||||
|
||||
// When user changes settings
|
||||
async onSettingsUpdate(newSettings: any) {
|
||||
const oldService = currentSettings.service;
|
||||
const newService = newSettings.service;
|
||||
const oldSidebar = currentSettings.addToSidebar;
|
||||
const newSidebar = newSettings.addToSidebar;
|
||||
|
||||
// Apply the new settings
|
||||
Object.assign(currentSettings, newSettings);
|
||||
|
||||
log("Settings updated:", Object.keys(newSettings));
|
||||
|
||||
// Check if sidebar setting changed
|
||||
if (oldSidebar !== newSidebar) {
|
||||
if (newSidebar) {
|
||||
try {
|
||||
sidebarUnpatch = patchSidebar();
|
||||
cleanupFunctions.push(() => {
|
||||
if (sidebarUnpatch) {
|
||||
sidebarUnpatch();
|
||||
sidebarUnpatch = undefined;
|
||||
}
|
||||
});
|
||||
sidebarUnpatch = patchSidebar();
|
||||
log("Sidebar enabled");
|
||||
} catch (error) {
|
||||
log("Sidebar setup failed:", error);
|
||||
log("Failed to enable sidebar:", error);
|
||||
}
|
||||
|
||||
validateAndInitialize();
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
log("Plugin unloading...");
|
||||
pluginState.pluginStopped = true;
|
||||
|
||||
// Run all cleanup functions
|
||||
cleanupFunctions.forEach((cleanup) => {
|
||||
try {
|
||||
cleanup();
|
||||
} catch (error) {
|
||||
// ignore cleanup errors
|
||||
}
|
||||
});
|
||||
cleanupFunctions.length = 0;
|
||||
|
||||
stop();
|
||||
log("Plugin unloaded");
|
||||
},
|
||||
|
||||
// When user changes settings
|
||||
async onSettingsUpdate(newSettings: any) {
|
||||
const oldService = currentSettings.service;
|
||||
const newService = newSettings.service;
|
||||
const oldSidebar = currentSettings.addToSidebar;
|
||||
const newSidebar = newSettings.addToSidebar;
|
||||
|
||||
// Apply the new settings
|
||||
Object.assign(currentSettings, newSettings);
|
||||
|
||||
log("Settings updated:", Object.keys(newSettings));
|
||||
|
||||
// Check if sidebar setting changed
|
||||
if (oldSidebar !== newSidebar) {
|
||||
if (newSidebar) {
|
||||
try {
|
||||
sidebarUnpatch = patchSidebar();
|
||||
log("Sidebar enabled");
|
||||
} catch (error) {
|
||||
log("Failed to enable sidebar:", error);
|
||||
}
|
||||
} else {
|
||||
if (sidebarUnpatch) {
|
||||
sidebarUnpatch();
|
||||
sidebarUnpatch = undefined;
|
||||
log("Sidebar disabled");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (sidebarUnpatch) {
|
||||
sidebarUnpatch();
|
||||
sidebarUnpatch = undefined;
|
||||
log("Sidebar disabled");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Switch services if needed
|
||||
if (oldService !== newService && newService) {
|
||||
log(`Service changed from ${oldService || "none"} to ${newService}`);
|
||||
await switchService(newService);
|
||||
} else if (!pluginState.pluginStopped && currentSettings.service) {
|
||||
// Just restart with the updated settings (only if service is selected)
|
||||
log("Restarting with updated settings...");
|
||||
await tryInitialize();
|
||||
} else if (!currentSettings.service) {
|
||||
// Service was unselected, stop the plugin
|
||||
log("Service unselected, stopping plugin...");
|
||||
stop();
|
||||
}
|
||||
},
|
||||
// Switch services if needed
|
||||
if (oldService !== newService && newService) {
|
||||
log(`Service changed from ${oldService || "none"} to ${newService}`);
|
||||
await switchService(newService);
|
||||
} else if (!pluginState.pluginStopped && currentSettings.service) {
|
||||
// Just restart with the updated settings (only if service is selected)
|
||||
log("Restarting with updated settings...");
|
||||
await tryInitialize();
|
||||
} else if (!currentSettings.service) {
|
||||
// Service was unselected, stop the plugin
|
||||
log("Service unselected, stopping plugin...");
|
||||
stop();
|
||||
}
|
||||
},
|
||||
|
||||
onDiscordReconnect() {
|
||||
if (!pluginState.pluginStopped) {
|
||||
log("Discord reconnected, reinitializing plugin...");
|
||||
tryInitialize();
|
||||
}
|
||||
},
|
||||
onDiscordReconnect() {
|
||||
if (!pluginState.pluginStopped) {
|
||||
log("Discord reconnected, reinitializing plugin...");
|
||||
tryInitialize();
|
||||
}
|
||||
},
|
||||
|
||||
settings: Settings,
|
||||
settings: Settings,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -10,8 +10,12 @@ import Settings from "./ui/pages/Settings";
|
|||
|
||||
const { FormSection, FormRow } = Forms;
|
||||
const { TableRowIcon } = findByProps("TableRowIcon");
|
||||
|
||||
const bunny = window.bunny;
|
||||
declare global {
|
||||
interface Window {
|
||||
bunny: any;
|
||||
}
|
||||
}
|
||||
|
||||
const tabsNavigationRef = bunny?.metro?.findByPropsLazy("getRootNavigationRef");
|
||||
const settingConstants = bunny?.metro?.findByPropsLazy(
|
||||
|
|
@ -141,8 +145,8 @@ function patchTabsUI(tabs, patches) {
|
|||
|
||||
patches.push(
|
||||
after("default", SettingsOverviewScreen, (args, ret) => {
|
||||
if (!args[0][firstRender]) {
|
||||
args[0][firstRender] = true;
|
||||
if (!(args[0] as { [key: symbol]: boolean })[firstRender]) {
|
||||
(args[0] as { [key: symbol]: boolean })[firstRender] = true;
|
||||
|
||||
const { sections } = findInReactTree(
|
||||
ret,
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ export function setDebugInfo(
|
|||
key: keyof typeof debugInfo,
|
||||
value: (typeof debugInfo)[typeof key],
|
||||
) {
|
||||
debugInfo[key] = value;
|
||||
(debugInfo[key] as any) = value;
|
||||
|
||||
// log the important stuff
|
||||
if (key === "lastError" && value) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue