2021-10-28 00:05:56 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-03-14 15:55:31 +00:00
|
|
|
type InteractionModeType = 'mouse' | 'keyboard';
|
|
|
|
|
2021-10-28 00:05:56 +00:00
|
|
|
let initialized = false;
|
2023-03-14 15:55:31 +00:00
|
|
|
let interactionMode: InteractionModeType = 'mouse';
|
2021-10-28 00:05:56 +00:00
|
|
|
|
|
|
|
export function startInteractionMode(): void {
|
|
|
|
if (initialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
initialized = true;
|
|
|
|
|
|
|
|
document.body.classList.add('mouse-mode');
|
|
|
|
|
|
|
|
window.enterKeyboardMode = () => {
|
|
|
|
if (interactionMode === 'keyboard') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
interactionMode = 'keyboard';
|
|
|
|
|
|
|
|
document.body.classList.add('keyboard-mode');
|
|
|
|
document.body.classList.remove('mouse-mode');
|
|
|
|
|
2023-03-20 22:23:53 +00:00
|
|
|
const clearTargetedMessage =
|
|
|
|
window.reduxActions?.conversations?.clearTargetedMessage;
|
|
|
|
if (clearTargetedMessage) {
|
|
|
|
clearTargetedMessage();
|
2021-10-28 00:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const userChanged = window.reduxActions?.user?.userChanged;
|
|
|
|
if (userChanged) {
|
|
|
|
userChanged({ interactionMode });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
window.enterMouseMode = () => {
|
|
|
|
if (interactionMode === 'mouse') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
interactionMode = 'mouse';
|
|
|
|
|
|
|
|
document.body.classList.add('mouse-mode');
|
|
|
|
document.body.classList.remove('keyboard-mode');
|
|
|
|
|
2023-03-20 22:23:53 +00:00
|
|
|
const clearTargetedMessage =
|
|
|
|
window.reduxActions?.conversations?.clearTargetedMessage;
|
|
|
|
if (clearTargetedMessage) {
|
|
|
|
clearTargetedMessage();
|
2021-10-28 00:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const userChanged = window.reduxActions?.user?.userChanged;
|
|
|
|
if (userChanged) {
|
|
|
|
userChanged({ interactionMode });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
document.addEventListener(
|
|
|
|
'keydown',
|
|
|
|
event => {
|
|
|
|
if (event.key === 'Tab') {
|
|
|
|
window.enterKeyboardMode();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
true
|
|
|
|
);
|
|
|
|
document.addEventListener('wheel', window.enterMouseMode, true);
|
|
|
|
document.addEventListener('mousedown', window.enterMouseMode, true);
|
2023-03-14 15:55:31 +00:00
|
|
|
}
|
2021-10-28 00:05:56 +00:00
|
|
|
|
2023-03-14 15:55:31 +00:00
|
|
|
export function getInteractionMode(): InteractionModeType {
|
|
|
|
return interactionMode;
|
2021-10-28 00:05:56 +00:00
|
|
|
}
|