-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow only one GUI instance on Linux
Otherwise, users may be confused if they try to activate Diode Transfer using the Applications menu: previously another instance of Diode Transfer would be launched. For #13
- Loading branch information
1 parent
3ba30eb
commit 260a522
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import json | ||
import subprocess | ||
import sys | ||
|
||
|
||
def activate(): | ||
""" | ||
Check whether the GUI is already running. If so, activate the existing | ||
window. Uses the [email protected] Gnome extension. | ||
:returns: A boolean indicating whether an already running instance was | ||
activated | ||
""" | ||
base_cmd = [ | ||
"gdbus", | ||
"call", | ||
"--session", | ||
"--dest", | ||
"org.gnome.Shell", | ||
"--object-path", | ||
"/org/gnome/Shell/Extensions/Windows", | ||
"--method", | ||
] | ||
completed = subprocess.run( | ||
base_cmd + ["org.gnome.Shell.Extensions.Windows.List"], | ||
stdout=subprocess.PIPE, | ||
) | ||
# Trim non-JSON characters from the front and back | ||
windows = json.loads(completed.stdout[2:-4]) | ||
windows = list(filter(lambda w: w["wm_class"] == "Diodetransfer", windows)) | ||
if windows: | ||
subprocess.run( | ||
base_cmd | ||
+ [ | ||
"org.gnome.Shell.Extensions.Windows.Activate", | ||
str(windows[0]["id"]), | ||
], | ||
) | ||
return True | ||
else: | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters