mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-09 06:12:56 +00:00
Merge pull request #2218 from PR0M3TH3AN/refactor-application-srp-12044709703939300356
🧹 Refactor Application to use AuthService and PlaybackService for state access
This commit is contained in:
5 files changed
+101
-47
No files matched your search
@@ -139,22 +139,10 @@ import {
|
||||
import { getDesignSystemMode as getCanonicalDesignSystemMode } from "./designSystem.js";
|
||||
import { getHashViewName, setHashView } from "./hashView.js";
|
||||
import {
|
||||
getPubkey as getStoredPubkey,
|
||||
setPubkey as setStoredPubkey,
|
||||
getCurrentUserNpub as getStoredCurrentUserNpub,
|
||||
setCurrentUserNpub as setStoredCurrentUserNpub,
|
||||
getCurrentVideo as getStoredCurrentVideo,
|
||||
setCurrentVideo as setStoredCurrentVideo,
|
||||
setModalState as setGlobalModalState,
|
||||
subscribeToAppStateKey,
|
||||
} from "./state/appState.js";
|
||||
import {
|
||||
getSavedProfiles,
|
||||
getActiveProfilePubkey,
|
||||
setActiveProfilePubkey as setStoredActiveProfilePubkey,
|
||||
setSavedProfiles,
|
||||
persistSavedProfiles,
|
||||
getProfileCacheMap,
|
||||
getCachedUrlHealth as readCachedUrlHealth,
|
||||
storeUrlHealth as persistUrlHealth,
|
||||
setInFlightUrlProbe,
|
||||
@@ -212,35 +200,43 @@ const RELAY_UI_BATCH_DELAY_MS = 250;
|
||||
*/
|
||||
class Application {
|
||||
get pubkey() {
|
||||
return getStoredPubkey();
|
||||
return this.authService.pubkey;
|
||||
}
|
||||
|
||||
set pubkey(value) {
|
||||
setStoredPubkey(value ?? null);
|
||||
this.authService.pubkey = value;
|
||||
}
|
||||
|
||||
get currentUserNpub() {
|
||||
return getStoredCurrentUserNpub();
|
||||
return this.authService.currentUserNpub;
|
||||
}
|
||||
|
||||
set currentUserNpub(value) {
|
||||
setStoredCurrentUserNpub(value ?? null);
|
||||
this.authService.currentUserNpub = value;
|
||||
}
|
||||
|
||||
get currentVideo() {
|
||||
return getStoredCurrentVideo();
|
||||
return this.playbackService.currentVideo;
|
||||
}
|
||||
|
||||
set currentVideo(value) {
|
||||
setStoredCurrentVideo(value ?? null);
|
||||
this.playbackService.currentVideo = value;
|
||||
}
|
||||
|
||||
get activeProfilePubkey() {
|
||||
return getActiveProfilePubkey();
|
||||
return this.authService.activeProfilePubkey;
|
||||
}
|
||||
|
||||
set activeProfilePubkey(value) {
|
||||
this.authService.setActiveProfilePubkey(value, { persist: false });
|
||||
}
|
||||
|
||||
get savedProfiles() {
|
||||
return getSavedProfiles();
|
||||
return this.authService.savedProfiles;
|
||||
}
|
||||
|
||||
set savedProfiles(value) {
|
||||
this.authService.setSavedProfiles(value, { persist: false, persistActive: false });
|
||||
}
|
||||
|
||||
constructor({ services = {}, ui = {}, helpers = {}, loadView: viewLoader } = {}) {
|
||||
@@ -604,7 +600,7 @@ class Application {
|
||||
queueSignEvent,
|
||||
bootstrapTrustedSeeds,
|
||||
getModerationSettings,
|
||||
getActiveProfilePubkey,
|
||||
getActiveProfilePubkey: () => this.authService.activeProfilePubkey,
|
||||
})),
|
||||
writable: true,
|
||||
configurable: true,
|
||||
@@ -689,7 +685,7 @@ class Application {
|
||||
}
|
||||
|
||||
persistActiveProfileSelection(pubkey, { persist = true } = {}) {
|
||||
setStoredActiveProfilePubkey(pubkey, { persist });
|
||||
this.authService.setActiveProfilePubkey(pubkey, { persist });
|
||||
this.renderSavedProfiles();
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import { userLogger } from "../utils/logger.js";
|
||||
import { requestDefaultExtensionPermissions } from "../nostr/defaultClient.js";
|
||||
import {
|
||||
getSavedProfiles,
|
||||
setSavedProfiles,
|
||||
getActiveProfilePubkey,
|
||||
setActiveProfilePubkey,
|
||||
mutateSavedProfiles,
|
||||
@@ -417,6 +418,38 @@ export default class AuthService {
|
||||
return publish(payload);
|
||||
}
|
||||
|
||||
get pubkey() {
|
||||
return getPubkey();
|
||||
}
|
||||
|
||||
set pubkey(value) {
|
||||
setPubkey(value ?? null);
|
||||
}
|
||||
|
||||
get currentUserNpub() {
|
||||
return getCurrentUserNpub();
|
||||
}
|
||||
|
||||
set currentUserNpub(value) {
|
||||
setCurrentUserNpub(value ?? null);
|
||||
}
|
||||
|
||||
get activeProfilePubkey() {
|
||||
return getActiveProfilePubkey();
|
||||
}
|
||||
|
||||
setActiveProfilePubkey(pubkey, options = {}) {
|
||||
return setActiveProfilePubkey(pubkey, options);
|
||||
}
|
||||
|
||||
get savedProfiles() {
|
||||
return getSavedProfiles();
|
||||
}
|
||||
|
||||
setSavedProfiles(profiles, options = {}) {
|
||||
return setSavedProfiles(profiles, options);
|
||||
}
|
||||
|
||||
getActivePubkey() {
|
||||
return getPubkey();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { userLogger } from "../utils/logger.js";
|
||||
import { safeDecodeURIComponent } from "../utils/safeDecode.js";
|
||||
import { PLAYBACK_START_TIMEOUT } from "../constants.js";
|
||||
import { getCurrentVideo, setCurrentVideo } from "../state/appState.js";
|
||||
// js/services/playbackService.js
|
||||
|
||||
/**
|
||||
@@ -285,6 +286,14 @@ export class PlaybackService {
|
||||
this.probeCacheTtlMs = PROBE_CACHE_TTL_MS;
|
||||
}
|
||||
|
||||
get currentVideo() {
|
||||
return getCurrentVideo();
|
||||
}
|
||||
|
||||
set currentVideo(value) {
|
||||
setCurrentVideo(value);
|
||||
}
|
||||
|
||||
log(...args) {
|
||||
try {
|
||||
this.logger(...args);
|
||||
|
||||
@@ -867,31 +867,6 @@ export default class ApplicationBootstrap {
|
||||
}
|
||||
};
|
||||
app.boundNwcSettingsToastHandler = null;
|
||||
Object.defineProperty(app, "savedProfiles", {
|
||||
configurable: false,
|
||||
enumerable: false,
|
||||
get() {
|
||||
return getSavedProfiles();
|
||||
},
|
||||
set(next) {
|
||||
setSavedProfiles(Array.isArray(next) ? next : [], {
|
||||
persist: false,
|
||||
persistActive: false,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(app, "activeProfilePubkey", {
|
||||
configurable: false,
|
||||
enumerable: false,
|
||||
get() {
|
||||
return getActiveProfilePubkey();
|
||||
},
|
||||
set(value) {
|
||||
setStoredActiveProfilePubkey(value, { persist: false });
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(app, "profileCache", {
|
||||
configurable: false,
|
||||
enumerable: false,
|
||||
|
||||
@@ -203,6 +203,47 @@ export async function createModerationAppHarness(options = {}) {
|
||||
const Application = await getApplicationClass();
|
||||
const app = Object.create(Application.prototype);
|
||||
|
||||
app.playbackService = {
|
||||
_currentVideo: null,
|
||||
get currentVideo() {
|
||||
return this._currentVideo;
|
||||
},
|
||||
set currentVideo(value) {
|
||||
this._currentVideo = value;
|
||||
},
|
||||
};
|
||||
|
||||
app.authService = {
|
||||
_pubkey: null,
|
||||
_currentUserNpub: null,
|
||||
_activeProfilePubkey: null,
|
||||
_savedProfiles: [],
|
||||
get pubkey() {
|
||||
return this._pubkey;
|
||||
},
|
||||
set pubkey(value) {
|
||||
this._pubkey = value;
|
||||
},
|
||||
get currentUserNpub() {
|
||||
return this._currentUserNpub;
|
||||
},
|
||||
set currentUserNpub(value) {
|
||||
this._currentUserNpub = value;
|
||||
},
|
||||
get activeProfilePubkey() {
|
||||
return this._activeProfilePubkey;
|
||||
},
|
||||
setActiveProfilePubkey(value) {
|
||||
this._activeProfilePubkey = value;
|
||||
},
|
||||
get savedProfiles() {
|
||||
return this._savedProfiles;
|
||||
},
|
||||
setSavedProfiles(value) {
|
||||
this._savedProfiles = value;
|
||||
},
|
||||
};
|
||||
|
||||
Object.defineProperty(app, "__profiles", {
|
||||
value: new Map(),
|
||||
writable: true,
|
||||
|
||||
Reference in new issue
Block a user