Make entrypoint.*.actions.*.shortcut optional

This commit is contained in:
Exidex 2025-05-03 10:09:57 +02:00
parent 9abbc1909d
commit ebcee6a470
No known key found for this signature in database
GPG key ID: AC63AA86DD4F2D45
7 changed files with 44 additions and 22 deletions

View file

@ -9,6 +9,13 @@ For changes in `@project-gauntlet/tools` see [separate CHANGELOG.md](https://git
## [Unreleased]
- Windows in "Opened windows" view entrypoint are now sorted following "most recently focused on the top" order
- Plugin manifest property `entrypoint.*.actions.*.shortcut` is now optional
### Fixes
- Unified `Vec<u8>` usage to `ArrayBuffer` in JS
- Fixes `icon` in EntrypointGenerator requiring `number[]`
## [18] - 2025-04-13
### General

View file

@ -29,10 +29,10 @@ enum_values = [
[[entrypoint]]
id = 'windows'
name = 'Open Windows'
name = 'Opened Windows'
path = 'src/windows.tsx'
type = 'view'
description = 'Show all open windows'
description = 'Show all opened windows'
[[entrypoint]]
id = 'settings'

View file

@ -13,7 +13,7 @@ export function ListOfWindows({ windows, focusWindow }: {
}) {
const knownWindows = readWindowOrder();
const sortedWindows = Object.keys(windows) // sort windows bases on array stored on storage
const sortedWindows = Object.keys(windows) // sort windows based on array stored on storage
.sort((a, b) => knownWindows.indexOf(a) - knownWindows.indexOf(b));
return (

View file

@ -75,8 +75,7 @@
"type": "object",
"required": [
"description",
"id",
"shortcut"
"id"
],
"properties": {
"description": {
@ -89,9 +88,12 @@
},
"shortcut": {
"description": "Default keyboard shortcut to trigger the action",
"allOf": [
"anyOf": [
{
"$ref": "#/definitions/PluginManifestActionShortcut"
},
{
"type": "null"
}
]
}

View file

@ -200,8 +200,8 @@ pub enum DbPluginPreferenceUserData {
pub struct DbPluginAction {
pub id: String,
pub description: String,
pub key: String,
pub kind: DbPluginActionShortcutKind,
pub key: Option<String>,
pub kind: Option<DbPluginActionShortcutKind>,
}
#[derive(Debug, Deserialize, Serialize)]
@ -722,17 +722,21 @@ impl DataDbRepository {
let action_shortcuts = actions
.into_iter()
.map(|action| {
.filter_map(|action| {
let id = action.id;
let shortcut = match actions_user_data.get(&id) {
None => {
let (physical_key, modifier_shift) = match ActionShortcutKey::from_value(&action.key) {
Some(key) => key.to_physical_key(),
None => return Err(anyhow!("unknown key: {}", &action.key)),
let (Some(key), Some(kind)) = (action.key, action.kind) else {
return None;
};
let (modifier_control, modifier_alt, modifier_meta) = match action.kind {
let (physical_key, modifier_shift) = match ActionShortcutKey::from_value(&key) {
Some(key) => key.to_physical_key(),
None => return Some(Err(anyhow!("unknown key: {}", &key))),
};
let (modifier_control, modifier_alt, modifier_meta) = match kind {
DbPluginActionShortcutKind::Main => {
if cfg!(target_os = "macos") {
(false, false, true)
@ -762,7 +766,7 @@ impl DataDbRepository {
}
};
Ok((id, shortcut))
Some(Ok((id, shortcut)))
})
.collect::<Result<HashMap<_, _>, _>>()?;

View file

@ -401,16 +401,25 @@ impl PluginLoader {
.actions
.into_iter()
.map(|action| {
DbPluginAction {
id: action.id,
description: action.description,
key: action.shortcut.key.to_model().to_value(),
kind: match action.shortcut.kind {
let key = action
.shortcut
.as_ref()
.map(|shortcut| shortcut.key.to_model().to_value());
let kind = action.shortcut.as_ref().map(|shortcut| {
match shortcut.kind {
PluginManifestActionShortcutKind::Main => DbPluginActionShortcutKind::Main,
PluginManifestActionShortcutKind::Alternative => {
DbPluginActionShortcutKind::Alternative
}
},
}
});
DbPluginAction {
id: action.id,
description: action.description,
key,
kind,
}
})
.collect(),

View file

@ -175,7 +175,7 @@ pub struct PluginManifestAction {
#[schemars(description = "Description of what the action does")]
pub description: String,
#[schemars(description = "Default keyboard shortcut to trigger the action")]
pub shortcut: PluginManifestActionShortcut,
pub shortcut: Option<PluginManifestActionShortcut>,
}
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
@ -382,7 +382,7 @@ pub enum PluginManifestActionShortcutKey {
}
impl PluginManifestActionShortcutKey {
pub fn to_model(self) -> ActionShortcutKey {
pub fn to_model(&self) -> ActionShortcutKey {
match self {
PluginManifestActionShortcutKey::Num0 => ActionShortcutKey::Num0,
PluginManifestActionShortcutKey::Num1 => ActionShortcutKey::Num1,