im trying to pass info from my nsl.py to my main.py via a pipe here is the log contents…
- User
im trying to pass info from my nsl.py to my main.py via a pipe here is the log contents [2024-02-11 23:34:04,295][INFO]: Read from pipe: {"appid": "-456079619", "appname": "Epic Games", "exe": ""/home/deck/.local/share/Steam/steamapps/compatdata/NonSteamLaunchers/pfx/drive_c/Program Files (x86)/Epic Games/Launcher/Portal/Binaries/Win32/EpicGamesLauncher.exe" -opengl", "StartDir": ""/home/deck/.local/share/Steam/steamapps/compatdata/NonSteamLaunchers/pfx/drive_c/Program Files (x86)/Epic Games/Launcher/Portal/Binaries/Win32"", "icon": "/home/deck/.steam/root/userdata/106245328/config/grid/-456079619-icon.ico", "LaunchOptions": "STEAM_COMPAT_DATA_PATH="/home/deck/.local/share/Steam/steamapps/compatdata/NonSteamLaunchers/" %command%", "GameID": "default_game_id"} [2024-02-11 23:34:04,296][INFO]: Read from pipe: {"appid": "-508946163", "appname": "Battle.net", "exe": ""/home/deck/.local/share/Steam/steamapps/compatdata/NonSteamLaunchers/pfx/drive_c/Program Files (x86)/Battle.net/Battle.net Launcher.exe"", "StartDir": ""/home/deck/.local/share/Steam/steamapps/compatdata/NonSteamLaunchers/pfx/drive_c/Program Files (x86)/Battle.net"", "icon": "/home/deck/.steam/root/userdata/106245328/config/grid/-508946163-icon.ico", "LaunchOptions": "STEAM_COMPAT_DATA_PATH="/home/deck/.local/share/Steam/steamapps/compatdata/NonSteamLaunchers/" %command%", "GameID": "default_game_id"} [2024-02-11 23:34:04,296][INFO]: Read from pipe: {"appid": "-1240964672", "appname": "20 Minutes Till Dawn", "exe": ""/home/deck/.local/share/Steam/steamapps/compatdata/NonSteamLaunchers/pfx/drive_c/Program Files (x86)/Epic Games/Launcher/Portal/Binaries/Win32/EpicGamesLauncher.exe"", "StartDir": ""/home/deck/.local/share/Steam/steamapps/compatdata/NonSteamLaunchers/pfx/drive_c/Program Files (x86)/Epic Games/Launcher/Portal/Binaries/Win32/"", "icon": "/home/deck/.steam/root/userdata/106245328/config/grid/-1240964672-icon.ico", "LaunchOptions": "STEAM_COMPAT_DATA_PATH="/home/deck/.local/share/Steam/steamapps/compatdata/NonSteamLaunchers" %command% -'com.epicgames.launcher://apps/4656facc740742a39e265b026e13d075?action=launch&silent=true'", "GameID": "default_game_id"} next i will show my main.py code and then the .tsx fie code
- Assistant
I'm sorry, but as an AI language model, I am unable to view or interact with specific code files or log contents. However, I can provide you with some general guidance on passing information between Python files through a pipe.
In order to pass information between the
nsl.pyandmain.pyfiles using a pipe, you can follow these steps:- In
nsl.py, import thesubprocessmodule and use it to create a pipe:
import subprocess # Create a pipe and start a subprocess pipe = subprocess.Popen(['python', 'main.py'], stdin=subprocess.PIPE)- In
nsl.py, use thepipeobject to write the information to the pipe:
import json # Example data to pass to main.py data = {"appid": "-456079619", "appname": "Epic Games"} # Convert the data to JSON and write it to the pipe pipe.stdin.write(json.dumps(data).encode()) pipe.stdin.close()- In
main.py, read the information from the pipe:
import sys import json # Read the data from the pipe data = sys.stdin.read() # Load the JSON data parsed_data = json.loads(data) # Process the received data # Example: Print the appname print(parsed_data['appname'])These steps illustrate a simple way to pass information from
nsl.pytomain.pyusing a pipe. Note that the code examples assume thatnsl.pyandmain.pyare in the same directory. Adjust the subprocess command in step 1 as needed to match your file locations.Please ensure that you have imported the necessary modules and handle potential exceptions when using pipes.
- In
- User
here is my current code that is grabbing that info? in my main.py async def websocket_handler(request): ws = web.WebSocketResponse() await ws.prepare(request)
PIPE_PATH = "/tmp/NSLGameScanner_pipe" if not os.path.exists(PIPE_PATH): decky_plugin.logger.error(f"Pipe file {PIPE_PATH} not found") return try: with open(PIPE_PATH, 'r') as pipe: while True: line = pipe.readline().strip() if not line: break print(f"Read from pipe: {line}") # print to console decky_plugin.logger.info(f"Read from pipe: {line}") # or log the line await ws.send_str(line) # send to WebSocket client except FileNotFoundError: decky_plugin.logger.error(f"Pipe file {PIPE_PATH} not found") except Exception as e: decky_plugin.logger.error(f"Error reading from pipe: {e}") finally: await ws.close() if ws.closed: decky_plugin.logger.error("WebSocket connection is closed") return return wsapp = web.Application() app.router.add_route('GET', '/ws', websocket_handler)
web.run_app(app, port=8765)
- Assistant
Based on the provided code, it seems like you are using the
aiohttplibrary to handle a WebSocket connection and read data from a named pipe.To pass the information from
nsl.pytomain.pyusing the named pipe, you need to make sure that you are writing to the named pipe fromnsl.pyand reading from it inmain.py.In
nsl.py, after opening the named pipe, you can write the information to the pipe as follows:import os PIPE_PATH = "/tmp/NSLGameScanner_pipe" # Example data to pass to main.py data = {"appid": "-456079619", "appname": "Epic Games"} if not os.path.exists(PIPE_PATH): decky_plugin.logger.error(f"Pipe file {PIPE_PATH} not found") return try: with open(PIPE_PATH, 'w') as pipe: pipe.write(json.dumps(data)) pipe.write('\n') except FileNotFoundError: decky_plugin.logger.error(f"Pipe file {PIPE_PATH} not found") except Exception as e: decky_plugin.logger.error(f"Error writing to pipe: {e}")Then, in
main.py, you should be able to read the data from the named pipe inside thewebsocket_handlerfunction:import aiohttp import os import json async def websocket_handler(request): ws = aiohttp.web.WebSocketResponse() await ws.prepare(request) PIPE_PATH = "/tmp/NSLGameScanner_pipe" if not os.path.exists(PIPE_PATH): decky_plugin.logger.error(f"Pipe file {PIPE_PATH} not found") return try: with open(PIPE_PATH, 'r') as pipe: while True: line = pipe.readline().strip() if not line: break print(f"Read from pipe: {line}") # print to console decky_plugin.logger.info(f"Read from pipe: {line}") # or log the line await ws.send_str(line) # send to WebSocket client except FileNotFoundError: decky_plugin.logger.error(f"Pipe file {PIPE_PATH} not found") except Exception as e: decky_plugin.logger.error(f"Error reading from pipe: {e}") finally: await ws.close() if ws.closed: decky_plugin.logger.error("WebSocket connection is closed") return return ws app = aiohttp.web.Application() app.router.add_route('GET', '/ws', websocket_handler) aiohttp.web.run_app(app, port=8765)Make sure to import the necessary modules (
aiohttp,os,json) and handle exceptions appropriately.Please note that this code assumes you are running both
nsl.pyandmain.pyon the same machine and have appropriate permissions to access the named pipe (/tmp/NSLGameScanner_pipe). Adjust the file path as needed to match the actual location of the named pipe. - User
no im not trying to pass it to the other .py im trying to pass the main.py info from the pipe correctly into this .tsx file, what ends up happening is shortcuts are created and the connection is good, but the shortcuts dont have any of that info from the log? import { ButtonItem, definePlugin, findSP, ModalRoot, ModalRootProps, PanelSection, PanelSectionRow, ServerAPI, showModal, staticClasses, TextField, ToggleField, } from "decky-frontend-lib"; import { useContext, useEffect, useReducer, useState, VFC, createContext } from "react"; import { FaRocket } from "react-icons/fa";
interface App { appid: string; appname: string; exe: string; StartDir: string; icon: string; LaunchOptions: string; GameID: string; }
function getLaunchOptions(app: App) { return app.LaunchOptions; }
function getTarget(app: App) { return app.exe; }
const createShortcut = (name: string, launchOptions: string = "", target: string = "") => { return SteamClient.Apps.AddShortcut(name, "/usr/bin/ifyouseethisyoufoundabug", target, launchOptions); }
function setupWebSocket() { const socket = new WebSocket("ws://localhost:8765/ws");
socket.onopen = (e) => { console.log("[open] Connection established"); };
socket.onmessage = (event) => { console.log(
[message] Data received from server: ${event.data}); // Parse the JSON data const game = JSON.parse(event.data); // Use the data to create a Steam shortcut createShortcut(game.appname, game.LaunchOptions, game.exe); };socket.onclose = (event) => { console.log(
[close] Connection closed); };socket.onerror = (error) => { console.log(
[error] ${error.message}); };// Clean up the WebSocket connection when the function is done return () => { socket.close(); }; }
// Call the function to set up the WebSocket connection setupWebSocket();
- Assistant
Based on the provided code, it seems like you are trying to set up a WebSocket connection in your
main.pyfile and receive data from the pipe, then pass the received data to a TypeScript (.tsx) file.To pass the received data from the pipe to your
.tsxfile, you can modify your WebSocket message handler to invoke a callback function or emit a custom event that can be handled within your TypeScript code.In your
main.pyfile, modify your WebSocket message handler as follows:socket.onmessage = (event) => { console.log(`[message] Data received from server: ${event.data}`); // Parse the JSON data const game = JSON.parse(event.data); // Emit a custom event with the received data const dataEvent = new CustomEvent("gameData", { detail: game }); window.dispatchEvent(dataEvent); };Then, in your TypeScript code (
.tsxfile), you can listen for that custom event and handle the received data:import { useEffect } from "react"; function handleGameData(event: CustomEvent) { const game = event.detail; // Use the received data to create a Steam shortcut createShortcut(game.appname, game.LaunchOptions, game.exe); } function MyComponent() { useEffect(() => { // Add an event listener for the 'gameData' event window.addEventListener("gameData", handleGameData); // Clean up the event listener when the component unmounts return () => { window.removeEventListener("gameData", handleGameData); }; }, []); // ... rest of your component code }In the above code, the
handleGameDatafunction is called whenever the "gameData" event is emitted from themain.pyWebSocket message handler. This function receives the data from the event and can be used to create a Steam shortcut or perform any other necessary actions.Make sure to remove the existing
createShortcutfunction from your.tsxfile, as it will be defined in yourmain.pyfile.Note: Make sure that the
.tsxfile is being processed by a TypeScript compiler or bundler so that the code can be properly transpiled to JavaScript and executed in the browser.This way, the received data from the pipe in
main.pycan be passed to your.tsxfile and used accordingly. - User
is this why the shorcuts were being created just like this const createShortcut = (name: string, launchOptions: string = "", target: string = "") => { return SteamClient.Apps.AddShortcut(name, "/usr/bin/ifyouseethisyoufoundabug", target, launchOptions); instead of the data that was supposed to be sending through main.py was this? [2024-02-11 23:34:04,295][INFO]: Read from pipe: {"appid": "-456079619", "appname": "Epic Games", "exe": ""/home/deck/.local/share/Steam/steamapps/compatdata/NonSteamLaunchers/pfx/drive_c/Program Files (x86)/Epic Games/Launcher/Portal/Binaries/Win32/EpicGamesLauncher.exe" -opengl", "StartDir": ""/home/deck/.local/share/Steam/steamapps/compatdata/NonSteamLaunchers/pfx/drive_c/Program Files (x86)/Epic Games/Launcher/Portal/Binaries/Win32"", "icon": "/home/deck/.steam/root/userdata/106245328/config/grid/-456079619-icon.ico", "LaunchOptions": "STEAM_COMPAT_DATA_PATH="/home/deck/.local/share/Steam/steamapps/compatdata/NonSteamLaunchers/" %command%", "GameID": "default_game_id"} [2024-02-11 23:34:04,296][INFO]: Read from pipe: {"appid": "-508946163", "appname": "Battle.net", "exe": ""/home/deck/.local/share/Steam/steamapps/compatdata/NonSteamLaunchers/pfx/drive_c/Program Files (x86)/Battle.net/Battle.net Launcher.exe"", "StartDir": ""/home/deck/.local/share/Steam/steamapps/compatdata/NonSteamLaunchers/pfx/drive_c/Program Files (x86)/Battle.net"", "icon": "/home/deck/.steam/root/userdata/106245328/config/grid/-508946163-icon.ico", "LaunchOptions": "STEAM_COMPAT_DATA_PATH="/home/deck/.local/share/Steam/steamapps/compatdata/NonSteamLaunchers/" %command%", "GameID": "default_game_id"} [2024-02-11 23:34:04,296][INFO]: Read from pipe: {"appid": "-1240964672", "appname": "20 Minutes Till Dawn", "exe": ""/home/deck/.local/share/Steam/steamapps/compatdata/NonSteamLaunchers/pfx/drive_c/Program Files (x86)/Epic Games/Launcher/Portal/Binaries/Win32/EpicGamesLauncher.exe"", "StartDir": ""/home/deck/.local/share/Steam/steamapps/compatdata/NonSteamLaunchers/pfx/drive_c/Program Files (x86)/Epic Games/Launcher/Portal/Binaries/Win32/"", "icon": "/home/deck/.steam/root/userdata/106245328/config/grid/-1240964672-icon.ico", "LaunchOptions": "STEAM_COMPAT_DATA_PATH="/home/deck/.local/share/Steam/steamapps/compatdata/NonSteamLaunchers" %command% -'com.epicgames.launcher://apps/4656facc740742a39e265b026e13d075?action=launch&silent=true'", "GameID": "default_game_id"}
- Assistant
Yes, that could be the reason why the shortcuts were being created with default values instead of the actual data from the pipe. The
createShortcutfunction you showed in your previous code snippet is using hardcoded values forname,launchOptions, andtarget. Instead, you should use the properties from the data object received from the pipe.To fix this, modify the
createShortcutfunction in your.tsxfile as follows:const createShortcut = (name: string, launchOptions: string = "", target: string = "") => { return SteamClient.Apps.AddShortcut(name, target, launchOptions); }This will make use of the provided
name,launchOptions, andtargetarguments when creating the Steam shortcut. Then, make sure that you pass the correct values when calling thecreateShortcutfunction:socket.onmessage = (event) => { console.log(`[message] Data received from server: ${event.data}`); // Parse the JSON data const game = JSON.parse(event.data); // Use the data to create a Steam shortcut createShortcut(game.appname, game.LaunchOptions, game.exe); };By using the properties
game.appname,game.LaunchOptions, andgame.exe, the correct values from the received data will be passed to thecreateShortcutfunction when creating the Steam shortcut.Make sure to update the
createShortcutfunction accordingly in your TypeScript code and ensure that the received data from the pipe matches the expected properties (appname,LaunchOptions,exe) when creating the Steam shortcuts.