| Total Complexity | 7 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from pathlib import Path |
||
| 2 | |||
| 3 | import applescript |
||
| 4 | import log |
||
| 5 | |||
| 6 | FUNCTIONS = Path(__file__).parent / "slack.applescript" |
||
| 7 | |||
| 8 | |||
| 9 | def activate() -> bool: |
||
| 10 | return _call("activate()") |
||
| 11 | |||
| 12 | |||
| 13 | def signin(workspace: str) -> bool: |
||
| 14 | return _call(f'signin("{workspace}")') |
||
| 15 | |||
| 16 | |||
| 17 | def signout(workspace: str) -> bool: |
||
| 18 | return _call(f'signout("{workspace}")', show_error=False) |
||
| 19 | |||
| 20 | |||
| 21 | def _call(signature: str, show_error: bool = True) -> bool: |
||
| 22 | functions = FUNCTIONS.read_text("utf-8") |
||
| 23 | |||
| 24 | log.debug(f"Calling AppleScript: {signature}") |
||
| 25 | result = applescript.run(functions + "\n\n" + signature) |
||
| 26 | |||
| 27 | if result.out: |
||
| 28 | log.debug(f"AppleScript output: {result.out}") |
||
| 29 | if result.err: |
||
| 30 | log.debug(f"AppleScript error: {result.err}") |
||
| 31 | if show_error: |
||
| 32 | message = result.err.split("error:")[-1].strip() |
||
| 33 | log.error(message) |
||
| 34 | |||
| 35 | return result.code == 0 |
||
| 36 |