feat(debug): add ability to debug view iframes, done #10

This commit is contained in:
Falcion 2025-04-14 19:44:19 +03:00
parent 8ee6bb2ea9
commit 6ce9d30cee
7 changed files with 46 additions and 5 deletions

View file

@ -3,7 +3,6 @@ .vault-ambience-player {
bottom: 10px;
right: 10px;
z-index: 1000;
display: none;
}
.file-ambience-player {
@ -11,7 +10,6 @@ .file-ambience-player {
bottom: 10px;
right: 10px;
z-index: 1000;
display: none;
}
.input-field {

View file

@ -141,6 +141,21 @@ export default class Whisperer extends Plugin {
}
}
async updateVisibleSettings(settings: WHISPERER_SETTINGS): Promise<void> {
if (this.players.length === 0) {
this.updateSettings(settings)
} else {
this._settings = settings
await this.saveData(this.settings)
this.players.forEach((player) => {
player.removeClass(this.settings.debug_frames ? 'hidden-frame' : 'visible')
player.addClass(this.settings.debug_frames ? 'visible' : 'hidden-frame')
})
}
}
public unapply(): void {
this.players.forEach((player) => {
player.remove()

View file

@ -60,7 +60,7 @@ export default class PlayerPerFile {
iframe.width = '300'
iframe.height = '166'
iframe.allow = 'autoplay'
iframe.addClass('hidden-frame')
iframe.addClass(this.plugin.settings.debug_frames ? 'visible' : 'hidden-frame')
player.appendChild(iframe)
} else if (musicPath.includes('soundcloud.com')) {
const embedUrl = getEmbedUrl(musicPath)
@ -69,7 +69,7 @@ export default class PlayerPerFile {
iframe.width = '300'
iframe.height = '166'
iframe.allow = 'autoplay'
iframe.addClass('hidden-frame')
iframe.addClass(this.plugin.settings.debug_frames ? 'visible' : 'hidden-frame')
player.appendChild(iframe)
}
} else {

View file

@ -22,6 +22,7 @@ export default class PlayerPerGlobal {
player = document.createElement('div')
player.className = 'vault-ambience-player'
player.addClass(this.plugin.settings.debug_frames ? 'visible' : 'hidden-frame')
if (isUrl(this.plugin.settings.vault_ambience_path)) {
if (

View file

@ -50,7 +50,7 @@ export default class WhispererSettingsTab extends PluginSettingTab {
settingsConstructor.SETTING_VAULT_PATH_INPUT,
settingsConstructor.SETTING_AMBIENCE_PER_FILE,
settingsConstructor.SETTING_AMBIENCE_PER_FILE_COMMENT,
settingsConstructor.SETTING_MUSIC_VOLUME
settingsConstructor.SETTING_DEBUG_FRAMES
]
SettingsConstructor.updateDisplays(

View file

@ -4,6 +4,8 @@ export interface WHISPERER_SETTINGS {
ambience_per_files: boolean
music_volume: number
debug_frames: boolean
MIN_VOLUME: number
MAX_VOLUME: number
VOLUME_STEP: number
@ -15,6 +17,8 @@ export const DEFAULT_SETTINGS: WHISPERER_SETTINGS = {
ambience_per_files: true,
music_volume: 50,
debug_frames: false,
MIN_VOLUME: 0,
MAX_VOLUME: 100,
VOLUME_STEP: 1

View file

@ -14,6 +14,7 @@ export default class SettingsConstructor {
private _SETTING_AMBIENCE_PER_FILE?: Setting
private _SETTING_AMBIENCE_PER_FILE_COMMENT?: Setting
private _SETTING_MUSICE_VOLUME?: Setting
private _SETTING_DEBUG_FRAMES?: Setting
public plugin: Whisperer
public containerEl: HTMLElement
@ -152,6 +153,28 @@ export default class SettingsConstructor {
return this._SETTING_MUSICE_VOLUME!
}
public get SETTING_DEBUG_FRAMES(): Setting {
if (!this._SETTING_DEBUG_FRAMES) {
this._SETTING_DEBUG_FRAMES = new Setting(this.containerEl)
.setName('Debug frames:')
.setDesc(
'Allows you to view frames generated by this plugin, meaning you can view mini-players for music/video.'
)
.addToggle((toggle) => {
toggle.setValue(this.plugin.settings.debug_frames).onChange(async (value) => {
const next = {
...this.plugin.settings,
debug_frames: value
}
await this.plugin.updateSettings(next)
})
})
}
return this._SETTING_DEBUG_FRAMES!
}
public static updateDisplays(elements: (Setting | TextAreaComponent)[], values: boolean[]): void {
if (elements.length !== values.length)
throw new Error('Elements and their values both are out of range in some other ways.')