Skip to content

Commit

Permalink
Run Keyboard Layout Map Func to Detect Physical Keyboard Presence
Browse files Browse the repository at this point in the history
  • Loading branch information
itsonlyjames committed Oct 23, 2024
1 parent 16c8552 commit 65dad25
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
QuickOpenSettingTab,
} from "./settings";
import {
canInjectFunctionality,
addModalStyles,
removeModalStyles,
isAppWindow,
isKeyboardPresent,
} from "./utils";

export default class QuickOpen extends Plugin {
Expand Down Expand Up @@ -144,11 +144,11 @@ export default class QuickOpen extends Plugin {
}
}

handleNewModal(modalElement: HTMLElement) {
async handleNewModal(modalElement: HTMLElement) {
const resultsContainer = modalElement.querySelector(
".suggestion, .prompt-results",
);
if (resultsContainer && canInjectFunctionality()) {
if (resultsContainer && (await isKeyboardPresent())) {
this.activeModal = modalElement;
this.injectFunctionality(resultsContainer);
addModalStyles(modalElement.ownerDocument);
Expand Down
6 changes: 0 additions & 6 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,3 @@ declare module "obsidian" {
};
}
}

interface NavigatorKeyboard extends Navigator {
keyboard?: {
lock: () => Promise<void>;
};
}
10 changes: 4 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { AppWindow } from "./types";

export const canInjectFunctionality = () => {
const userAgent = navigator.userAgent;

if (/Android|iPhone|iPod/.test(userAgent)) return false;

return true;
export const isKeyboardPresent = async () => {
// @ts-ignore
const keyboardLayout = await navigator.keyboard.getLayoutMap();
return keyboardLayout && keyboardLayout.size > 0;
};

export const addModalStyles = (doc: Document) => {
Expand Down

0 comments on commit 65dad25

Please sign in to comment.