added sound notifications (used in mail for now) and more settings UI work
This commit is contained in:
parent
aea4815fbd
commit
83ef9dc3ca
@ -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)
|
||||
|
@ -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]
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from typing import Union
|
||||
import os
|
||||
|
||||
|
||||
def get_static_dir()->str:
|
||||
return os.path.dirname(os.path.realpath(__file__)) + '/../../static-data/'
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name" : "pms",
|
||||
"version" : "1.0",
|
||||
"version" : "0.1.0",
|
||||
"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
|
||||
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 <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, '')
|
||||
|
||||
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
|
||||
|
BIN
static-data/sounds/notification1.mp3
Normal file
BIN
static-data/sounds/notification1.mp3
Normal file
Binary file not shown.
@ -143,17 +143,30 @@
|
||||
<div class="columns">
|
||||
<div class="column">
|
||||
<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 class="column is-2">
|
||||
<div class="field">
|
||||
<input id="forwardSecrecySetting" type="checkbox"
|
||||
class="switch is-rounded is-warning" checked>
|
||||
class="switch is-rounded is-danger" checked>
|
||||
<label for="forwardSecrecySetting"></label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="columns">
|
||||
<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="column">
|
||||
Keep messages when blocks are deleted
|
||||
</div>
|
||||
@ -165,21 +178,47 @@
|
||||
</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">
|
||||
Inbox notifications
|
||||
</div>
|
||||
<div class="column is-2">
|
||||
<div class="field">
|
||||
<input id="notificationSetting" type="checkbox"
|
||||
class="switch is-rounded" checked>
|
||||
<label for="notificationSetting"></label>
|
||||
</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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--Start of content-->
|
||||
<div class="container">
|
||||
<div class="tabs" id="tabBtns">
|
||||
|
14
static-data/www/mail/loadsettings.js
Normal file
14
static-data/www/mail/loadsettings.js
Normal file
@ -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;
|
||||
}
|
||||
|
||||
#settingsModal small{
|
||||
font-size: 0.5em;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user