-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotification.v
70 lines (61 loc) · 1.38 KB
/
notification.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module notify
import os
pub struct Notification {
pub mut:
app_name string
title string = 'Title'
message string = 'Message'
icon string = 'dialog-information'
timeout u32 = 5000
categories []Category
urgency Level = .normal
}
/*
-a, --app-name=APP_NAME: specifies the application name for the icon.
-h TYPE:NAME:VALUE, --hint=TYPE:NAME:VALUE: specifies basic extra data to pass. The possible values of TYPE are: int, double, string or byte.
*/
pub fn (mut n Notification) add_category(c Category) {
if c in n.categories {
return
}
n.categories << c
}
pub fn (mut n Notification) remove_category(c Category) {
for i := 0; i < n.categories.len; i++ {
if n.categories[i] == c {
n.categories.delete(i)
break
}
}
}
pub fn (n Notification) has_category(c Category) bool {
return c in n.categories
}
pub fn (n Notification) str() string {
mut cmd := 'notify-send'
//
cmd += ' \'$n.title\''
cmd += ' \'$n.message\''
//
cmd += ' --app-name=\'$n.app_name\''
//
cmd += ' --icon=$n.icon'
//
cmd += ' --expire-time=$n.timeout'
//
categories := categories_to_string(n.categories)
cmd += ' --category=$categories'
//
cmd += ' --urgency=$n.urgency'
//
cmd += ' --hint=string:sound-name:message-new-email'
//
return cmd
}
pub fn (n Notification) send() bool {
println('')
println(n)
println('')
res := os.execute(n.str())
return res.exit_code == 0
}