From 5c3f15c70e705c585d09f998b5acb523a371fbef Mon Sep 17 00:00:00 2001 From: woni <320753691@qq.com> Date: Wed, 25 Oct 2023 11:13:45 +0800 Subject: [PATCH] adjust project directory --- app/sw.js | 24 -------- botext/__init__.py | 48 ++++++++++++++++ {host => botext/console}/install_host.bat | 2 +- botext/install.py | 21 +++++++ {host => bridge}/botext.bat | 0 {host => bridge}/client.py | 0 bridge/com.woni.chrome.botext.json | 9 +++ .../native-messaging-example-host | 0 .../native-messaging-example-host copy | 0 {host => bridge}/server.py | 0 {host => bridge}/uninstall_host.bat | 0 build.bat | 1 + {app => crx}/content-script.js | 0 {app => crx}/index.html | 0 {app => crx}/index.js | 0 {app => crx}/manifest.json | 0 crx/sw.js | 52 ++++++++++++++++++ {app => crx}/wps.js | 0 dist/botext-0.1.0-py3-none-any.whl | Bin 1016 -> 2664 bytes dist/botext-0.1.0.tar.gz | Bin 623 -> 1812 bytes docs/botext-init.md | 6 ++ docs/install.md | 11 ++++ host/com.google.chrome.botext.json | 9 --- pyproject.toml | 3 +- 24 files changed, 151 insertions(+), 35 deletions(-) delete mode 100644 app/sw.js rename {host => botext/console}/install_host.bat (68%) create mode 100644 botext/install.py rename {host => bridge}/botext.bat (100%) rename {host => bridge}/client.py (100%) create mode 100644 bridge/com.woni.chrome.botext.json rename {host => bridge}/native-messaging-example-host (100%) rename {host => bridge}/native-messaging-example-host copy (100%) rename {host => bridge}/server.py (100%) rename {host => bridge}/uninstall_host.bat (100%) create mode 100644 build.bat rename {app => crx}/content-script.js (100%) rename {app => crx}/index.html (100%) rename {app => crx}/index.js (100%) rename {app => crx}/manifest.json (100%) create mode 100644 crx/sw.js rename {app => crx}/wps.js (100%) create mode 100644 docs/botext-init.md create mode 100644 docs/install.md delete mode 100644 host/com.google.chrome.botext.json diff --git a/app/sw.js b/app/sw.js deleted file mode 100644 index 8e493ad..0000000 --- a/app/sw.js +++ /dev/null @@ -1,24 +0,0 @@ -function injectedFunction(color) { - document.body.style.backgroundColor = color; -} - - -chrome.runtime.onMessage.addListener(async ({ name, options }) => { - if (name === 'addRecord') { - console.log('Hello World!'); - - // get active tab - // const [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); - // chrome.scripting.executeScript({ - // target: { tabId: tab.id }, - // func: injectedFunction, - // args: ["orange"], - // }); - - const [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); - const response = await chrome.tabs.sendMessage(tab.id, { greeting: "hello" }); - // do something with response here, not outside the function - console.log(response); - - } -}); diff --git a/botext/__init__.py b/botext/__init__.py index 8b13789..8cb3f9e 100644 --- a/botext/__init__.py +++ b/botext/__init__.py @@ -1 +1,49 @@ +import win32pipe +import win32file +import struct + +class HostClient: + def __init__(self): + self.pipe_name = r"\\.\pipe\BotExtPipe" + self.pipe = None + + def connect(self): + self.pipe = win32file.CreateFile( + self.pipe_name, + win32file.GENERIC_READ | win32file.GENERIC_WRITE, + 0, + None, + win32file.OPEN_EXISTING, + 0, + None, + ) + + def write(self, data): + if not self.pipe: + self.connect() + length = len(data) + length_bytes = struct.pack("I", length) + win32file.WriteFile(self.pipe, length_bytes) + win32file.WriteFile(self.pipe, data) + + def read(self): + if not self.pipe: + self.connect() + length_bytes = win32file.ReadFile(self.pipe, 4)[1] + length = struct.unpack("I", length_bytes)[0] + data = win32file.ReadFile(self.pipe, length)[1] + return data + + def close(self): + if self.pipe: + win32file.CloseHandle(self.pipe) + self.pipe = None + + +if __name__ == "__main__": + client = HostClient() + client.connect() + client.write(b"Hello, World!") + print(client.read()) + client.close() diff --git a/host/install_host.bat b/botext/console/install_host.bat similarity index 68% rename from host/install_host.bat rename to botext/console/install_host.bat index 6b4de40..e995453 100644 --- a/host/install_host.bat +++ b/botext/console/install_host.bat @@ -4,4 +4,4 @@ :: Change HKCU to HKLM if you want to install globally. :: %~dp0 is the directory containing this bat script and ends with a backslash. -REG ADD "HKCU\Software\Google\Chrome\NativeMessagingHosts\com.google.chrome.botext" /ve /t REG_SZ /d "%~dp0com.google.chrome.botext.json" /f +REG ADD "HKCU\Software\Google\Chrome\NativeMessagingHosts\com.woni.botext" /ve /t REG_SZ /d "%~dp0com.google.chrome.botext.json" /f diff --git a/botext/install.py b/botext/install.py new file mode 100644 index 0000000..c8b2e1b --- /dev/null +++ b/botext/install.py @@ -0,0 +1,21 @@ +import os + + +# 在下载文件夹创建test目录 +# 获取windows 下载文件夹路径 +def get_download_folder(): + home_dir = os.path.expanduser("~") + download_folder = os.path.join(home_dir, "Downloads") + return download_folder + +def main(): + # download_path = get_download_folder() + # test = os.path.join(download_path, "test") + # if not os.path.exists(test): + # os.mkdir(test) + print("install_host.bat") + # os.system("install_host.bat") + + +if __name__ == '__main__': + main() diff --git a/host/botext.bat b/bridge/botext.bat similarity index 100% rename from host/botext.bat rename to bridge/botext.bat diff --git a/host/client.py b/bridge/client.py similarity index 100% rename from host/client.py rename to bridge/client.py diff --git a/bridge/com.woni.chrome.botext.json b/bridge/com.woni.chrome.botext.json new file mode 100644 index 0000000..ffd72df --- /dev/null +++ b/bridge/com.woni.chrome.botext.json @@ -0,0 +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/" + ] +} diff --git a/host/native-messaging-example-host b/bridge/native-messaging-example-host similarity index 100% rename from host/native-messaging-example-host rename to bridge/native-messaging-example-host diff --git a/host/native-messaging-example-host copy b/bridge/native-messaging-example-host copy similarity index 100% rename from host/native-messaging-example-host copy rename to bridge/native-messaging-example-host copy diff --git a/host/server.py b/bridge/server.py similarity index 100% rename from host/server.py rename to bridge/server.py diff --git a/host/uninstall_host.bat b/bridge/uninstall_host.bat similarity index 100% rename from host/uninstall_host.bat rename to bridge/uninstall_host.bat diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..0f27524 --- /dev/null +++ b/build.bat @@ -0,0 +1 @@ +poetry build && pip install dist\botext-0.1.0-py3-none-any.whl --force-reinstall diff --git a/app/content-script.js b/crx/content-script.js similarity index 100% rename from app/content-script.js rename to crx/content-script.js diff --git a/app/index.html b/crx/index.html similarity index 100% rename from app/index.html rename to crx/index.html diff --git a/app/index.js b/crx/index.js similarity index 100% rename from app/index.js rename to crx/index.js diff --git a/app/manifest.json b/crx/manifest.json similarity index 100% rename from app/manifest.json rename to crx/manifest.json diff --git a/crx/sw.js b/crx/sw.js new file mode 100644 index 0000000..fe468cf --- /dev/null +++ b/crx/sw.js @@ -0,0 +1,52 @@ +// function injectedFunction(color) { +// document.body.style.backgroundColor = color; +// } + + +// chrome.runtime.onMessage.addListener(async ({ name, options }) => { +// if (name === 'addRecord') { +// console.log('Hello World!'); + +// // get active tab +// // const [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); +// // chrome.scripting.executeScript({ +// // target: { tabId: tab.id }, +// // func: injectedFunction, +// // args: ["orange"], +// // }); + +// const [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); +// const response = await chrome.tabs.sendMessage(tab.id, { greeting: "hello" }); +// // do something with response here, not outside the function +// console.log(response); + +// } +// }); + +let port; + +function sendMessage(message) { + if (!port) { + // this will run the first time to launch the native host, and save the connection to that instance in the port + port = chrome.runtime.connectNative('com.woni.chrome.botext'); + } + // Convert the message to a Uint8Array. + var encoder = new TextEncoder(); + var messageBytes = encoder.encode(message); + // Send the message length as a 32-bit integer. + var buffer = new ArrayBuffer(4); + var view = new DataView(buffer); + view.setUint32(0, messageBytes.length, true); + port.postMessage(buffer); + + // Send the message content. + port.postMessage(messageBytes); +} + + + + + +sendMessage('message 1'); +sendMessage('message 2'); +sendMessage('message 3'); diff --git a/app/wps.js b/crx/wps.js similarity index 100% rename from app/wps.js rename to crx/wps.js diff --git a/dist/botext-0.1.0-py3-none-any.whl b/dist/botext-0.1.0-py3-none-any.whl index e86ac901de845febec13e77c3a10c809f947cc5f..4780986c03bf4a8cd7dda7ab6e3a143e3d30d559 100644 GIT binary patch literal 2664 zcm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XU5r7$%Udq@O**Z(|l3U1w)CkcZHy7`A;2h*0IkXidN@T=9=Z& s`BWF?E8D-k%op8e@-DY+NP7SP00000000000K71M0oIdG;{YfC0HSO*`2YX_ diff --git a/docs/botext-init.md b/docs/botext-init.md new file mode 100644 index 0000000..78922d5 --- /dev/null +++ b/docs/botext-init.md @@ -0,0 +1,6 @@ +1. 注册表 + +REG ADD "HKCU\Software\Google\Chrome\NativeMessagingHosts\com.google.chrome.botext" /ve /t REG_SZ /d "%~dp0com.google.chrome.botext.json" /f + +com.woni.chrome.botext + diff --git a/docs/install.md b/docs/install.md new file mode 100644 index 0000000..acf6240 --- /dev/null +++ b/docs/install.md @@ -0,0 +1,11 @@ +安装python模块自动运行脚本 + +1. 修改注册表 +2. 拷贝文件至目标目录 +3. 安装插件 + + + + + + diff --git a/host/com.google.chrome.botext.json b/host/com.google.chrome.botext.json deleted file mode 100644 index 6bb7b9e..0000000 --- a/host/com.google.chrome.botext.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "com.google.chrome.botext", - "description": "botext", - "path": "D:\\rust\\botext\\target\\debug\\botext.exe", - "type": "stdio", - "allowed_origins": [ - "chrome-extension://hbneoijjlheddhhonbkamdmgljmjcdom/" - ] -} diff --git a/pyproject.toml b/pyproject.toml index 2997438..6273d47 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,5 +17,6 @@ requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" + [tool.poetry.scripts] -# pyd = "python build-pyd.py build_ext --inplace" +install = "botext.install:main"