This commit is contained in:
Ximi1970
2020-01-12 19:12:34 +01:00
parent dcd54fe201
commit 1b57cff6d3
6 changed files with 124 additions and 1 deletions

16
app/README.md Normal file
View File

@@ -0,0 +1,16 @@
# SysTray-X App
Please be aware that the JSON file needs to be installed in the:
.mozilla (Firefox) config directory
and NOT in the .thunderbird (Thunderbird) config dir.
## Donations
To support this project, you can make a donation to its current maintainer:
[![paypal](https://github.com/Ximi1970/Donate/blob/master/paypal_btn_donateCC_LG_2.gif)](https://paypal.me/Ximi1970)
[![bitcoin-qrcode-black](https://github.com/Ximi1970/Donate/blob/master/bitcoin-donate-qrcode-black.png)](https://raw.githubusercontent.com/Ximi1970/Donate/master/bitcoin-address.txt)

14
app/install-linux.sh Executable file
View File

@@ -0,0 +1,14 @@
#!/bin/bash
if [ -z $1 ] ; then
echo "Usage: $0 <tb-config-path>"
exit 1
fi
mkdir .mozilla/native-messaging-hosts
#mkdir .mozilla/managed-storage
#mkdir .mozilla/pkcs11-modules
cp ping_pong.json .mozilla/native-messaging-hosts/ping_pong.json
#cp ping_pong.json .mozilla/managed-storage/ping_pong.json
#cp ping_pong.json .mozilla/pkcs11-modules/ping_pong.json

7
app/ping_pong.json Normal file
View File

@@ -0,0 +1,7 @@
{
"name": "ping_pong",
"description": "Example host for native messaging",
"path": "/home/maxime/Diskstation/github/Ximi1970/systray-x/app/ping_pong.py",
"type": "stdio",
"allowed_extensions": [ "systray-x@Ximi1970" ]
}

63
app/ping_pong.py Executable file
View File

@@ -0,0 +1,63 @@
#!/usr/bin/python
import sys
import json
import struct
try:
# Python 3.x version
# Read a message from stdin and decode it.
def getMessage():
rawLength = sys.stdin.buffer.read(4)
if len(rawLength) == 0:
sys.exit(0)
messageLength = struct.unpack('@I', rawLength)[0]
message = sys.stdin.buffer.read(messageLength).decode('utf-8')
return json.loads(message)
# Encode a message for transmission,
# given its content.
def encodeMessage(messageContent):
encodedContent = json.dumps(messageContent).encode('utf-8')
encodedLength = struct.pack('@I', len(encodedContent))
return {'length': encodedLength, 'content': encodedContent}
# Send an encoded message to stdout
def sendMessage(encodedMessage):
sys.stdout.buffer.write(encodedMessage['length'])
sys.stdout.buffer.write(encodedMessage['content'])
sys.stdout.buffer.flush()
while True:
receivedMessage = getMessage()
if receivedMessage == "ping":
sendMessage(encodeMessage("pong3"))
except AttributeError:
# Python 2.x version (if sys.stdin.buffer is not defined)
# Read a message from stdin and decode it.
def getMessage():
rawLength = sys.stdin.read(4)
if len(rawLength) == 0:
sys.exit(0)
messageLength = struct.unpack('@I', rawLength)[0]
message = sys.stdin.read(messageLength)
return json.loads(message)
# Encode a message for transmission,
# given its content.
def encodeMessage(messageContent):
encodedContent = json.dumps(messageContent)
encodedLength = struct.pack('@I', len(encodedContent))
return {'length': encodedLength, 'content': encodedContent}
# Send an encoded message to stdout
def sendMessage(encodedMessage):
sys.stdout.write(encodedMessage['length'])
sys.stdout.write(encodedMessage['content'])
sys.stdout.flush()
while True:
receivedMessage = getMessage()
if receivedMessage == "ping":
sendMessage(encodeMessage("pong2"))

View File

@@ -99,6 +99,29 @@ console.log("Starting SysTray-X");
SysTrayX.Messaging.init();
/*
* Start native messaging
*/
var port = browser.runtime.connectNative("ping_pong");
// Listen for messages from the app.
port.onMessage.addListener((response) => {
console.log("Received: " + response);
});
// Every second, send the app a message.
function ping() {
console.log("Sending: ping");
port.postMessage("ping");
}
window.setInterval(ping, 1000);
/*
* Poll the accounts
*/
function pollAccounts() {
console.debug("Polling");

View File

@@ -19,7 +19,7 @@
"default_locale": "en-US",
"permissions": ["accountsRead", "messagesRead", "storage"],
"permissions": ["accountsRead", "messagesRead", "storage", "nativeMessaging"],
"background": {
"page": "background.html"