Skip to content

Commit 915f2a5

Browse files
authored
Fix notify (#475)
* fix notification delay * added copilot suggestions
1 parent 1908688 commit 915f2a5

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

src/Utility/OSDNotify.vala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public class OSDNotify : GLib.Object {
7070

7171
string s = "notify-send -t %d -u %s -i %s \"%s\" \"%s\" -h %s".printf(
7272
durationMillis, urgency, "gtk-dialog-" + dialog_type, title, message, hint);
73-
74-
retVal = exec_sync (s, null, null);
73+
74+
retVal = TeeJee.ProcessHelper.exec_user_async(s);
7575

7676
dt_last_notification = new DateTime.now_local();
7777
}

src/Utility/TeeJee.Process.vala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,26 @@ namespace TeeJee.ProcessHelper{
202202
}
203203
}
204204

205+
/**
206+
executes a command as the "normal" unprivileged user async
207+
may execute the command as root if the user could not be determined or the name could not be resolved
208+
*/
209+
public static int exec_user_async(string command) {
210+
// find correct user
211+
int uid = TeeJee.System.get_user_id();
212+
string cmd = command;
213+
if(uid > 0) {
214+
// non root
215+
string? user = TeeJee.System.get_username_from_uid(uid);
216+
if(user != null) {
217+
cmd = "pkexec --user %s env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS ".printf(user) + cmd;
218+
}
219+
}
220+
221+
log_debug(cmd);
222+
return TeeJee.ProcessHelper.exec_script_async(cmd);
223+
}
224+
205225
public string? save_bash_script_temp (string commands, string? script_path = null,
206226
bool force_locale = true, bool supress_errors = false){
207227

src/Utility/TeeJee.System.vala

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ namespace TeeJee.System{
6767

6868
public string? get_username_from_uid(int user_id){
6969
unowned Posix.Passwd? pw = Posix.getpwuid(user_id);
70-
return pw?.pw_name;
70+
string? outvalue = pw?.pw_name;
71+
if(null == outvalue) {
72+
log_error("Could not get username for uid %d".printf(user_id));
73+
}
74+
return outvalue;
7175
}
7276

7377
// system ------------------------------------
@@ -90,19 +94,7 @@ namespace TeeJee.System{
9094

9195
string cmd = "xdg-open '%s'".printf(escape_single_quote(file));
9296

93-
// find correct user
94-
int uid = get_user_id();
95-
if(uid > 0) {
96-
// non root
97-
string? user = get_username_from_uid(uid);
98-
if(user != null) {
99-
cmd = "pkexec --user %s env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS ".printf(user) + cmd;
100-
}
101-
}
102-
103-
log_debug(cmd);
104-
int status = exec_script_async(cmd);
105-
return (status == 0);
97+
return exec_user_async(cmd) == 0;
10698
}
10799

108100
public bool exo_open_folder (string dir_path, bool xdg_open_try_first = true){

0 commit comments

Comments
 (0)