Replace FolderList.Tree mail hooks with plugin
Using a plugin to manage folder new mail highlighting so it works in the same way as for other notifications.
This commit is contained in:
parent
df7889d732
commit
c72ce8d8da
7 changed files with 129 additions and 14 deletions
|
|
@ -97,6 +97,8 @@ src/client/plugin/plugin-plugin-base.vala
|
|||
src/client/plugin/plugin-trusted-etension.vala
|
||||
src/client/plugin/desktop-notifications/desktop-notifications.plugin.in
|
||||
src/client/plugin/desktop-notifications/desktop-notifications.vala
|
||||
src/client/plugin/folder-highlight/folder-highlight.plugin.in
|
||||
src/client/plugin/folder-highlight/folder-highlight.vala
|
||||
src/client/plugin/messaging-menu/messaging-menu.plugin.in
|
||||
src/client/plugin/messaging-menu/messaging-menu.vala
|
||||
src/client/plugin/notification-badge/notification-badge.plugin.in
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ public class Application.PluginManager : GLib.Object {
|
|||
// application stats up
|
||||
private const string[] AUTOLOAD_MODULES = {
|
||||
"desktop-notifications",
|
||||
"folder-highlight",
|
||||
"notification-badge",
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -14,11 +14,6 @@ public class FolderList.Tree : Sidebar.Tree, Geary.BaseInterface {
|
|||
private const int INBOX_ORDINAL = -2; // First account branch is zero
|
||||
private const int SEARCH_ORDINAL = -1;
|
||||
|
||||
private const Geary.SpecialFolderType[] INTERESTING_FOLDERS = {
|
||||
INBOX,
|
||||
NONE
|
||||
};
|
||||
|
||||
|
||||
public signal void folder_selected(Geary.Folder? folder);
|
||||
public signal void copy_conversation(Geary.Folder folder);
|
||||
|
|
@ -113,7 +108,6 @@ public class FolderList.Tree : Sidebar.Tree, Geary.BaseInterface {
|
|||
if (folder.special_folder_type == Geary.SpecialFolderType.INBOX)
|
||||
inboxes_branch.add_inbox(folder);
|
||||
|
||||
folder.email_locally_appended.connect(on_email_appended);
|
||||
account_branch.add_folder(folder);
|
||||
}
|
||||
|
||||
|
|
@ -141,7 +135,6 @@ public class FolderList.Tree : Sidebar.Tree, Geary.BaseInterface {
|
|||
if (folder.special_folder_type == Geary.SpecialFolderType.INBOX)
|
||||
inboxes_branch.remove_inbox(folder.account);
|
||||
|
||||
folder.email_locally_appended.disconnect(on_email_appended);
|
||||
account_branch.remove_folder(folder);
|
||||
}
|
||||
|
||||
|
|
@ -269,11 +262,4 @@ public class FolderList.Tree : Sidebar.Tree, Geary.BaseInterface {
|
|||
graft(branch, branch.account.information.ordinal);
|
||||
}
|
||||
|
||||
private void on_email_appended(Geary.Folder folder,
|
||||
Gee.Collection<Geary.EmailIdentifier> ids) {
|
||||
if (folder.special_folder_type in INTERESTING_FOLDERS) {
|
||||
set_has_new(folder, true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
[Plugin]
|
||||
Module=folder-highlight
|
||||
Name=Folder Highlight
|
||||
Description=Highlights folders that have newly delivered mail
|
||||
95
src/client/plugin/folder-highlight/folder-highlight.vala
Normal file
95
src/client/plugin/folder-highlight/folder-highlight.vala
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Copyright © 2016 Software Freedom Conservancy Inc.
|
||||
* Copyright © 2019-2020 Michael Gratton <mike@vee.net>.
|
||||
*
|
||||
* This software is licensed under the GNU Lesser General Public License
|
||||
* (version 2.1 or later). See the COPYING file in this distribution.
|
||||
*/
|
||||
|
||||
[ModuleInit]
|
||||
public void peas_register_types(TypeModule module) {
|
||||
Peas.ObjectModule obj = module as Peas.ObjectModule;
|
||||
obj.register_extension_type(
|
||||
typeof(Plugin.PluginBase),
|
||||
typeof(Plugin.FolderHighlight)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Manages highlighting folders that have newly delivered mail
|
||||
*/
|
||||
public class Plugin.FolderHighlight :
|
||||
PluginBase, NotificationExtension, TrustedExtension {
|
||||
|
||||
|
||||
private const Geary.SpecialFolderType[] MONITORED_TYPES = {
|
||||
INBOX, NONE
|
||||
};
|
||||
|
||||
|
||||
public NotificationContext notifications {
|
||||
get; construct set;
|
||||
}
|
||||
|
||||
public global::Application.Client client_application {
|
||||
get; construct set;
|
||||
}
|
||||
|
||||
public global::Application.PluginManager client_plugins {
|
||||
get; construct set;
|
||||
}
|
||||
|
||||
public override async void activate() throws GLib.Error {
|
||||
this.notifications.new_messages_arrived.connect(on_new_messages_arrived);
|
||||
this.notifications.new_messages_retired.connect(on_new_messages_retired);
|
||||
|
||||
FolderStore folders = yield this.notifications.get_folders();
|
||||
folders.folders_available.connect(
|
||||
(folders) => check_folders(folders)
|
||||
);
|
||||
folders.folders_unavailable.connect(
|
||||
(folders) => check_folders(folders)
|
||||
);
|
||||
folders.folders_type_changed.connect(
|
||||
(folders) => check_folders(folders)
|
||||
);
|
||||
check_folders(folders.get_folders());
|
||||
}
|
||||
|
||||
public override async void deactivate(bool is_shutdown) throws GLib.Error {
|
||||
// no-op
|
||||
}
|
||||
|
||||
private void check_folders(Gee.Collection<Folder> folders) {
|
||||
foreach (Folder folder in folders) {
|
||||
if (folder.folder_type in MONITORED_TYPES) {
|
||||
this.notifications.start_monitoring_folder(folder);
|
||||
} else {
|
||||
this.notifications.stop_monitoring_folder(folder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void on_new_messages_arrived(Folder folder,
|
||||
int total,
|
||||
Gee.Collection<EmailIdentifier> added) {
|
||||
Geary.Folder? engine = this.client_plugins.get_engine_folder(folder);
|
||||
if (engine != null) {
|
||||
foreach (global::Application.MainWindow window
|
||||
in this.client_application.get_main_windows()) {
|
||||
window.folder_list.set_has_new(engine, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void on_new_messages_retired(Folder folder, int total) {
|
||||
Geary.Folder? engine = this.client_plugins.get_engine_folder(folder);
|
||||
if (engine != null) {
|
||||
foreach (global::Application.MainWindow window
|
||||
in this.client_application.get_main_windows()) {
|
||||
window.folder_list.set_has_new(engine, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
26
src/client/plugin/folder-highlight/meson.build
Normal file
26
src/client/plugin/folder-highlight/meson.build
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
plugin_name = 'folder-highlight'
|
||||
|
||||
plugin_src = join_paths(plugin_name + '.vala')
|
||||
plugin_data = join_paths(plugin_name + '.plugin')
|
||||
plugin_dest = join_paths(plugins_dir, plugin_name)
|
||||
|
||||
shared_module(
|
||||
plugin_name,
|
||||
sources: plugin_src,
|
||||
dependencies: plugin_dependencies,
|
||||
include_directories: config_h_dir,
|
||||
vala_args: geary_vala_args,
|
||||
c_args: plugin_c_args,
|
||||
install: true,
|
||||
install_dir: plugin_dest
|
||||
)
|
||||
|
||||
i18n.merge_file(
|
||||
input: plugin_data + '.in',
|
||||
output: plugin_data,
|
||||
type: 'desktop',
|
||||
po_dir: po_dir,
|
||||
install: true,
|
||||
install_dir: plugin_dest
|
||||
)
|
||||
|
|
@ -23,5 +23,6 @@ plugin_dependencies = [
|
|||
plugin_c_args = geary_c_args
|
||||
|
||||
subdir('desktop-notifications')
|
||||
subdir('folder-highlight')
|
||||
subdir('messaging-menu')
|
||||
subdir('notification-badge')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue