mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 17:11:17 -08:00
fix(console): stop the paste-scam warning firing on every mobile keyboard
This commit is contained in:
2 files changed
+50
No files matched your search
@@ -0,0 +1,44 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { installConsolePasteScamWarning } from './consolePasteScamWarning';
|
||||
|
||||
const isMobileTauri = vi.hoisted(() => vi.fn<() => boolean>());
|
||||
|
||||
vi.mock('./platform', () => ({ isMobileTauri }));
|
||||
|
||||
describe('installConsolePasteScamWarning', () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
vi.clearAllMocks();
|
||||
window.innerWidth = 800;
|
||||
window.outerWidth = 800;
|
||||
window.innerHeight = 400;
|
||||
// A soft keyboard shrinks the viewport by far more than the 160px threshold.
|
||||
window.outerHeight = 900;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('stays silent on a phone, where the keyboard looks like docked devtools', () => {
|
||||
isMobileTauri.mockReturnValue(true);
|
||||
const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
|
||||
|
||||
installConsolePasteScamWarning();
|
||||
vi.advanceTimersByTime(2000);
|
||||
|
||||
expect(warn).not.toHaveBeenCalled();
|
||||
warn.mockRestore();
|
||||
});
|
||||
|
||||
it('still warns on desktop when devtools look docked', () => {
|
||||
isMobileTauri.mockReturnValue(false);
|
||||
const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
|
||||
|
||||
installConsolePasteScamWarning();
|
||||
vi.advanceTimersByTime(2000);
|
||||
|
||||
expect(warn).toHaveBeenCalled();
|
||||
warn.mockRestore();
|
||||
});
|
||||
});
|
||||
@@ -1,3 +1,5 @@
|
||||
import { isMobileTauri } from './platform';
|
||||
|
||||
// This is probably not very accurate, but doesn't really matter I suppose
|
||||
function isDockedDevtoolsLikely(): boolean {
|
||||
const gapW = window.outerWidth - window.innerWidth;
|
||||
@@ -7,6 +9,10 @@ function isDockedDevtoolsLikely(): boolean {
|
||||
}
|
||||
|
||||
export function installConsolePasteScamWarning(): void {
|
||||
// A phone has no docked devtools, and the soft keyboard moves the viewport far enough
|
||||
// to look exactly like one opening.
|
||||
if (isMobileTauri()) return;
|
||||
|
||||
const BANNER_STYLE =
|
||||
'font-size:56px;font-weight:900;color:#ff0033;background:#1a0006;padding:16px 24px;border:6px solid #ff0033;line-height:1.1;';
|
||||
const BODY_STYLE =
|
||||
|
||||
Reference in new issue
Block a user