diff --git a/ui/nvui/src/notify.ts b/ui/nvui/src/notify.ts index 41f1ed4833dc..7ff651d4e964 100644 --- a/ui/nvui/src/notify.ts +++ b/ui/nvui/src/notify.ts @@ -7,14 +7,15 @@ type Notification = { export class Notify { notification: Notification | undefined; + redraw?: () => void; - constructor(readonly redraw: () => void, readonly timeout: number = 3000) {} + constructor(readonly timeout: number = 3000) {} set = (msg: string) => { // make sure it's different from previous, so it gets read again if (this.notification && this.notification.text == msg) msg += ' '; this.notification = { text: msg, date: new Date() }; - lichess.requestIdleCallback(this.redraw, 500); + lichess.requestIdleCallback(() => this.redraw && this.redraw(), 500); }; currentText = () => diff --git a/ui/round/src/ctrl.ts b/ui/round/src/ctrl.ts index 207a2a50ebb8..742e7a993bfe 100644 --- a/ui/round/src/ctrl.ts +++ b/ui/round/src/ctrl.ts @@ -109,6 +109,7 @@ export default class RoundController { }, 3000); this.socket = makeSocket(opts.socketSend, this); + this.nvui?.setRedraw(redraw); if (d.clock) this.clock = new ClockController(d, { diff --git a/ui/round/src/interfaces.ts b/ui/round/src/interfaces.ts index ba87f2d83c16..0c56ceadd606 100644 --- a/ui/round/src/interfaces.ts +++ b/ui/round/src/interfaces.ts @@ -6,6 +6,7 @@ import RoundController from './ctrl'; import { ChatCtrl, ChatPlugin } from 'chat'; import * as cg from 'chessground/types'; import * as Prefs from 'common/prefs'; +import { Redraw } from 'common/snabbdom'; export interface Untyped { [key: string]: any; @@ -16,6 +17,7 @@ export interface NvuiPlugin { playPremove: (ctrl: RoundController) => void; premoveInput: string; render(ctrl: RoundController): VNode; + setRedraw(redraw: Redraw): void; } export interface SocketOpts { diff --git a/ui/round/src/plugins/nvui.ts b/ui/round/src/plugins/nvui.ts index d9efd8061cc3..ef20442c05e0 100644 --- a/ui/round/src/plugins/nvui.ts +++ b/ui/round/src/plugins/nvui.ts @@ -35,15 +35,14 @@ import { renderSetting } from 'nvui/setting'; import { Notify } from 'nvui/notify'; import { commands } from 'nvui/command'; import { throttled } from '../sound'; -import { Redraw } from 'common/snabbdom'; const selectSound = throttled('select'); const borderSound = throttled('outOfBound'); const errorSound = throttled('error'); // esbuild -export function initModule(redraw: Redraw): NvuiPlugin { - const notify = new Notify(redraw), +export function initModule(): NvuiPlugin { + const notify = new Notify(), moveStyle = styleSetting(), prefixStyle = prefixSetting(), pieceStyle = pieceSetting(), @@ -56,6 +55,9 @@ export function initModule(redraw: Redraw): NvuiPlugin { lichess.pubsub.on('round.suggestion', notify.set); return { + setRedraw(redraw) { + notify.redraw = redraw; + }, premoveInput: '', playPremove(ctrl: RoundController) { const nvui = ctrl.nvui!;