Skip to content

Commit

Permalink
New Extension Binding
Browse files Browse the repository at this point in the history
Adapted to NeutralinoJS > 4.15.0
  • Loading branch information
hschneider committed Jan 14, 2024
1 parent 9a1bb9d commit 51df654
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
44 changes: 32 additions & 12 deletions extensions/python/NeutralinoExtension.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# pypy -m pip install --no-binary :all: simple-websocket
# pypy -m pip install --no-binary :all: simple-websocket-server
#
# (c)2023 Harald Schneider - marketmix.com
# (c)2023-2024 Harald Schneider - marketmix.com

from argparse import *
import uuid, json, time, asyncio, sys, os, signal, subprocess
Expand All @@ -17,29 +17,48 @@
class NeutralinoExtension:
def __init__(self, debug=False):

self.version = "1.1.9"

parser = ArgumentParser()
parser.add_argument('--nl-port')
parser.add_argument('--nl-token')
parser.add_argument('--nl-extension-id')
args = parser.parse_args()
self.version = "1.2.1"

self.debug = debug
self.debugTermColors = True # Use terminal colors
self.debugTermColorIN = "\033[32m" # Green: All incoming events, except function calls
self.debugTermColorCALL = "\033[91m" # Red: Incoming function calls
self.debugTermColorOUT = "\033[33m" # Yellow: Outgoing events

self.port = args.nl_port
self.token = args.nl_token
self.idExtension = args.nl_extension_id
self.urlSocket = f"ws://127.0.0.1:{self.port}?extensionId={self.idExtension}"
if len(sys.argv) > 1:
parser = ArgumentParser()
parser.add_argument('--nl-port')
parser.add_argument('--nl-token')
parser.add_argument('--nl-extension-id')
args = parser.parse_args()

self.port = args.nl_port
self.token = args.nl_token
self.idExtension = args.nl_extension_id
self.connectToken = ''
self.urlSocket = f"ws://127.0.0.1:{self.port}?extensionId={self.idExtension}"
else:
conf = json.loads(sys.stdin.read())
self.port = conf['nlPort']
self.token = conf['nlToken']
self.idExtension = conf['nlExtensionId']
self.connectToken = conf['nlConnectToken']
self.urlSocket = f"ws://127.0.0.1:{self.port}?extensionId={self.idExtension}&connectToken={self.connectToken}"

self.debugLog('---')
self.debugLog("Received extension config via stdin:")
self.debugLog(json.dumps(conf, indent=4))
self.debugLog('---')
self.debugLog('WebSocket URL is:')
self.debugLog(self.urlSocket)

self.qSend = Queue()

self.termOnWindowClose = True # Terminate on windowCloseEvent message

self.debugLog('---')
self.debugLog(f"{self.idExtension} running on port {self.port}")
self.debugLog('---')

def sendMessage(self, event, data=None):
"""
Expand Down Expand Up @@ -104,6 +123,7 @@ async def run(self, onReceiveMessage):
onReceiveMessage(msg)

except (KeyboardInterrupt, EOFError, ConnectionClosed):
self.debugLog('WebSocket closed.')
await self.socket.close()

def parseFunctionCall(self, d):
Expand Down
2 changes: 1 addition & 1 deletion neutralino.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"resourcesPath": "/resources/",
"extensionsPath": "/extensions/",
"clientLibrary": "/resources/js/neutralino.js",
"binaryVersion": "4.15.0",
"binaryVersion": "nightly",
"clientVersion": "3.13.0"
},
"extensions": [
Expand Down
2 changes: 1 addition & 1 deletion resources/js/neutralino.js.map

Large diffs are not rendered by default.

0 comments on commit 51df654

Please sign in to comment.