Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[master] feat: Improve macOS defaults support #66466

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

cdalvaro
Copy link
Contributor

@cdalvaro cdalvaro commented May 5, 2024

What does this PR do?

Improve macOS defaults support by adding typecasting as well as dictionaries and arrays parsing.

Previous Behavior

Dictionaries and arrays were not supported.

New Behavior

Now you can set dictionaries and arrays, and support for floats and integers values has been improved.

Some examples that works now:

Rectangle - Almost Maximize height:
  macdefaults.write:
    - name: almostMaximizeHeight
    - domain: com.knollsoft.Rectangle.plist
    - value: 0.80
    - vtype: float
    - user: cdalvaro
    - require:
        - pkg: Rectangle

Rectangle - Almost Maximize shortcut:
  macdefaults.write:
    - name: almostMaximize
    - domain: com.knollsoft.Rectangle.plist
    - value:
        keyCode: 36
        modifierFlags: 786432
    - vtype: dict
    - user: cdalvaro
    - require:
        - pkg: Rectangle

The recipe Rectangle - Almost Maximize height didn't work because when comparing the current value with the new one, the new one was a float and the retrieved by macdefaults.read was a string. Thus, the comparison doesn't match.

The recipe Rectangle - Almost Maximize shortcut was not working at all. The write command wasn't formed well. And the output retrieved by macdefaults.read was not parsed into a Python dictionary, so comparison always fails.

Other recipes that works now:

Empty dict set:
  macdefaults.write:
    - name: PROPERTY
    - domain: DOMAIN
    - value: {}
    - vtype: dict

Add new elements to existing dict:
  macdefaults.write:
    - name: PROPERTY
    - domain: DOMAIN
    - value:
      - existingKey: 1
      - newKey: 'Hi'
    - vtype: dict-add

Array set:
  macdefaults.write:
    - name: PROPERTY
    - domain: DOMAIN
    - value:
      - 1
      - 2
      - 3
    - vtype: array

Add an array to existing array:
# Order matters, if the new array is not contained
# in the existing array with the same order it will be appended
  macdefaults.write:
    - name: PROPERTY
    - domain: DOMAIN
    - value:
      - 5
      - 6
    - vtype: array-add

⚠️ Breaking changes

Values are typecasted when possible, so some formulas may need to be adapted to be idempotent.

The type parameter in the macdefaults.write method has been deprecated in favor of vtype. This makes the state and the module coherent and avoids the collision between the parameter and the built-in type() Python function.

The type parameter should be removed in version 3009.

Merge requirements satisfied?

Commits signed with GPG?

Yes

Please review Salt's Contributing Guide for best practices, including the
PR Guidelines.

See GitHub's page on GPG signing for more information about signing commits with GPG.

@salt-project-bot-prod-environment salt-project-bot-prod-environment bot changed the title feat: Improve macOS defaults support [master] feat: Improve macOS defaults support May 5, 2024
@cdalvaro cdalvaro force-pushed the enhancement/improve_macOS_defaults_support branch from 5ac919d to 290b097 Compare May 8, 2024 09:16
@cdalvaro cdalvaro marked this pull request as ready for review May 8, 2024 09:17
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.

None yet

1 participant