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
80e9312a
Verified
Commit
80e9312a
authored
Mar 21, 2026
by
Kirill Unitsaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
notification: compile static regexes only once
parent
6f87653a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
108 deletions
+48
-108
configModel.vala
src/configModel/configModel.vala
+20
-93
notification.vala
src/notification/notification.vala
+28
-15
No files found.
src/configModel/configModel.vala
View file @
80e9312a
...
...
@@ -113,101 +113,28 @@ namespace XimperShellNotificationCenter {
private
const
RegexMatchFlags
REGEX_MATCH_FLAGS
=
RegexMatchFlags
.
NOTEMPTY
;
public
virtual
bool
matches_notification
(
NotifyParams
param
)
{
if
(
app_name
!=
null
)
{
if
(
param
.
app_name
==
null
)
{
return
false
;
}
bool
result
=
Regex
.
match_simple
(
app_name
,
param
.
app_name
,
REGEX_COMPILE_OPTIONS
,
REGEX_MATCH_FLAGS
);
if
(!
result
)
{
return
false
;
}
private
static
bool
matches_field
(
string
?
pattern
,
string
?
value
,
RegexCompileFlags
compile_flags
=
REGEX_COMPILE_OPTIONS
)
{
if
(
pattern
==
null
)
{
return
true
;
}
if
(
desktop_entry
!=
null
)
{
if
(
param
.
desktop_entry
==
null
)
{
return
false
;
}
bool
result
=
Regex
.
match_simple
(
desktop_entry
,
param
.
desktop_entry
,
REGEX_COMPILE_OPTIONS
,
REGEX_MATCH_FLAGS
);
if
(!
result
)
{
return
false
;
}
}
if
(
summary
!=
null
)
{
if
(
param
.
summary
==
null
)
{
return
false
;
}
bool
result
=
Regex
.
match_simple
(
summary
,
param
.
summary
,
REGEX_COMPILE_OPTIONS
,
REGEX_MATCH_FLAGS
);
if
(!
result
)
{
return
false
;
}
}
if
(
body
!=
null
)
{
if
(
param
.
body
==
null
)
{
return
false
;
}
bool
result
=
Regex
.
match_simple
(
body
,
param
.
body
,
0
,
REGEX_MATCH_FLAGS
);
if
(!
result
)
{
return
false
;
}
}
if
(
urgency
!=
null
)
{
bool
result
=
Regex
.
match_simple
(
urgency
,
param
.
urgency
.
to_string
(),
REGEX_COMPILE_OPTIONS
,
REGEX_MATCH_FLAGS
);
if
(!
result
)
{
return
false
;
}
}
if
(
category
!=
null
)
{
if
(
param
.
category
==
null
)
{
return
false
;
}
bool
result
=
Regex
.
match_simple
(
category
,
param
.
category
,
REGEX_COMPILE_OPTIONS
,
REGEX_MATCH_FLAGS
);
if
(!
result
)
{
return
false
;
}
}
if
(
sound_file
!=
null
)
{
if
(
param
.
sound_file
==
null
)
{
return
false
;
}
bool
result
=
Regex
.
match_simple
(
sound_file
,
param
.
sound_file
,
REGEX_COMPILE_OPTIONS
,
REGEX_MATCH_FLAGS
);
if
(!
result
)
{
return
false
;
}
}
if
(
sound_name
!=
null
)
{
if
(
param
.
sound_name
==
null
)
{
return
false
;
}
bool
result
=
Regex
.
match_simple
(
sound_name
,
param
.
sound_name
,
REGEX_COMPILE_OPTIONS
,
REGEX_MATCH_FLAGS
);
if
(!
result
)
{
return
false
;
}
if
(
value
==
null
)
{
return
false
;
}
return
true
;
return
Regex
.
match_simple
(
pattern
,
value
,
compile_flags
,
REGEX_MATCH_FLAGS
);
}
public
virtual
bool
matches_notification
(
NotifyParams
param
)
{
return
matches_field
(
app_name
,
param
.
app_name
)
&&
matches_field
(
desktop_entry
,
param
.
desktop_entry
)
&&
matches_field
(
summary
,
param
.
summary
)
&&
matches_field
(
body
,
param
.
body
,
0
)
&&
matches_field
(
urgency
,
param
.
urgency
.
to_string
())
&&
matches_field
(
category
,
param
.
category
)
&&
matches_field
(
sound_file
,
param
.
sound_file
)
&&
matches_field
(
sound_name
,
param
.
sound_name
);
}
public
string
to_string
()
{
...
...
src/notification/notification.vala
View file @
80e9312a
...
...
@@ -87,18 +87,10 @@ namespace XimperShellNotificationCenter {
public
bool
has_inline_reply
{
get
;
private
set
;
default
=
false
;
}
private
static
Regex
code_regex
;
private
static
Regex
tag_regex
;
private
static
Regex
tag_unescape_regex
;
private
static
Regex
img_tag_regex
;
private
const
string
[]
TAGS
=
{
"b"
,
"u"
,
"i"
};
private
const
string
[]
UNESCAPE_CHARS
=
{
"lt;"
,
"#60;"
,
"#x3C;"
,
"#x3c;"
,
// <
"gt;"
,
"#62;"
,
"#x3E;"
,
"#x3e;"
,
// >
"apos;"
,
"#39;"
,
// '
"quot;"
,
"#34;"
,
// "
"amp;"
// &
};
private
static
bool
regexes_initialized
=
false
;
public
bool
dismissed
{
get
;
private
set
;
default
=
false
;
}
public
bool
dismissed_by_swipe
{
get
;
private
set
;
default
=
false
;
}
...
...
@@ -130,18 +122,39 @@ namespace XimperShellNotificationCenter {
build_noti
();
}
construct
{
private
const
string
[]
TAGS
=
{
"b"
,
"u"
,
"i"
};
private
const
string
[]
UNESCAPE_CHARS
=
{
"lt;"
,
"#60;"
,
"#x3C;"
,
"#x3c;"
,
// <
"gt;"
,
"#62;"
,
"#x3E;"
,
"#x3e;"
,
// >
"apos;"
,
"#39;"
,
// '
"quot;"
,
"#34;"
,
// "
"amp;"
// &
};
private
static
void
init_regexes
()
{
if
(
regexes_initialized
)
{
return
;
}
try
{
code_regex
=
new
Regex
(
"(?<= |^)(\\d{3}(-| )\\d{3}|\\d{4,8})(?= |$|\\.|,)"
,
RegexCompileFlags
.
MULTILINE
);
code_regex
=
new
Regex
(
"(?<= |^)(\\d{3}(-| )\\d{3}|\\d{4,8})(?= |$|\\.|,)"
,
RegexCompileFlags
.
MULTILINE
);
string
joined_tags
=
string
.
joinv
(
"|"
,
TAGS
);
tag_regex
=
new
Regex
(
"<(/?(?:%s))>"
.
printf
(
joined_tags
));
tag_regex
=
new
Regex
(
"<(/?(?:%s))>"
.
printf
(
joined_tags
));
string
unescaped
=
string
.
joinv
(
"|"
,
UNESCAPE_CHARS
);
tag_unescape_regex
=
new
Regex
(
"&(?=%s)"
.
printf
(
unescaped
));
img_tag_regex
=
new
Regex
(
"<img[^>]* src=((\"([^\"]*)\")|(\'([^\']*)\'))[^>]*>"
);
tag_unescape_regex
=
new
Regex
(
"&(?=%s)"
.
printf
(
unescaped
));
img_tag_regex
=
new
Regex
(
"<img[^>]* src=((\"([^\"]*)\")|(\'([^\']*)\'))[^>]*>"
);
regexes_initialized
=
true
;
}
catch
(
Error
e
)
{
stderr
.
printf
(
"Invalid regex: %s"
,
e
.
message
);
}
}
construct
{
init_regexes
();
bind_property
(
"dismissed"
,
this
,
"sensitive"
,
...
...
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