New full screen chat WIP + code refactoring.

This commit is contained in:
John Livingston
2024-01-08 11:56:44 +01:00
parent 22a675e915
commit e04d553d0b
10 changed files with 74 additions and 15 deletions

View File

@ -1,5 +1,5 @@
import type { SVGButton } from './buttons'
import { logger } from './logger'
import { logger } from '../utils/logger'
interface displayButtonOptionsBase {
buttonContainer: HTMLElement

View File

@ -1,46 +0,0 @@
import { logger } from './logger'
import { AutoColors, areAutoColorsValid } from 'shared/lib/autocolors'
function computeAutoColors (): AutoColors | null {
if (!window.getComputedStyle) {
logger.warn('[AutoColors] getComputedStyle is not available, aborting.')
return null
}
const styles = window.getComputedStyle(document.body)
// Peertube has no CSS variable for the button color...
// Computing by hand.
// Searching for one of these button:
const button = document.querySelector('.publish-button') ?? document.querySelector('.peertube-button-link')
if (!button) {
logger.warn('[AutoColors] Cant find a button, aborting.')
return null
}
const buttonStyles = window.getComputedStyle(button)
const autocolors: AutoColors = {
mainForeground: styles.getPropertyValue('--mainForegroundColor').trim(),
mainBackground: styles.getPropertyValue('--mainBackgroundColor').trim(),
greyForeground: styles.getPropertyValue('--greyForegroundColor').trim(),
greyBackground: styles.getPropertyValue('--greyBackgroundColor').trim(),
menuForeground: styles.getPropertyValue('--menuForegroundColor').trim(),
menuBackground: styles.getPropertyValue('--menuBackgroundColor').trim(),
inputForeground: styles.getPropertyValue('--inputForegroundColor').trim(),
inputBackground: styles.getPropertyValue('--inputBackgroundColor').trim(),
buttonForeground: buttonStyles.color.trim(),
buttonBackground: styles.getPropertyValue('--mainColor').trim(),
link: styles.getPropertyValue('--mainForegroundColor').trim(),
linkHover: styles.getPropertyValue('--mainForegroundColor').trim()
}
const autoColorsTest = areAutoColorsValid(autocolors)
if (autoColorsTest !== true) {
logger.warn('[AutoColors] Computed colors are not valid, dropping. Invalid values: ' + autoColorsTest.join(', '))
return null
}
return autocolors
}
export {
computeAutoColors
}

View File

@ -1,10 +0,0 @@
const logger = {
log: (s: string) => console.log('[peertube-plugin-livechat] ' + s),
info: (s: string) => console.info('[peertube-plugin-livechat] ' + s),
error: (s: string) => console.error('[peertube-plugin-livechat] ' + s),
warn: (s: string) => console.warn('[peertube-plugin-livechat] ' + s)
}
export {
logger
}

View File

@ -1,7 +1,7 @@
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
import type { Video } from '@peertube/peertube-types'
import { helpButtonSVG } from './buttons'
import { logger } from './logger'
import { logger } from '../utils/logger'
import { getIframeUri, getXMPPAddr, UriOptions } from './uri'
import { isAutoColorsAvailable } from 'shared/lib/autocolors'
import { localizedHelpUrl } from '../utils/help'

View File

@ -2,8 +2,8 @@ import type { RegisterClientOptions } from '@peertube/peertube-types/client'
import type { Video } from '@peertube/peertube-types'
import { AutoColors, isAutoColorsAvailable } from 'shared/lib/autocolors'
import { getBaseRoute } from '../utils/uri'
import { logger } from './logger'
import { computeAutoColors } from './colors'
import { logger } from '../utils/logger'
import { computeAutoColors } from '../utils/colors'
interface UriOptions {
readonly?: boolean | 'noscroll'