Cleanup of #371
- Remove --rpc requirement, add version command, fix help behavior and dark mode - Add controller RPC commands and fix startup order - Fixed help command, added version command, fixed GTK Dark mode - Update README.md - Removed requirement for --rpc - Revise README for clarity and formatting - Updated usage instructions and fixed formatting issues in the README. - added a 'leave' function - Update README.md - rename helper functions - removed unreachable returns - re-added spaces - moved constants into helper function - cleaned up readme --------- Co-authored-by: Abhilash <pianoabhilash@gmail.com> Co-authored-by: Abhilash K <81313252+ebilesh@users.noreply.github.com>
This commit is contained in:
parent
d35198c56d
commit
6ec3ee0524
2 changed files with 98 additions and 62 deletions
29
README.md
29
README.md
|
|
@ -27,7 +27,11 @@ This will close out any already running discover overlay for this user
|
|||
#### Close the overlay
|
||||
`discover-overlay --close` or `discover-overlay -x`
|
||||
|
||||
This closes the process running the overlay, hence any `--rpc` commands sent afterwards will do nothing
|
||||
This closes the process running the overlay. Any control commands sent afterwards will do nothing
|
||||
|
||||
#### Show version
|
||||
|
||||
`discover-overlay --version` or `discover-overlay --V`
|
||||
|
||||
#### Open configuration window
|
||||
`discover-overlay --configure` or `discover-overlay -c`
|
||||
|
|
@ -38,40 +42,43 @@ This closes the process running the overlay, hence any `--rpc` commands sent aft
|
|||
This will redirect all debug to the file `~/.config/discover-overlay/output.txt`
|
||||
|
||||
#### Hide the currently shown overlays
|
||||
`discover-overlay --rpc --hide`
|
||||
`discover-overlay --hide`
|
||||
|
||||
This will not stop the process running the overlay. This means the `--rpc` commands sent afterwards continue working as expected, and the `--show` is much quicker than starting the overlay from the start.
|
||||
This will not stop the process running the overlay. This means the control commands sent afterwards continue working as expected, and the `--show` is much quicker than starting the overlay from the start.
|
||||
|
||||
#### Show the overlays
|
||||
`discover-overlay --rpc --show`
|
||||
`discover-overlay --show`
|
||||
|
||||
Note that if the process running the overlay has stopped or crashed then this will do nothing
|
||||
|
||||
#### Mute yourself in voice chat
|
||||
`discover-overlay --rpc --mute`
|
||||
`discover-overlay --mute`
|
||||
|
||||
#### Unmute yourself in voice chat
|
||||
`discover-overlay --rpc --unmute`
|
||||
`discover-overlay --unmute`
|
||||
|
||||
#### Deafen yourself in voice chat
|
||||
`discover-overlay --rpc --deaf`
|
||||
`discover-overlay --deaf`
|
||||
|
||||
#### Undeafen yourself in voice chat
|
||||
`discover-overlay --rpc --undeaf`
|
||||
`discover-overlay --undeaf`
|
||||
|
||||
### Attempt to leave the current voice channel
|
||||
|
||||
`discover-overlay --leave` or `discover-overlay -l`
|
||||
#### Attempt to join voice channel by room ID
|
||||
`discover-overlay --rpc --moveto=X`
|
||||
`discover-overlay --moveto=X`
|
||||
|
||||
Using a Room ID from Discord to replace `X`, this will attempt to join the voice channel.
|
||||
|
||||
#### Populate the channel RPC file with a list of guilds
|
||||
`discover-overlay --rpc --refresh-guilds`
|
||||
`discover-overlay --refresh-guilds`
|
||||
Requests a list of guilds. Once collected, it will write them to
|
||||
`~/.config/discover-overlay/channels.rpc`
|
||||
as a JSON object
|
||||
|
||||
#### Populate the channel RPC file with a list of channels from a guild
|
||||
`discover-overlay --rpc --guild-request=X`
|
||||
`discover-overlay --guild-request=X`
|
||||
Using a Server ID from Discord to replace `X`, this will request a list of channels (text & voice) from the given guild. Once collected, it will write them to
|
||||
`~/.config/discover-overlay/channels.rpc`
|
||||
as a JSON object.
|
||||
|
|
|
|||
|
|
@ -97,35 +97,6 @@ class Discover:
|
|||
"""
|
||||
Read in arg list from command or RPC and act accordingly
|
||||
"""
|
||||
if "--help" in data or "-h" in data:
|
||||
print(_("Usage") + ": discover-overlay [OPTIONS]... ")
|
||||
print(_("Show an X11 or wlroots overlay with information"))
|
||||
print(_("from Discord client"))
|
||||
print("")
|
||||
print(" -c, --configure ", _("Open configuration window"))
|
||||
print(" -x, --close ",
|
||||
_("Close currently running instance"))
|
||||
print(" -v, --debug ",
|
||||
_("Verbose output for aid in debugging"))
|
||||
print(" -h, --help ", _("This screen"))
|
||||
print(" --hide ", _("Hide overlay"))
|
||||
print(" --show ", _("Show overlay"))
|
||||
print(" --rpc ",
|
||||
_("Send command, not start new instance."))
|
||||
print(" --mute ", _("Set own user to mute"))
|
||||
print(" --unmute ", _("Set unmuted"))
|
||||
print(" --toggle-mute ", _("Toggle muted"))
|
||||
print(" --deaf ", _("Set own user to deafened"))
|
||||
print(" --undeaf ", _("Unset user deafened state"))
|
||||
print(" --toggle-deaf ", _("Toggle deaf"))
|
||||
print(" --moveto=XX ",
|
||||
_("Move the user into voice room, by Room ID"))
|
||||
print(" --minimized ",
|
||||
_("If tray icon is enabled, start with only tray icon and no configuration window"))
|
||||
print("")
|
||||
print(_("For gamescope compatibility ensure ENV has 'GDK_BACKEND=x11'"))
|
||||
if normal_close:
|
||||
sys.exit(0)
|
||||
if "--close" in data or "-x" in data:
|
||||
self.exit()
|
||||
if "--steamos" in data or "-s" in data:
|
||||
|
|
@ -155,6 +126,9 @@ class Discover:
|
|||
if "--refresh-guilds" in data:
|
||||
if self.connection:
|
||||
self.connection.req_guilds()
|
||||
if "--leave" in data or "-l" in data:
|
||||
if self.connection:
|
||||
self.connection.change_voice_room(None)
|
||||
pattern = re.compile("--moveto=([0-9]+)")
|
||||
if any((match := pattern.match(x)) for x in data):
|
||||
if self.connection:
|
||||
|
|
@ -487,6 +461,60 @@ class Discover:
|
|||
if deaf is not None:
|
||||
GLib.idle_add(self.connection.set_deaf, deaf)
|
||||
|
||||
def show_help():
|
||||
print(_("Usage") + ": discover-overlay [OPTIONS]... ")
|
||||
print(_("Show an X11 or wlroots overlay with information"))
|
||||
print(_("from Discord client"))
|
||||
print("")
|
||||
print(" -c, --configure ", _("Open configuration window"))
|
||||
print(" -x, --close ",
|
||||
_("Close currently running instance"))
|
||||
print(" -v, --debug ",
|
||||
_("Verbose output for aid in debugging"))
|
||||
print(" -h, --help ", _("This screen"))
|
||||
print(" -V, --version ", _("Show version information"))
|
||||
print(" --hide ", _("Hide overlay"))
|
||||
print(" --show ", _("Show overlay"))
|
||||
print(" --mute ", _("Set own user to mute"))
|
||||
print(" --unmute ", _("Set unmuted"))
|
||||
print(" --toggle-mute ", _("Toggle muted"))
|
||||
print(" --deaf ", _("Set own user to deafened"))
|
||||
print(" --undeaf ", _("Unset user deafened state"))
|
||||
print(" --toggle-deaf ", _("Toggle deaf"))
|
||||
print(" --moveto=XX ",
|
||||
_("Move the user into voice room, by Room ID"))
|
||||
print(" --leave ", _("Leave the current voice channel"))
|
||||
print(" --minimized ",
|
||||
_("If tray icon is enabled, start with only tray icon and no configuration window"))
|
||||
print("")
|
||||
print(_("For gamescope compatibility ensure ENV has 'GDK_BACKEND=x11'"))
|
||||
|
||||
def show_version():
|
||||
print(pkg_resources.get_distribution('discover_overlay').version)
|
||||
|
||||
def is_a_controller(argv):
|
||||
|
||||
actions = {
|
||||
"-x", "--close",
|
||||
"--hide", "--show",
|
||||
"--mute", "--unmute", "--toggle-mute",
|
||||
"--deaf", "--undeaf", "--toggle-deaf",
|
||||
"-l", "--leave",
|
||||
"--refresh-guilds",
|
||||
}
|
||||
controls = {
|
||||
"--moveto=",
|
||||
"--guild-request=",
|
||||
}
|
||||
for arg in argv:
|
||||
# Match the actions (i.e --mute, --deafen)
|
||||
if arg in actions:
|
||||
return True
|
||||
# Match the controls (i.e --moveto=123456789 and --guild-request=987654321)
|
||||
for control in controls:
|
||||
if arg.startswith(control):
|
||||
return True
|
||||
return False
|
||||
|
||||
def entrypoint():
|
||||
"""
|
||||
|
|
@ -502,6 +530,12 @@ def entrypoint():
|
|||
"""
|
||||
|
||||
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||
if "--help" in sys.argv or "-h" in sys.argv:
|
||||
show_help()
|
||||
return
|
||||
if "--version" in sys.argv or "-V" in sys.argv:
|
||||
show_version()
|
||||
return
|
||||
# Find Config directory
|
||||
config_dir = os.path.join(xdg_config_home, "discover_overlay")
|
||||
os.makedirs(config_dir, exist_ok=True)
|
||||
|
|
@ -512,6 +546,17 @@ def entrypoint():
|
|||
config_file = os.path.join(config_dir, "config.ini")
|
||||
debug_file = os.path.join(config_dir, "output.txt")
|
||||
|
||||
if "-c" in sys.argv or "--configure" in sys.argv:
|
||||
_settings = MainSettingsWindow(config_file, rpc_file, channel_file, sys.argv[1:])
|
||||
Gtk.main()
|
||||
return
|
||||
|
||||
if is_a_controller(sys.argv):
|
||||
line = " ".join(arg for arg in sys.argv[1:]).strip()
|
||||
with open(rpc_file, "w", encoding="utf-8") as f:
|
||||
f.write(line)
|
||||
return
|
||||
|
||||
# Prepare logger
|
||||
logging.getLogger().setLevel(logging.INFO)
|
||||
log_format = "%(levelname)s - %(name)s - %(message)s"
|
||||
|
|
@ -528,30 +573,14 @@ def entrypoint():
|
|||
if 'GAMESCOPE_WAYLAND_DISPLAY' in os.environ:
|
||||
os.unsetenv("WAYLAND_DISPLAY")
|
||||
|
||||
|
||||
# Catch any errors and log them
|
||||
try:
|
||||
if "--rpc" in sys.argv:
|
||||
# Send command to overlay
|
||||
line = ""
|
||||
for arg in sys.argv[1:]:
|
||||
line = f"{line} {arg}"
|
||||
with open(rpc_file, "w", encoding="utf-8") as tfile:
|
||||
tfile.write(line)
|
||||
log.warning("Sent RPC command")
|
||||
else:
|
||||
if "-c" in sys.argv or "--configure" in sys.argv:
|
||||
# Show config window
|
||||
_settings = MainSettingsWindow(
|
||||
config_file, rpc_file, channel_file, sys.argv[1:])
|
||||
Gtk.main()
|
||||
else:
|
||||
# Tell any other running overlay to close
|
||||
with open(rpc_file, "w", encoding="utf-8") as tfile:
|
||||
tfile.write("--close")
|
||||
# Show the overlay
|
||||
Discover(rpc_file, config_file, channel_file,
|
||||
debug_file, sys.argv[1:])
|
||||
return
|
||||
with open(rpc_file, "w", encoding="utf-8") as tfile:
|
||||
tfile.write("--close")
|
||||
# Show the overlay
|
||||
Discover(rpc_file, config_file, channel_file,
|
||||
debug_file, sys.argv[1:])
|
||||
|
||||
except Exception as ex: # pylint: disable=broad-except
|
||||
log.error(ex)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue