Skip to content

Commit

Permalink
Allow for alternate dragon invocations
Browse files Browse the repository at this point in the history
At least when building dragon from source the binary is called
"dragon" and not "dragon-drop". Solve this by providing a
configuration knob which can point at the right thing.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
  • Loading branch information
stsquad authored and moverest committed May 5, 2023
1 parent dcab91f commit f82b7a9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ file_name = "screencast_%Y-%m-%dT%H:%M:%S.mkv"

# Record audio.
audio = "ask" # "yes", "no"

[notification_actions]
# Alternative name for dragon-drop binary
dragon.command = "dragon"

```

The `SWAY_INTERACTIVE_SCREENSHOT_SAVEDIR` environment variable, while still supported, is deprecated and will be removed in a future version.
30 changes: 24 additions & 6 deletions sway-interactive-screenshot
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ class Config:
"file_name": "screencast_%Y-%m-%dT%H:%M:%S.mkv",
"audio": "ask",
},
"notification_actions": {
"dragon": {
"command": "dragon-drop",
}
},
}

_validate = staticmethod(
Expand All @@ -124,6 +129,15 @@ class Config:
"audio": config_enum_validator({"yes", "no", "ask"}),
}
),
"notification_actions": config_dict_validator(
{
"dragon": config_dict_validator(
{
"command": config_type_validator(str),
}
)
}
),
}
)
)
Expand Down Expand Up @@ -517,7 +531,7 @@ class NotificationAction(abc.ABC):

@classmethod
@abc.abstractmethod
def run(cls, *, filepath: Path) -> None:
def run(cls, *, filepath: Path, config_getter: Callable[[str], Any]) -> None:
pass


Expand All @@ -526,7 +540,7 @@ class EditNotificationAction(NotificationAction):
description = "Edit"

@classmethod
def run(cls, *, filepath: Path) -> None:
def run(cls, *, filepath: Path, config_getter: Callable[[str], Any]) -> None:
filepath_str = str(filepath.expanduser())
edit_capture(filepath_str)
copy_file_to_clipboard(filepath_str)
Expand All @@ -537,7 +551,7 @@ class DeleteNotificationAction(NotificationAction):
description = "Delete"

@classmethod
def run(cls, *, filepath: Path) -> None:
def run(cls, *, filepath: Path, config_getter: Callable[[str], Any]) -> None:
filepath.expanduser().unlink()
notify("Deleted")

Expand All @@ -547,8 +561,8 @@ class DragonNotificationAction(NotificationAction):
description = "Drag and drop"

@classmethod
def run(cls, *, filepath: Path) -> None:
subprocess.run(["dragon-drop", filepath.expanduser()], check=False)
def run(cls, *, filepath: Path, config_getter: Callable[[str], Any]) -> None:
subprocess.run([config_getter("command"), filepath.expanduser()], check=False)


class OpenNotificationAction(NotificationAction):
Expand Down Expand Up @@ -801,7 +815,11 @@ def main():
)

if action is not None:
action.run(filepath=filepath)
action.run(filepath=filepath,
config_getter=partial(config.get,
"notification_actions",
action.name)
)

except Exception as err: # pylint: disable=broad-except
display_name = (
Expand Down

0 comments on commit f82b7a9

Please sign in to comment.