Skip to content

Commit

Permalink
fix client show issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sulincix committed Jan 19, 2024
1 parent 8317d49 commit 390a29b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/client/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def power_mode_event(self, widget):
data["new-mode"] = "performance"
send_server(data)

@asynchronous
@idle
def update(self,data):
self.init()
print(data)
Expand All @@ -173,7 +173,7 @@ def update(self,data):
self.o("ui_scale_brightness").set_value((cur*100)/max)
else:
self.o("ui_box_brightness").set_visible(False)
if "show" in data:
if "show" in data and data["show"] == str(os.getuid()):
self.open_window_event(None)
if self.current_mode == "powersave":
self.o("ui_button_powersave").set_sensitive(False)
Expand Down
8 changes: 6 additions & 2 deletions src/client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def usage():
print("Usage: ppm [set/get] [mode/backlight] (value)")
exit(1)

if len(sys.argv) <= 2:
if len(sys.argv) <= 2 and sys.argv[1] != "show":
usage()

if not os.path.exists("/run/ppm"):
Expand All @@ -16,7 +16,11 @@ def usage():

data = {}
data["pid"] = os.getpid()
if sys.argv[1] == "set":
if sys.argv[1] == "show":
data["show"] = str(os.getuid())
with open("/run/ppm","w") as f:
f.write(json.dumps(data))
elif sys.argv[1] == "set":
if len(sys.argv) <= 3:
usage()
if sys.argv[2] == "mode":
Expand Down
19 changes: 8 additions & 11 deletions src/client/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,23 @@
from MainWindow import *
import os, sys

import gi
import gi, json
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gio, GLib

client_dir = "/run/user/{}/ppm/".format(os.getuid())
no_show = False
if os.path.exists(client_dir):
data = {}
data["pid"] = os.getpid()
data["show"] = "1"
for fifo in listdir(client_dir):
if os.path.exists("/proc/{}".format(fifo)):
writefile(client_dir + fifo, json.dumps(data))
no_show = True
else:
os.unlink(client_dir + fifo)
if len(os.listdir(client_dir)) > 0:
data = {}
data["pid"] = os.getpid()
data["show"] = str(os.getuid())
no_show = True
with open("/run/ppm","w") as f:
f.write(json.dumps(data))
if no_show:
exit(0)


class Application(Gtk.Application):
def __init__(self, *args, **kwargs):
super().__init__(*args, application_id="tr.org.pardus.power-manager",
Expand Down
8 changes: 8 additions & 0 deletions src/common/asyncfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ def wrapper(*args, **kwargs):
return thread
return wrapper


from gi.repository import GObject

def idle(func):
def wrapper(*args, **kwargs):
GObject.idle_add(func, *args, **kwargs)
return wrapper

2 changes: 2 additions & 0 deletions src/service/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def main(data):
# client update
udata = {}
udata["mode"] = power.get_mode()
if "show" in data:
udata["show"] = data["show"]
udata["backlight"] = {}
for dev in backlight.get_devices():
udata["backlight"][dev] = {}
Expand Down

0 comments on commit 390a29b

Please sign in to comment.