add edge addon publish scripts

This commit is contained in:
jianxin committed 2023-11-04 07:13:35 +08:00
1 parent 5c3f15c70e
commit 5dba81e4a4
27 files changed
+889 -792

No files matched your search

+4 -4
View File
@@ -1,4 +1,4 @@
@echo off
python "%~dp0/native-messaging-example-host" %*
@echo off
python "%~dp0/native-messaging-example-host" %*
+19 -19
View File
@@ -1,19 +1,19 @@
import win32pipe
import win32file
# 连接到命名管道
pipe_name = r'\\.\pipe\botext'
pipe = win32file.CreateFile(
pipe_name,
win32file.GENERIC_READ | win32file.GENERIC_WRITE,
0,
None,
win32file.OPEN_EXISTING,
0,
None
)
win32file.WriteFile(pipe, b'close1')
# 关闭管道
win32file.CloseHandle(pipe)
import win32pipe
import win32file
# 连接到命名管道
pipe_name = r'\\.\pipe\botext'
pipe = win32file.CreateFile(
pipe_name,
win32file.GENERIC_READ | win32file.GENERIC_WRITE,
0,
None,
win32file.OPEN_EXISTING,
0,
None
)
win32file.WriteFile(pipe, b'close1')
# 关闭管道
win32file.CloseHandle(pipe)
+9 -9
View File
@@ -1,9 +1,9 @@
{
"name": "com.woni.chrome.botext",
"description": "botext",
"path": "D:\\CS\\BotBridge\\bin\\Debug\\net8.0\\BotBridge.exe",
"type": "stdio",
"allowed_origins": [
"chrome-extension://hhfenmonendjidnaibblhgkapmbncmnp/"
]
}
{
"name": "com.woni.chrome.botext",
"description": "botext",
"path": "D:\\CS\\BotBridge\\bin\\Debug\\net8.0\\BotBridge.exe",
"type": "stdio",
"allowed_origins": [
"chrome-extension://hhfenmonendjidnaibblhgkapmbncmnp/"
]
}
+82 -82
View File
@@ -1,82 +1,82 @@
import sys
import struct
import ctypes
import threading
import win32pipe
import win32file
pipe_name = r"\\.\pipe\botext"
pipe_access = win32pipe.PIPE_ACCESS_DUPLEX
pipe_type =win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_WAIT | win32pipe.PIPE_READMODE_MESSAGE
pipe_mode = win32pipe.PIPE_UNLIMITED_INSTANCES
max_instances = 65536
out_buffer_size = 65536
default_time_out = 0
security_attributes = None
pipe = win32pipe.CreateNamedPipe(
pipe_name,
pipe_access,
pipe_type,
pipe_mode,
max_instances,
out_buffer_size,
default_time_out,
security_attributes,
)
def write_data(data):
msglen = len(data)
msglen_bytes = struct.pack("=I", msglen)
sys.stdout.buffer.write(msglen_bytes)
sys.stdout.buffer.write(data.encode())
sys.stdout.buffer.flush()
def read_thread_func():
while True:
raw_msglen = sys.stdin.buffer.read(4)
if not raw_msglen:
sys.exit(0)
msglen = struct.unpack("=I", raw_msglen)[0]
# Read the message data
data = sys.stdin.buffer.read(msglen)
ctypes.windll.user32.MessageBoxW(0, data.decode(), "BotExt", 0)
write_data('{"msg": "bridge"}')
def namepipe_server(pipe):
try:
while True:
win32pipe.ConnectNamedPipe(pipe, None)
_, data = win32file.ReadFile(pipe, 4096)
if data == b"close":
sys.exit(0)
print(data)
write_data('{"msg": "client"}')
# ctypes.windll.user32.MessageBoxW(0, "hi", "BotExt", 0)
win32pipe.DisconnectNamedPipe(pipe)
except Exception as e:
win32pipe.DisconnectNamedPipe(pipe)
finally:
win32file.CloseHandle(pipe)
def namepipe_server_forver(pipe):
while True:
namepipe_server(pipe)
if __name__ == "__main__":
thread = threading.Thread(target=read_thread_func)
thread2 = threading.Thread(target=namepipe_server_forver, args=(pipe,))
thread.daemon = True
thread2.daemon = True
thread.start()
thread2.start()
thread.join()
thread2.join()
import sys
import struct
import ctypes
import threading
import win32pipe
import win32file
pipe_name = r"\\.\pipe\botext"
pipe_access = win32pipe.PIPE_ACCESS_DUPLEX
pipe_type =win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_WAIT | win32pipe.PIPE_READMODE_MESSAGE
pipe_mode = win32pipe.PIPE_UNLIMITED_INSTANCES
max_instances = 65536
out_buffer_size = 65536
default_time_out = 0
security_attributes = None
pipe = win32pipe.CreateNamedPipe(
pipe_name,
pipe_access,
pipe_type,
pipe_mode,
max_instances,
out_buffer_size,
default_time_out,
security_attributes,
)
def write_data(data):
msglen = len(data)
msglen_bytes = struct.pack("=I", msglen)
sys.stdout.buffer.write(msglen_bytes)
sys.stdout.buffer.write(data.encode())
sys.stdout.buffer.flush()
def read_thread_func():
while True:
raw_msglen = sys.stdin.buffer.read(4)
if not raw_msglen:
sys.exit(0)
msglen = struct.unpack("=I", raw_msglen)[0]
# Read the message data
data = sys.stdin.buffer.read(msglen)
ctypes.windll.user32.MessageBoxW(0, data.decode(), "BotExt", 0)
write_data('{"msg": "bridge"}')
def namepipe_server(pipe):
try:
while True:
win32pipe.ConnectNamedPipe(pipe, None)
_, data = win32file.ReadFile(pipe, 4096)
if data == b"close":
sys.exit(0)
print(data)
write_data('{"msg": "client"}')
# ctypes.windll.user32.MessageBoxW(0, "hi", "BotExt", 0)
win32pipe.DisconnectNamedPipe(pipe)
except Exception as e:
win32pipe.DisconnectNamedPipe(pipe)
finally:
win32file.CloseHandle(pipe)
def namepipe_server_forver(pipe):
while True:
namepipe_server(pipe)
if __name__ == "__main__":
thread = threading.Thread(target=read_thread_func)
thread2 = threading.Thread(target=namepipe_server_forver, args=(pipe,))
thread.daemon = True
thread2.daemon = True
thread.start()
thread2.start()
thread.join()
thread2.join()
+112 -112
View File
@@ -1,112 +1,112 @@
import struct
import sys
import threading
from queue import Queue
import tkinter as Tkinter
from tkinter import messagebox as tkMessageBox
if sys.platform == "win32":
import os, msvcrt
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
def send_message(message):
sys.stdout.write(str(len(message)))
sys.stdout.write(message)
sys.stdout.flush()
def read_thread_func(queue):
message_number = 0
while 1:
text_length_bytes = sys.stdin.read(4)
if len(text_length_bytes) == 0:
if queue:
queue.put(None)
sys.exit(0)
text_length = struct.unpack("i", text_length_bytes)[0]
text = sys.stdin.read(text_length).decode("utf-8")
if queue:
queue.put(text)
else:
send_message('{"echo": %s}' % text)
if Tkinter:
class NativeMessagingWindow(Tkinter.Frame):
def __init__(self, queue):
self.queue = queue
Tkinter.Frame.__init__(self)
self.pack()
self.text = Tkinter.Text(self)
self.text.grid(row=0, column=0, padx=10, pady=10, columnspan=2)
self.text.config(state=Tkinter.DISABLED, height=10, width=40)
self.messageContent = Tkinter.StringVar()
self.sendEntry = Tkinter.Entry(self, textvariable=self.messageContent)
self.sendEntry.grid(row=1, column=0, padx=10, pady=10)
self.sendButton = Tkinter.Button(self, text="Send", command=self.onSend)
self.sendButton.grid(row=1, column=1, padx=10, pady=10)
self.after(100, self.processMessages)
def processMessages(self):
while not self.queue.empty():
message = self.queue.get_nowait()
if message == None:
self.quit()
return
self.log("Received %s" % message)
self.after(100, self.processMessages)
def onSend(self):
text = '{"text": "' + self.messageContent.get() + '"}'
self.log("Sending %s" % text)
try:
send_message(text)
except IOError:
tkMessageBox.showinfo(
"Native Messaging Example", "Failed to send message."
)
sys.exit(1)
def log(self, message):
self.text.config(state=Tkinter.NORMAL)
self.text.insert(Tkinter.END, message + "\n")
self.text.config(state=Tkinter.DISABLED)
def Main():
if not Tkinter:
send_message(
"\"Tkinter python module wasn't found. Running in headless "
+ 'mode. Please consider installing Tkinter."'
)
read_thread_func(None)
sys.exit(0)
queue = Queue()
main_window = NativeMessagingWindow(queue)
main_window.master.title("Native Messaging Example")
thread = threading.Thread(target=read_thread_func, args=(queue,))
thread.daemon = True
thread.start()
main_window.mainloop()
sys.exit(0)
if __name__ == "__main__":
Main()
import struct
import sys
import threading
from queue import Queue
import tkinter as Tkinter
from tkinter import messagebox as tkMessageBox
if sys.platform == "win32":
import os, msvcrt
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
def send_message(message):
sys.stdout.write(str(len(message)))
sys.stdout.write(message)
sys.stdout.flush()
def read_thread_func(queue):
message_number = 0
while 1:
text_length_bytes = sys.stdin.read(4)
if len(text_length_bytes) == 0:
if queue:
queue.put(None)
sys.exit(0)
text_length = struct.unpack("i", text_length_bytes)[0]
text = sys.stdin.read(text_length).decode("utf-8")
if queue:
queue.put(text)
else:
send_message('{"echo": %s}' % text)
if Tkinter:
class NativeMessagingWindow(Tkinter.Frame):
def __init__(self, queue):
self.queue = queue
Tkinter.Frame.__init__(self)
self.pack()
self.text = Tkinter.Text(self)
self.text.grid(row=0, column=0, padx=10, pady=10, columnspan=2)
self.text.config(state=Tkinter.DISABLED, height=10, width=40)
self.messageContent = Tkinter.StringVar()
self.sendEntry = Tkinter.Entry(self, textvariable=self.messageContent)
self.sendEntry.grid(row=1, column=0, padx=10, pady=10)
self.sendButton = Tkinter.Button(self, text="Send", command=self.onSend)
self.sendButton.grid(row=1, column=1, padx=10, pady=10)
self.after(100, self.processMessages)
def processMessages(self):
while not self.queue.empty():
message = self.queue.get_nowait()
if message == None:
self.quit()
return
self.log("Received %s" % message)
self.after(100, self.processMessages)
def onSend(self):
text = '{"text": "' + self.messageContent.get() + '"}'
self.log("Sending %s" % text)
try:
send_message(text)
except IOError:
tkMessageBox.showinfo(
"Native Messaging Example", "Failed to send message."
)
sys.exit(1)
def log(self, message):
self.text.config(state=Tkinter.NORMAL)
self.text.insert(Tkinter.END, message + "\n")
self.text.config(state=Tkinter.DISABLED)
def Main():
if not Tkinter:
send_message(
"\"Tkinter python module wasn't found. Running in headless "
+ 'mode. Please consider installing Tkinter."'
)
read_thread_func(None)
sys.exit(0)
queue = Queue()
main_window = NativeMessagingWindow(queue)
main_window.master.title("Native Messaging Example")
thread = threading.Thread(target=read_thread_func, args=(queue,))
thread.daemon = True
thread.start()
main_window.mainloop()
sys.exit(0)
if __name__ == "__main__":
Main()
+55 -55
View File
@@ -1,55 +1,55 @@
# python windows namepipe serve
import win32pipe, win32file
import json
import threading
import sys
import ctypes
# 连接到命名管道
pipe_name = r"\\.\pipe\botext"
pipe_access = win32pipe.PIPE_ACCESS_DUPLEX
pipe_type = win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_WAIT
pipe_mode = 1
max_instances = 65536
out_buffer_size = 65536
default_time_out = 0
security_attributes = None
pipe = win32pipe.CreateNamedPipe(
pipe_name,
win32pipe.PIPE_ACCESS_DUPLEX,
win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_WAIT | win32pipe.PIPE_READMODE_MESSAGE,
win32pipe.PIPE_UNLIMITED_INSTANCES,
65535,
65535,
0,
None,
)
def namepipe_server(pipe):
try:
while True:
win32pipe.ConnectNamedPipe(pipe, None)
_, data = win32file.ReadFile(pipe, 4096)
if data == b'close':
sys.exit(0)
print(data)
ctypes.windll.user32.MessageBoxW(0, "hi", "BotExt", 0)
win32pipe.DisconnectNamedPipe(pipe)
except Exception as e:
win32pipe.DisconnectNamedPipe(pipe)
finally:
win32file.CloseHandle(pipe)
def namepipe_server_forver(pipe):
while True:
namepipe_server(pipe)
if __name__ == "__main__":
task = threading.Thread(target=namepipe_server, args=(pipe,))
task.daemon = True
task.start()
task.join()
# python windows namepipe serve
import win32pipe, win32file
import json
import threading
import sys
import ctypes
# 连接到命名管道
pipe_name = r"\\.\pipe\botext"
pipe_access = win32pipe.PIPE_ACCESS_DUPLEX
pipe_type = win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_WAIT
pipe_mode = 1
max_instances = 65536
out_buffer_size = 65536
default_time_out = 0
security_attributes = None
pipe = win32pipe.CreateNamedPipe(
pipe_name,
win32pipe.PIPE_ACCESS_DUPLEX,
win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_WAIT | win32pipe.PIPE_READMODE_MESSAGE,
win32pipe.PIPE_UNLIMITED_INSTANCES,
65535,
65535,
0,
None,
)
def namepipe_server(pipe):
try:
while True:
win32pipe.ConnectNamedPipe(pipe, None)
_, data = win32file.ReadFile(pipe, 4096)
if data == b'close':
sys.exit(0)
print(data)
ctypes.windll.user32.MessageBoxW(0, "hi", "BotExt", 0)
win32pipe.DisconnectNamedPipe(pipe)
except Exception as e:
win32pipe.DisconnectNamedPipe(pipe)
finally:
win32file.CloseHandle(pipe)
def namepipe_server_forver(pipe):
while True:
namepipe_server(pipe)
if __name__ == "__main__":
task = threading.Thread(target=namepipe_server, args=(pipe,))
task.daemon = True
task.start()
task.join()
+7 -7
View File
@@ -1,7 +1,7 @@
:: Copyright 2014 The Chromium Authors. All rights reserved.
:: Use of this source code is governed by a BSD-style license that can be
:: found in the LICENSE file.
:: Deletes the entry created by install_host.bat
REG DELETE "HKCU\Software\Google\Chrome\NativeMessagingHosts\com.google.chrome.botext" /f
REG DELETE "HKLM\Software\Google\Chrome\NativeMessagingHosts\com.google.chrome.botext" /f
:: Copyright 2014 The Chromium Authors. All rights reserved.
:: Use of this source code is governed by a BSD-style license that can be
:: found in the LICENSE file.
:: Deletes the entry created by install_host.bat
REG DELETE "HKCU\Software\Google\Chrome\NativeMessagingHosts\com.google.chrome.botext" /f
REG DELETE "HKLM\Software\Google\Chrome\NativeMessagingHosts\com.google.chrome.botext" /f