diff --git a/src/notifier/__init__.py b/src/notifier/__init__.py index 345350b7..bceb9c1a 100644 --- a/src/notifier/__init__.py +++ b/src/notifier/__init__.py @@ -13,7 +13,7 @@ else: from utils.readstatic import get_static_dir import config - +from onionrplugins.onionrevents import event as plugin_api_event """ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -34,16 +34,22 @@ if not config.get('general.show_notifications', True): notification_sound_file = get_static_dir() + "sounds/notification1.mp3" + def notify(title: str = "Onionr", message: str = ""): """Cross platform method to show a notification.""" if not notifications_enabled: return + plugin_api_event("notification", data={"title": title, "message": message}) simplenotify.notify(title, message) def notification_with_sound(sound = '', **kwargs): + if not notifications_enabled: + return + if not sound: + sound = notification_sound_file try: - Popen(["mpv", notification_sound_file]) + Popen(["mpv", sound]) except FileNotFoundError: pass notify(**kwargs) diff --git a/src/onionrcommands/daemonlaunch/quotes.py b/src/onionrcommands/daemonlaunch/quotes.py index 099afc33..5cdf547f 100644 --- a/src/onionrcommands/daemonlaunch/quotes.py +++ b/src/onionrcommands/daemonlaunch/quotes.py @@ -19,7 +19,7 @@ QUOTES = [ ("Freedom of the press is guaranteed only to those who own one", "A. J. Liebling"), ("We kill people based on metadata", - "Authoritarians") + "") ] shuffle(QUOTES) QUOTE = QUOTES[0] diff --git a/src/utils/readstatic.py b/src/utils/readstatic.py index 44b0b5ea..59b331c0 100644 --- a/src/utils/readstatic.py +++ b/src/utils/readstatic.py @@ -2,6 +2,8 @@ get static directory and read static data files """ +from typing import Union +import os """ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,9 +19,6 @@ get static directory and read static data files along with this program. If not, see . """ -from typing import Union -import os - def get_static_dir()->str: return os.path.dirname(os.path.realpath(__file__)) + '/../../static-data/' diff --git a/static-data/default-plugins/pms/info.json b/static-data/default-plugins/pms/info.json index 454b9bd6..55c20967 100755 --- a/static-data/default-plugins/pms/info.json +++ b/static-data/default-plugins/pms/info.json @@ -1,5 +1,5 @@ { "name" : "pms", - "version" : "1.0", + "version" : "0.1.0", "author" : "onionr" } diff --git a/static-data/default-plugins/pms/main.py b/static-data/default-plugins/pms/main.py index 20fa87b4..f1984707 100755 --- a/static-data/default-plugins/pms/main.py +++ b/static-data/default-plugins/pms/main.py @@ -1,9 +1,17 @@ -''' - Onionr - Private P2P Communication +"""Onionr - Private P2P Communication. - This default plugin handles private messages in an email like fashion -''' -''' +Private messages in an email like fashion +""" +import locale +import sys +import os +import json + +from onionrusers import contactmanager +from utils import reconstructhash +from onionrutils import bytesconverter +import notifier +""" This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or @@ -16,21 +24,12 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . -''' - -# Imports some useful libraries -import logger, config, threading, time, datetime -import onionrexceptions -from onionrusers import onionrusers, contactmanager -from utils import reconstructhash -from onionrutils import stringvalidators, escapeansi, bytesconverter -import notifier -import locale, sys, os, json +""" locale.setlocale(locale.LC_ALL, '') plugin_name = 'pms' -PLUGIN_VERSION = '0.0.1' +PLUGIN_VERSION = '0.1.0' sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) import sentboxdb, mailapi, loadinbox # import after path insert @@ -39,6 +38,7 @@ from onblacklist import on_blacklist_add flask_blueprint = mailapi.flask_blueprint security_whitelist = ['staticfiles.mail', 'staticfiles.mailindex'] + def add_deleted(keyStore, b_hash): existing = keyStore.get('deleted_mail') bHash = reconstructhash.reconstruct_hash(b_hash) @@ -49,12 +49,14 @@ def add_deleted(keyStore, b_hash): return keyStore.put('deleted_mail', existing.append(b_hash)) + def on_insertblock(api, data={}): meta = json.loads(data['meta']) if meta['type'] == 'pm': sentboxTools = sentboxdb.SentBox() sentboxTools.addToSent(data['hash'], data['peer'], data['content'], meta['subject']) + def on_processblocks(api, data=None): if data['type'] != 'pm': return diff --git a/static-data/sounds/notification1.mp3 b/static-data/sounds/notification1.mp3 new file mode 100644 index 00000000..8021af73 Binary files /dev/null and b/static-data/sounds/notification1.mp3 differ diff --git a/static-data/www/mail/index.html b/static-data/www/mail/index.html index 62164c50..e154c49e 100755 --- a/static-data/www/mail/index.html +++ b/static-data/www/mail/index.html @@ -143,17 +143,30 @@
Ask senders to use forward-secrecy
- Only turn off if you use multiple devices with 1 ID or have Onionr data erasure on exit enabled. + Turn off if using 1 ID on more than 1 device, or have Onionr data erasure on exit enabled.
+ class="switch is-rounded is-danger" checked>
-
+
+
+
Message padding
+ Improves privacy slightly for a small performance hit. +
+
+
+ + +
+
+
+
Keep messages when blocks are deleted
@@ -165,21 +178,47 @@
- Signature - -
+
+ Inbox notifications +
+
+
+ + +
+
+
+
+
+ Only show notifications for friends +
+
+
+ + +
+
+
+
+
+ Notification sound
- + +
+ Signature +
-
diff --git a/static-data/www/mail/loadsettings.js b/static-data/www/mail/loadsettings.js new file mode 100644 index 00000000..36189b1a --- /dev/null +++ b/static-data/www/mail/loadsettings.js @@ -0,0 +1,14 @@ +mailSettings = {} + +fetch('/config/get/mail', { + headers: { + "content-type": "application/json", + "token": webpass + }}) +.then((resp) => resp.json()) +.then(function(settings) { + mailSettings = settings || {} + if (mailSettings.default_forward_secrecy === false){ + document.getElementById('forwardSecrecySetting').checked = false + } + }) \ No newline at end of file diff --git a/static-data/www/mail/mail.css b/static-data/www/mail/mail.css index 4f778698..45099b0b 100755 --- a/static-data/www/mail/mail.css +++ b/static-data/www/mail/mail.css @@ -55,3 +55,7 @@ margin-top: 1em; } +#settingsModal small{ + font-size: 0.5em; +} + diff --git a/static-data/www/mail/settings.js b/static-data/www/mail/settings.js index 605d6b71..a938632f 100644 --- a/static-data/www/mail/settings.js +++ b/static-data/www/mail/settings.js @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - +var notificationSetting = document.getElementById('notificationSetting') document.getElementById('forwardSecrecySetting').onchange = function(e){ postData = JSON.stringify({"default_forward_secrecy": e.target.checked}) fetch('/config/set/mail', { @@ -34,3 +34,18 @@ document.getElementById('forwardSecrecySetting').onchange = function(e){ }) }) } + + +notificationSetting.onchange = function(e){ + let notificationSettings = document.getElementsByClassName('notificationSetting') + if (e.target.checked){ + for (i = 0; i < notificationSettings.length; i++){ + notificationSettings[i].style.display = "flex" + } + } + else{ + for (i = 0; i < notificationSettings.length; i++){ + notificationSettings[i].style.display = "none" + } + } +} \ No newline at end of file