Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
ximper-shell-notification-center
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ximper Linux
ximper-shell-notification-center
Commits
ea66e687
Unverified
Commit
ea66e687
authored
Sep 26, 2023
by
Erik Reider
Committed by
GitHub
Sep 26, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplified script and base_widget command execution (#318)
parent
237310c6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
54 deletions
+56
-54
configModel.vala
src/configModel/configModel.vala
+12
-38
baseWidget.vala
src/controlCenter/widgets/baseWidget.vala
+3
-13
buttonsGrid.vala
src/controlCenter/widgets/buttonsGrid/buttonsGrid.vala
+1
-1
menubar.vala
src/controlCenter/widgets/menubar/menubar.vala
+2
-2
functions.vala
src/functions.vala
+38
-0
No files found.
src/configModel/configModel.vala
View file @
ea66e687
...
...
@@ -237,44 +237,18 @@ namespace SwayNotificationCenter {
public
ScriptRunOnType
run_on
{
get
;
set
;
default
=
ScriptRunOnType
.
RECEIVE
;
}
public
async
bool
run_script
(
NotifyParams
param
,
out
string
msg
)
{
msg
=
""
;
try
{
string
[]
spawn_env
=
Environ
.
get
();
// Export env variables
spawn_env
+=
"SWAYNC_APP_NAME=%s"
.
printf
(
param
.
app_name
);
spawn_env
+=
"SWAYNC_SUMMARY=%s"
.
printf
(
param
.
summary
);
spawn_env
+=
"SWAYNC_BODY=%s"
.
printf
(
param
.
body
);
spawn_env
+=
"SWAYNC_URGENCY=%s"
.
printf
(
param
.
urgency
.
to_string
());
spawn_env
+=
"SWAYNC_CATEGORY=%s"
.
printf
(
param
.
category
);
spawn_env
+=
"SWAYNC_ID=%s"
.
printf
(
param
.
applied_id
.
to_string
());
spawn_env
+=
"SWAYNC_REPLACES_ID=%s"
.
printf
(
param
.
replaces_id
.
to_string
());
spawn_env
+=
"SWAYNC_TIME=%s"
.
printf
(
param
.
time
.
to_string
());
spawn_env
+=
"SWAYNC_DESKTOP_ENTRY=%s"
.
printf
(
param
.
desktop_entry
??
""
);
Pid
child_pid
;
Process
.
spawn_async
(
"/"
,
exec
.
split
(
" "
),
spawn_env
,
SpawnFlags
.
SEARCH_PATH
|
SpawnFlags
.
DO_NOT_REAP_CHILD
,
null
,
out
child_pid
);
// Close the child when the spawned process is idling
int
end_status
=
0
;
ChildWatch
.
add
(
child_pid
,
(
pid
,
status
)
=>
{
Process
.
close_pid
(
pid
);
end_status
=
status
;
run_script
.
callback
();
});
// Waits until `run_script.callback()` is called above
yield
;
return
end_status
==
0
;
}
catch
(
Error
e
)
{
stderr
.
printf
(
"Run_Script Error: %s\n"
,
e
.
message
);
msg
=
e
.
message
;
return
false
;
}
string
[]
spawn_env
=
{};
spawn_env
+=
"SWAYNC_APP_NAME=%s"
.
printf
(
param
.
app_name
);
spawn_env
+=
"SWAYNC_SUMMARY=%s"
.
printf
(
param
.
summary
);
spawn_env
+=
"SWAYNC_BODY=%s"
.
printf
(
param
.
body
);
spawn_env
+=
"SWAYNC_URGENCY=%s"
.
printf
(
param
.
urgency
.
to_string
());
spawn_env
+=
"SWAYNC_CATEGORY=%s"
.
printf
(
param
.
category
);
spawn_env
+=
"SWAYNC_ID=%s"
.
printf
(
param
.
applied_id
.
to_string
());
spawn_env
+=
"SWAYNC_REPLACES_ID=%s"
.
printf
(
param
.
replaces_id
.
to_string
());
spawn_env
+=
"SWAYNC_TIME=%s"
.
printf
(
param
.
time
.
to_string
());
spawn_env
+=
"SWAYNC_DESKTOP_ENTRY=%s"
.
printf
(
param
.
desktop_entry
??
""
);
return
yield
Functions
.
execute_command
(
exec
,
spawn_env
,
out
msg
);
}
public
override
bool
matches_notification
(
NotifyParams
param
)
{
...
...
src/controlCenter/widgets/baseWidget.vala
View file @
ea66e687
using
Posix
;
namespace
SwayNotificationCenter.Widgets
{
public
abstract
class
BaseWidget
:
Gtk
.
Box
{
public
abstract
string
widget_name
{
get
;
}
...
...
@@ -101,17 +99,9 @@ namespace SwayNotificationCenter.Widgets {
return
res
;
}
protected
void
execute_command
(
string
cmd
)
{
pid_t
pid
;
int
status
;
if
((
pid
=
fork
())
<
0
)
{
perror
(
"fork()"
);
}
if
(
pid
==
0
)
{
// Child process
execl
(
"/bin/sh"
,
"sh"
,
"-c"
,
cmd
);
exit
(
EXIT_FAILURE
);
// should not return from execl
}
waitpid
(
pid
,
out
status
,
1
);
protected
async
void
execute_command
(
string
cmd
,
string
[]
env_additions
=
{})
{
string
msg
=
""
;
yield
Functions
.
execute_command
(
cmd
,
env_additions
,
out
msg
);
}
}
}
src/controlCenter/widgets/buttonsGrid/buttonsGrid.vala
View file @
ea66e687
...
...
@@ -28,7 +28,7 @@ namespace SwayNotificationCenter.Widgets {
foreach
(
var
act
in
actions
)
{
Gtk
.
Button
b
=
new
Gtk
.
Button
.
with_label
(
act
.
label
);
b
.
clicked
.
connect
(()
=>
execute_command
(
act
.
command
));
b
.
clicked
.
connect
(()
=>
execute_command
.
begin
(
act
.
command
));
container
.
insert
(
b
,
-
1
);
}
...
...
src/controlCenter/widgets/menubar/menubar.vala
View file @
ea66e687
...
...
@@ -76,7 +76,7 @@ namespace SwayNotificationCenter.Widgets {
foreach
(
Action
a
in
obj
.
actions
)
{
Gtk
.
Button
b
=
new
Gtk
.
Button
.
with_label
(
a
.
label
);
b
.
clicked
.
connect
(()
=>
execute_command
(
a
.
command
));
b
.
clicked
.
connect
(()
=>
execute_command
.
begin
(
a
.
command
));
container
.
add
(
b
);
}
...
...
@@ -111,7 +111,7 @@ namespace SwayNotificationCenter.Widgets {
foreach
(
var
a
in
obj
.
actions
)
{
Gtk
.
Button
b
=
new
Gtk
.
Button
.
with_label
(
a
.
label
);
b
.
clicked
.
connect
(()
=>
execute_command
(
a
.
command
));
b
.
clicked
.
connect
(()
=>
execute_command
.
begin
(
a
.
command
));
menu
.
pack_start
(
b
,
true
,
true
,
0
);
}
...
...
src/functions.vala
View file @
ea66e687
...
...
@@ -299,5 +299,43 @@ namespace SwayNotificationCenter {
}
return
result
;
}
public
static
async
bool
execute_command
(
string
cmd
,
string
[]
env_additions
=
{},
out
string
msg
)
{
msg
=
""
;
try
{
string
[]
spawn_env
=
Environ
.
get
();
// Export env variables
foreach
(
string
additions
in
env_additions
)
{
spawn_env
+=
additions
;
}
string
[]
argvp
=
{};
Shell
.
parse_argv
(
cmd
,
out
argvp
);
Pid
child_pid
;
Process
.
spawn_async
(
"/"
,
argvp
,
spawn_env
,
SpawnFlags
.
SEARCH_PATH
|
SpawnFlags
.
DO_NOT_REAP_CHILD
,
null
,
out
child_pid
);
// Close the child when the spawned process is idling
int
end_status
=
0
;
ChildWatch
.
add
(
child_pid
,
(
pid
,
status
)
=>
{
Process
.
close_pid
(
pid
);
end_status
=
status
;
execute_command
.
callback
();
});
// Waits until `run_script.callback()` is called above
yield
;
return
end_status
==
0
;
}
catch
(
Error
e
)
{
stderr
.
printf
(
"Run_Script Error: %s\n"
,
e
.
message
);
msg
=
e
.
message
;
return
false
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment