This repository has been archived by the owner on Mar 12, 2024. It is now read-only.
generated from tau-OS/vala-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
175 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
{ | ||
"mesonbuild.configureOnOpen": true, | ||
"[meson]": { | ||
"editor.defaultFormatter": "mesonbuild.mesonbuild" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
[Desktop Entry] | ||
Type = Application | ||
Name = Skiff | ||
Comment = Privacy-first end-to-end encrypted email | ||
Icon = @ICON_NAME@ | ||
Exec = @COMMAND@ | ||
Categories = GTK;GNOME;Office;Email;Calendar;ContactManagement | ||
DBusActivatable=true | ||
X-GNOME-UsesNotifications=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[D-BUS Service] | ||
Name=@APP_ID@ | ||
Exec=@BINDIR@/@APP_ID@ --gapplication-service |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,148 @@ | ||
public class SkiffDesktop.MessageHandler { | ||
private class NotificationItem : Object { | ||
private WebKit.WebView webview; | ||
private WebKit.UserScript script = new WebKit.UserScript ( | ||
""" | ||
window.IsSkiffWindowsDesktop = true | ||
window.chrome = { | ||
webview: { | ||
postMessage: (v) => window.webkit.messageHandlers.skiffDesktop.postMessage(v), | ||
addEventListener: (_, listener) => window._skiffListener = listener, | ||
removeEventListener: (_, listener) => delete window._skiffListener, | ||
} | ||
} | ||
""", | ||
WebKit.UserContentInjectedFrames.TOP_FRAME, | ||
WebKit.UserScriptInjectionTime.START, | ||
null, | ||
null | ||
); | ||
|
||
private class NotificationItem : Object, Json.Serializable { | ||
public string title { get; set; } | ||
public string body { get; set; } | ||
public string threadID { get; set; } | ||
public string emailID { get; set; } | ||
public string thread_id { get; set; } | ||
public string email_id { get; set; } | ||
|
||
public override unowned ParamSpec? find_property (string name) { | ||
switch (name) { | ||
case "threadID": | ||
name = "thread_id"; | ||
break; | ||
case "emailID": | ||
name = "email_id"; | ||
break; | ||
} | ||
|
||
return this.get_class ().find_property (name); | ||
} | ||
} | ||
|
||
private class NotificationData : Object { | ||
public NotificationItem[] notificationData { get; set; } | ||
private class UnreadData : Object, Json.Serializable { | ||
public int num_unread { get; set; } | ||
|
||
public override unowned ParamSpec? find_property (string name) { | ||
switch (name) { | ||
case "numUnread": | ||
name = "num_unread"; | ||
break; | ||
} | ||
|
||
return this.get_class ().find_property (name); | ||
} | ||
} | ||
|
||
private void display_notification (NotificationItem notification_item) { | ||
var notification = new Notification (notification_item.title); | ||
notification.set_body (notification_item.body); | ||
|
||
notification.set_default_action_and_target ("app.open-thread", "s", notification_item.thread_id); | ||
notification.add_button_with_target(_("Mark As Read"), "app.mark-as-read", "s", notification_item.thread_id); | ||
// notification.add_button_with_target(_("Mark As Spam"), "app.mark-as-spam", "s", notification_item.thread_id); kinda useless IMO (plus, goes over GNOME's limit :/) | ||
notification.add_button_with_target(_("Trash"), "app.trash-thread", "s", notification_item.thread_id); | ||
notification.add_button_with_target(_("Archive"), "app.archive-thread", "s", notification_item.thread_id); | ||
|
||
GLib.Application.get_default ().send_notification ("meowy", notification); | ||
} | ||
|
||
private class UnreadData : Object { | ||
public int numUnread { get; set; } | ||
public void send_notification_action (string thread_id, string action) { | ||
var root = new Json.Builder () | ||
.begin_object () | ||
.set_member_name ("type") | ||
.add_string_value ("notificationAction") | ||
.set_member_name ("data") | ||
.begin_object () | ||
.set_member_name ("action") | ||
.add_string_value (action) | ||
.set_member_name ("threadId") | ||
.add_string_value (thread_id) | ||
.end_object () | ||
.end_object () | ||
.get_root (); | ||
|
||
var generator = new Json.Generator (); | ||
generator.set_root (root); | ||
|
||
string? json_string = generator.to_data (null); | ||
|
||
var dict = new VariantDict (); | ||
dict.insert ("message", "s", json_string); | ||
var args = dict.end (); | ||
|
||
this.webview.call_async_javascript_function ( | ||
""" | ||
if ('_skiffListener' in window) { | ||
window._skiffListener({ data: message }) | ||
} | ||
""", | ||
-1, | ||
args, | ||
null, | ||
null, | ||
null | ||
); | ||
} | ||
|
||
public void on_script_message (JSC.Value val) { | ||
var parser = new Json.Parser (); | ||
parser.load_from_data (val.to_string ()); | ||
|
||
var root = parser.get_root (); | ||
var message_type = root.get_object ().get_string_member ("type"); | ||
var root_object = root.get_object (); | ||
var message_type = root_object.get_string_member ("type"); | ||
var message_data = root_object.get_member ("data"); | ||
|
||
switch (message_type) { | ||
case "unreadMailCount": | ||
var unread_data = Json.gobject_deserialize (typeof (UnreadData), root) as UnreadData; | ||
var unread_data = Json.gobject_deserialize (typeof (UnreadData), message_data) as UnreadData; | ||
assert (unread_data != null); | ||
print ("unread count: %d\n", unread_data.numUnread); | ||
|
||
debug ("Received unread count of %d", unread_data.num_unread); | ||
// TODO: do something with this count | ||
break; | ||
case "newMessageNotifications": | ||
var notification_data = Json.gobject_deserialize (typeof (NotificationData), root) as NotificationData; | ||
assert (notification_data != null); | ||
print ("notifications: %d\n", notification_data.notificationData.length); | ||
var notification_data = message_data.get_object (); | ||
var notification_array = notification_data.get_array_member ("notificationData"); | ||
|
||
debug ("Received %u new message notifications", notification_array.get_length ()); | ||
|
||
foreach (var element in notification_array.get_elements ()) { | ||
var notification_item = Json.gobject_deserialize (typeof (NotificationItem), element) as NotificationItem; | ||
assert (notification_item != null); | ||
display_notification (notification_item); | ||
} | ||
break; | ||
default: | ||
print ("Received unknown message %s\n", val.to_string ()); | ||
debug ("Received unknown message %s", val.to_string ()); | ||
break; | ||
} | ||
} | ||
|
||
public MessageHandler (WebKit.WebView webview) { | ||
this.webview = webview; | ||
|
||
var content_manager = webview.get_user_content_manager (); | ||
content_manager.add_script (this.script); | ||
content_manager.script_message_received.connect (this.on_script_message); | ||
content_manager.register_script_message_handler ("skiffDesktop", null); | ||
} | ||
} |