mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-20 00:43:04 +00:00
feat: new blocking progress bar, fixes #18
feat: change cloud icon to history, fixes #15 fix: action search items overlap, fixes #16 feat: show tooltips immediately
This commit is contained in:
39
src/lib/os-layout.ts
Normal file
39
src/lib/os-layout.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import {persistentWritable} from "$lib/storage"
|
||||
import {get} from "svelte/store"
|
||||
|
||||
export const osLayout = persistentWritable<Record<string, string>>("os-layout", {})
|
||||
|
||||
const keysCurrentlyDown = new Set<string>()
|
||||
|
||||
function keydown({code, key}: KeyboardEvent) {
|
||||
const keys = [...keysCurrentlyDown]
|
||||
keysCurrentlyDown.add(code)
|
||||
|
||||
const keyString = JSON.stringify([...keys.sort(), code])
|
||||
if (keyString in get(osLayout) || get(osLayout)[JSON.stringify([code])] === key) return
|
||||
|
||||
osLayout.update(layout => {
|
||||
layout[keyString] = key
|
||||
return layout
|
||||
})
|
||||
}
|
||||
|
||||
function keyup({code}: KeyboardEvent) {
|
||||
keysCurrentlyDown.delete(code)
|
||||
}
|
||||
|
||||
export function runLayoutDetection() {
|
||||
if ("keyboard" in navigator) {
|
||||
;(navigator.keyboard as any).getLayoutMap().then((layout: Map<string, string>) => {
|
||||
osLayout.update(osLayout => {
|
||||
Object.assign(
|
||||
osLayout,
|
||||
Object.fromEntries([...layout.entries()].map(([key, value]) => [JSON.stringify([key]), value])),
|
||||
)
|
||||
return osLayout
|
||||
})
|
||||
})
|
||||
}
|
||||
window.addEventListener("keydown", keydown)
|
||||
window.addEventListener("keyup", keyup)
|
||||
}
|
||||
Reference in New Issue
Block a user