vjs: hide errors when updating i18n
## Issue 6989 console errors and warnings are getting out of hand! ## Notes This method was previously criticized in 5643. But given that no better solution has been submitted after a long while, nor is there a new solution for doing i18n, I'm reviving it again. It'll be no worse from the status quo. Despite try-catch being overkill, I think the code-clarity outweighs the performance issues (if any, in the first place). Also, we are only suppressing the error in a very specialized function which even if it fails, will simply be a no-op and the GUI falling back to English.
This commit is contained in:
parent
72cceac943
commit
18fb0147de
1 changed files with 43 additions and 38 deletions
|
@ -296,44 +296,49 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||||
// as the listener to update static texts.
|
// as the listener to update static texts.
|
||||||
const player = playerRef.current;
|
const player = playerRef.current;
|
||||||
if (player) {
|
if (player) {
|
||||||
const controlBar = player.getChild('controlBar');
|
try {
|
||||||
switch (e.type) {
|
const controlBar = player.getChild('controlBar');
|
||||||
case 'play':
|
switch (e.type) {
|
||||||
controlBar.getChild('PlayToggle').controlText(__('Pause (space)'));
|
case 'play':
|
||||||
break;
|
controlBar.getChild('PlayToggle').controlText(__('Pause (space)'));
|
||||||
case 'pause':
|
break;
|
||||||
controlBar.getChild('PlayToggle').controlText(__('Play (space)'));
|
case 'pause':
|
||||||
break;
|
controlBar.getChild('PlayToggle').controlText(__('Play (space)'));
|
||||||
case 'volumechange':
|
break;
|
||||||
controlBar
|
case 'volumechange':
|
||||||
.getChild('VolumePanel')
|
controlBar
|
||||||
.getChild('MuteToggle')
|
.getChild('VolumePanel')
|
||||||
.controlText(player.muted() || player.volume() === 0 ? __('Unmute (m)') : __('Mute (m)'));
|
.getChild('MuteToggle')
|
||||||
break;
|
.controlText(player.muted() || player.volume() === 0 ? __('Unmute (m)') : __('Mute (m)'));
|
||||||
case 'fullscreenchange':
|
break;
|
||||||
controlBar
|
case 'fullscreenchange':
|
||||||
.getChild('FullscreenToggle')
|
controlBar
|
||||||
.controlText(player.isFullscreen() ? __('Exit Fullscreen (f)') : __('Fullscreen (f)'));
|
.getChild('FullscreenToggle')
|
||||||
break;
|
.controlText(player.isFullscreen() ? __('Exit Fullscreen (f)') : __('Fullscreen (f)'));
|
||||||
case 'loadstart':
|
break;
|
||||||
// --- Do everything ---
|
case 'loadstart':
|
||||||
controlBar.getChild('PlaybackRateMenuButton').controlText(__('Playback Rate (<, >)'));
|
// --- Do everything ---
|
||||||
controlBar.getChild('QualityButton').controlText(__('Quality'));
|
controlBar.getChild('PlaybackRateMenuButton').controlText(__('Playback Rate (<, >)'));
|
||||||
resolveCtrlText({ type: 'play' });
|
controlBar.getChild('QualityButton').controlText(__('Quality'));
|
||||||
resolveCtrlText({ type: 'pause' });
|
resolveCtrlText({ type: 'play' });
|
||||||
resolveCtrlText({ type: 'volumechange' });
|
resolveCtrlText({ type: 'pause' });
|
||||||
resolveCtrlText({ type: 'fullscreenchange' });
|
resolveCtrlText({ type: 'volumechange' });
|
||||||
// (1) The 'Theater mode' button should probably be changed to a class
|
resolveCtrlText({ type: 'fullscreenchange' });
|
||||||
// so that we can use getChild() with a specific name. There might be
|
// (1) The 'Theater mode' button should probably be changed to a class
|
||||||
// clashes if we add a new button in the future.
|
// so that we can use getChild() with a specific name. There might be
|
||||||
// (2) We'll have to get 'makeSelectClientSetting(SETTINGS.VIDEO_THEATER_MODE)'
|
// clashes if we add a new button in the future.
|
||||||
// as a prop here so we can say "Theater mode|Default mode" instead of
|
// (2) We'll have to get 'makeSelectClientSetting(SETTINGS.VIDEO_THEATER_MODE)'
|
||||||
// "Toggle Theater mode".
|
// as a prop here so we can say "Theater mode|Default mode" instead of
|
||||||
controlBar.getChild('Button').controlText(__('Toggle Theater mode (t)'));
|
// "Toggle Theater mode".
|
||||||
break;
|
controlBar.getChild('Button').controlText(__('Toggle Theater mode (t)'));
|
||||||
default:
|
break;
|
||||||
if (isDev) throw Error('Unexpected: ' + e.type);
|
default:
|
||||||
break;
|
if (isDev) throw Error('Unexpected: ' + e.type);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Just fail silently. It'll just be due to hidden ctrls, and if it is
|
||||||
|
// due to control hierarchy change, we'll notice that in the GUI.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue