added sound notifications (used in mail for now) and more settings UI work
parent
aea4815fbd
commit
83ef9dc3ca
|
@ -13,7 +13,7 @@ else:
|
||||||
|
|
||||||
from utils.readstatic import get_static_dir
|
from utils.readstatic import get_static_dir
|
||||||
import config
|
import config
|
||||||
|
from onionrplugins.onionrevents import event as plugin_api_event
|
||||||
"""
|
"""
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
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"
|
notification_sound_file = get_static_dir() + "sounds/notification1.mp3"
|
||||||
|
|
||||||
|
|
||||||
def notify(title: str = "Onionr", message: str = ""):
|
def notify(title: str = "Onionr", message: str = ""):
|
||||||
"""Cross platform method to show a notification."""
|
"""Cross platform method to show a notification."""
|
||||||
if not notifications_enabled:
|
if not notifications_enabled:
|
||||||
return
|
return
|
||||||
|
plugin_api_event("notification", data={"title": title, "message": message})
|
||||||
simplenotify.notify(title, message)
|
simplenotify.notify(title, message)
|
||||||
|
|
||||||
|
|
||||||
def notification_with_sound(sound = '', **kwargs):
|
def notification_with_sound(sound = '', **kwargs):
|
||||||
|
if not notifications_enabled:
|
||||||
|
return
|
||||||
|
if not sound:
|
||||||
|
sound = notification_sound_file
|
||||||
try:
|
try:
|
||||||
Popen(["mpv", notification_sound_file])
|
Popen(["mpv", sound])
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
notify(**kwargs)
|
notify(**kwargs)
|
||||||
|
|
|
@ -19,7 +19,7 @@ QUOTES = [
|
||||||
("Freedom of the press is guaranteed only to those who own one",
|
("Freedom of the press is guaranteed only to those who own one",
|
||||||
"A. J. Liebling"),
|
"A. J. Liebling"),
|
||||||
("We kill people based on metadata",
|
("We kill people based on metadata",
|
||||||
"Authoritarians")
|
"")
|
||||||
]
|
]
|
||||||
shuffle(QUOTES)
|
shuffle(QUOTES)
|
||||||
QUOTE = QUOTES[0]
|
QUOTE = QUOTES[0]
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
get static directory and read static data files
|
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
|
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
|
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 <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import Union
|
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
def get_static_dir()->str:
|
def get_static_dir()->str:
|
||||||
return os.path.dirname(os.path.realpath(__file__)) + '/../../static-data/'
|
return os.path.dirname(os.path.realpath(__file__)) + '/../../static-data/'
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name" : "pms",
|
"name" : "pms",
|
||||||
"version" : "1.0",
|
"version" : "0.1.0",
|
||||||
"author" : "onionr"
|
"author" : "onionr"
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
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
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
'''
|
"""
|
||||||
|
|
||||||
# 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, '')
|
locale.setlocale(locale.LC_ALL, '')
|
||||||
|
|
||||||
plugin_name = 'pms'
|
plugin_name = 'pms'
|
||||||
PLUGIN_VERSION = '0.0.1'
|
PLUGIN_VERSION = '0.1.0'
|
||||||
|
|
||||||
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
||||||
import sentboxdb, mailapi, loadinbox # import after path insert
|
import sentboxdb, mailapi, loadinbox # import after path insert
|
||||||
|
@ -39,6 +38,7 @@ from onblacklist import on_blacklist_add
|
||||||
flask_blueprint = mailapi.flask_blueprint
|
flask_blueprint = mailapi.flask_blueprint
|
||||||
security_whitelist = ['staticfiles.mail', 'staticfiles.mailindex']
|
security_whitelist = ['staticfiles.mail', 'staticfiles.mailindex']
|
||||||
|
|
||||||
|
|
||||||
def add_deleted(keyStore, b_hash):
|
def add_deleted(keyStore, b_hash):
|
||||||
existing = keyStore.get('deleted_mail')
|
existing = keyStore.get('deleted_mail')
|
||||||
bHash = reconstructhash.reconstruct_hash(b_hash)
|
bHash = reconstructhash.reconstruct_hash(b_hash)
|
||||||
|
@ -49,12 +49,14 @@ def add_deleted(keyStore, b_hash):
|
||||||
return
|
return
|
||||||
keyStore.put('deleted_mail', existing.append(b_hash))
|
keyStore.put('deleted_mail', existing.append(b_hash))
|
||||||
|
|
||||||
|
|
||||||
def on_insertblock(api, data={}):
|
def on_insertblock(api, data={}):
|
||||||
meta = json.loads(data['meta'])
|
meta = json.loads(data['meta'])
|
||||||
if meta['type'] == 'pm':
|
if meta['type'] == 'pm':
|
||||||
sentboxTools = sentboxdb.SentBox()
|
sentboxTools = sentboxdb.SentBox()
|
||||||
sentboxTools.addToSent(data['hash'], data['peer'], data['content'], meta['subject'])
|
sentboxTools.addToSent(data['hash'], data['peer'], data['content'], meta['subject'])
|
||||||
|
|
||||||
|
|
||||||
def on_processblocks(api, data=None):
|
def on_processblocks(api, data=None):
|
||||||
if data['type'] != 'pm':
|
if data['type'] != 'pm':
|
||||||
return
|
return
|
||||||
|
|
Binary file not shown.
|
@ -143,16 +143,29 @@
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<div>Ask senders to use forward-secrecy</div>
|
<div>Ask senders to use forward-secrecy</div>
|
||||||
<small>Only turn off if you use multiple devices with 1 ID or have Onionr data erasure on exit enabled.</small>
|
<small>Turn off if using 1 ID on more than 1 device, or have Onionr data erasure on exit enabled.</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="column is-2">
|
<div class="column is-2">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<input id="forwardSecrecySetting" type="checkbox"
|
<input id="forwardSecrecySetting" type="checkbox"
|
||||||
class="switch is-rounded is-warning" checked>
|
class="switch is-rounded is-danger" checked>
|
||||||
<label for="forwardSecrecySetting"></label>
|
<label for="forwardSecrecySetting"></label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="columns">
|
||||||
|
<div class="column">
|
||||||
|
<div>Message padding</div>
|
||||||
|
<small>Improves privacy slightly for a small performance hit.</small>
|
||||||
|
</div>
|
||||||
|
<div class="column is-2">
|
||||||
|
<div class="field">
|
||||||
|
<input id="messagePadding" type="checkbox"
|
||||||
|
class="switch is-rounded is-warning" checked>
|
||||||
|
<label for="messagePadding"></label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
<div class="column">
|
<div class="column">
|
||||||
Keep messages when blocks are deleted
|
Keep messages when blocks are deleted
|
||||||
|
@ -165,21 +178,47 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
Signature
|
|
||||||
<textarea id="mailSignatureSetting" class="textarea" placeholder="Signature to add to every message" rows="5"></textarea>
|
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
<div class="column">
|
<div class="column">
|
||||||
|
Inbox notifications
|
||||||
</div>
|
</div>
|
||||||
<div class="column is-2">
|
<div class="column is-2">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
|
<input id="notificationSetting" type="checkbox"
|
||||||
|
class="switch is-rounded" checked>
|
||||||
|
<label for="notificationSetting"></label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="columns notificationSetting">
|
||||||
|
<div class="column">
|
||||||
|
Only show notifications for friends
|
||||||
|
</div>
|
||||||
|
<div class="column is-2">
|
||||||
|
<div class="field">
|
||||||
|
<input id="friendsOnlyNotifications" type="checkbox"
|
||||||
|
class="switch is-rounded">
|
||||||
|
<label for="friendsOnlyNotifications"></label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="columns notificationSetting">
|
||||||
|
<div class="column">
|
||||||
|
Notification sound
|
||||||
|
</div>
|
||||||
|
<div class="column is-2">
|
||||||
|
<div class="field">
|
||||||
|
<input id="audibleNotificationSetting" type="checkbox"
|
||||||
|
class="switch is-rounded">
|
||||||
|
<label for="audibleNotificationSetting"></label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
Signature
|
||||||
|
<textarea id="mailSignatureSetting" class="textarea" placeholder="Signature to add to every message" rows="5"></textarea>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!--Start of content-->
|
<!--Start of content-->
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="tabs" id="tabBtns">
|
<div class="tabs" id="tabBtns">
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
})
|
|
@ -55,3 +55,7 @@
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#settingsModal small{
|
||||||
|
font-size: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
var notificationSetting = document.getElementById('notificationSetting')
|
||||||
document.getElementById('forwardSecrecySetting').onchange = function(e){
|
document.getElementById('forwardSecrecySetting').onchange = function(e){
|
||||||
postData = JSON.stringify({"default_forward_secrecy": e.target.checked})
|
postData = JSON.stringify({"default_forward_secrecy": e.target.checked})
|
||||||
fetch('/config/set/mail', {
|
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue