| Total Complexity | 6 |
| Total Lines | 33 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import log |
||
| 2 | from datafiles import datafile, field |
||
| 3 | |||
| 4 | |||
| 5 | @datafile |
||
| 6 | class Workspace: |
||
| 7 | name: str |
||
| 8 | active: bool = True |
||
| 9 | |||
| 10 | |||
| 11 | @datafile("~/Library/Preferences/slackoff.yml") |
||
| 12 | class Settings: |
||
| 13 | workspaces: list[Workspace] = field(default_factory=list) |
||
| 14 | |||
| 15 | def activate(self, name: str): |
||
| 16 | log.debug(f"Marking workspace active: {name}") |
||
| 17 | self._update(name, True) |
||
| 18 | |||
| 19 | def deactivate(self, name: str): |
||
| 20 | log.debug(f"Marking workspace inactive: {name}") |
||
| 21 | self._update(name, False) |
||
| 22 | |||
| 23 | def _update(self, name: str, active: bool): |
||
| 24 | for workspace in self.workspaces: |
||
| 25 | if workspace.name == name: |
||
| 26 | workspace.active = active |
||
| 27 | break |
||
| 28 | else: |
||
| 29 | self.workspaces.append(Workspace(name, active)) |
||
| 30 | |||
| 31 | |||
| 32 | settings = Settings() |
||
| 33 |