Skip to content

Commit

Permalink
fix round NVUI - closes #13077
Browse files Browse the repository at this point in the history
very, very dirty garbage, to get a hotfix online ASAP.
Please make it better!
  • Loading branch information
ornicar committed Jun 23, 2023
1 parent b3ae8fd commit 684bfce
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
5 changes: 3 additions & 2 deletions ui/nvui/src/notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () =>
Expand Down
1 change: 1 addition & 0 deletions ui/round/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
2 changes: 2 additions & 0 deletions ui/round/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,6 +17,7 @@ export interface NvuiPlugin {
playPremove: (ctrl: RoundController) => void;
premoveInput: string;
render(ctrl: RoundController): VNode;
setRedraw(redraw: Redraw): void;
}

export interface SocketOpts {
Expand Down
8 changes: 5 additions & 3 deletions ui/round/src/plugins/nvui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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!;
Expand Down

0 comments on commit 684bfce

Please sign in to comment.