Skip to content

feat: sub extension can set 'platforms' now#847

Merged
RainyNight9 merged 1 commit intomainfrom
feat/sub_ext_platforms
Jul 31, 2025
Merged

feat: sub extension can set 'platforms' now#847
RainyNight9 merged 1 commit intomainfrom
feat/sub_ext_platforms

Conversation

@SteveLauC
Copy link
Copy Markdown
Member

Before this commit, sub extensions were not allowed to set their "platforms" field, this restriction is lifted in this commit.

By allowing this, a group extension can have sub extensions for different platforms, here is an example (irrelavent fields are omitted for the sake of simplicity):

{
  "name": "Suspend my machine",
  "type": "Group",
  "platforms": ["macos", "windows"],
  "commands": [
    {
      "name": "Suspend macOS":
      "platforms": ["macos"],
      "action": {...}
    },
    {
      "name": "Suspend Windows":
      "platforms": ["windows"],
      "action": {...}
    }
  ]
}

While loading or installing extensions, incompatible sub extensions will be filtered out by Coco, e.g., you won't see that "Suspend Windows" command if you are on macOS.

An extra check is added in this commit to ensure a sub extensions won't support the platforms that are incompatible with its main extension.

Even though main extensions and sub extensions can both have "platforms" specified, the semantics of this field, when not set, differs between them. For main extensions, it means this extension is compatible with all the platforms supported by Coco (null == all). For sub extensions, having it not set implicitly says that this field has the same value as the main extension's "platforms" field.

The primary reason behind this design is that if we choose the semantics used by the main extension, treating null as all, all the extensions we currently have will become invalid, because they are all macOS-only, the main extensions's "platforms" field is "macos" and sub extensions' "platforms" is not set (null), they will be equivalent to:

{
  "name": "this is macOS-only",
  "type": "Group",
  "platforms": ["macos"],
  "commands": [
    {
      "name": "How the fxxk can this support all the platforms!"
      "platforms": ["macos", "windows", "linux"],
      "type": "Command",
      "action": {...}
    }
  ]
}

This hits exactly the check we mentioned earlier and will be rejected by Coco. If we have users installed them, the installed extensions will be treated invalid and rejected by future Coco release, boom, we break backward compatibility.

Also, the current design actually makes sense. Nobody wants to repeatedly tell Coco that all the sub extensions support macOS if this can be said only once:

{
  "name": "this is macOS-only",
  "platforms": ["macos"],
  "commands": [
    {
      "name": "This supports macOS"
      "platforms": ["macos"],
    },
    {
      "name": "This supports macOS too"
      "platforms": ["macos"],
    },
    {
      "name": "Guess what! this also supports macOS"
      "platforms": ["macos"],
    },
    {
      "name": "Come on dude, do I really to say this platform=macos so many times"
      "platforms": ["macos"],
    }
  ]
}

Standards checklist

  • The PR title is descriptive
  • The commit messages are semantic
  • Necessary tests are added
  • Updated the release notes
  • Necessary documents have been added if this is a new feature
  • Performance tests checked, no obvious performance degradation

Before this commit, sub extensions were not allowed to set their
"platforms" field, this restriction is lifted in this commit.

By allowing this, a group extension can have sub extensions for
different platforms, here is an example (irrelavent fields are omitted
for the sake of simplicity):

```json
{
  "name": "Suspend my machine",
  "type": "Group",
  "platforms": ["macos", "windows"],
  "commands": [
    {
      "name": "Suspend macOS":
      "platforms": ["macos"],
      "action": {...}
    },
    {
      "name": "Suspend Windows":
      "platforms": ["windows"],
      "action": {...}
    }
  ]
}
```

While loading or installing extensions, incompatible sub extensions will
be filtered out by Coco, e.g., you won't see that "Suspend Windows"
command if you are on macOS.

An extra check is added in this commit to ensure a sub extensions won't
support the platforms that are incompatible with its main extension.

Even though main extensions and sub extensions can both have "platforms"
specified, the semantics of this field, when not set, differs between them.
For main extensions, it means this extension is compatible with all the
platforms supported by Coco (null == all).  For sub extensions, having it
not set implicitly says that this field has the same value as the main
extension's "platforms" field.

The primary reason behind this design is that if we choose the semantics used
by the main extension, treating null as all, all the extensions we currently
have will become invalid, because they are all macOS-only, the main extensions's
"platforms" field is "macos" and sub extensions' "platforms" is not set (null),
they will be equivalent to:

```json
{
  "name": "this is macOS-only",
  "type": "Group",
  "platforms": ["macos"],
  "commands": [
    {
      "name": "How the fxxk can this support all the platforms!"
      "platforms": ["macos", "windows", "linux"],
      "type": "Command",
      "action": {...}
    }
  ]
}
```
This hits exactly the check we mentioned earlier and will be rejected by
Coco.  If we have users installed them, the installed extensions will be
treated invalid and rejected by future Coco release, boom, we break backward
compatibility.

Also, the current design actually makes sense.  Nobody wants to repeatedly
tell Coco that all the sub extensions support macOS if this can be said only
once:

```json
{
  "name": "this is macOS-only",
  "platforms": ["macos"],
  "commands": [
    {
      "name": "This supports macOS"
      "platforms": ["macos"],
    },
    {
      "name": "This supports macOS too"
      "platforms": ["macos"],
    },
    {
      "name": "Guess what! this also supports macOS"
      "platforms": ["macos"],
    },
    {
      "name": "Come on dude, do I really to say this platform=macos so many times"
      "platforms": ["macos"],
    }
  ]
}
```
@SteveLauC SteveLauC force-pushed the feat/sub_ext_platforms branch from 24a7cc9 to 613ad92 Compare July 31, 2025 10:08
@RainyNight9 RainyNight9 merged commit c30df6c into main Jul 31, 2025
4 checks passed
@RainyNight9 RainyNight9 deleted the feat/sub_ext_platforms branch July 31, 2025 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[extension] Support Platform-Specific Commands Within a Single Extension

2 participants