Skip to content

Commit

Permalink
More correctly show platform-localized super keys
Browse files Browse the repository at this point in the history
  • Loading branch information
obra committed Feb 26, 2024
1 parent 7573cb5 commit ba10887
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/api/focus/keymap/db/gui.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
const GuiLabels = {
linux: { full: "Super", "1u": "Sup.", short: "Su" },
win32: { full: "Windows", "1u": "Win", short: "W" },
darwin: { full: "Command", "1u": "Cmd", short: "Cm" },
win32: { full: "Windows", "1u": "Win", short: "" },
darwin: { full: "Command", "1u": "Cmd", short: "" },
default: { full: "Gui", "1u": "Gui", short: "G" },
};
export const GuiLabel = GuiLabels.default; // TODO: GuiLabels[process.platform] || GuiLabels.default;

const getPlatformLabels = () => {
const platform = navigator.platform.toLowerCase();
const macosPrefix = "mac";
const windowsPrefixes = ["win"];
const iosPrefixes = ["iphone", "ipad", "ipod"];
const linuxPrefix = "linux";
const androidPrefix = "android";

if (platform.startsWith(macosPrefix)) {
return GuiLabels.darwin;
} else if (iosPrefixes.some((prefix) => platform.startsWith(prefix))) {
return GuiLabels.darwin;
} else if (windowsPrefixes.some((prefix) => platform.startsWith(prefix))) {
return GuiLabels.win32;
} else if (platform.startsWith(androidPrefix)) {
return GuiLabels.default;
} else if (platform.startsWith(linuxPrefix)) {
return GuiLabels.linux;
} else {
return GuiLabels.default;
}
};

export const GuiLabel = getPlatformLabels();

export const GuiShortLabel = GuiLabel.short;

0 comments on commit ba10887

Please sign in to comment.