Skip to content

Commit

Permalink
Merge pull request #2 from AkazaRenn/main
Browse files Browse the repository at this point in the history
Document update, merge pause button with game icon
  • Loading branch information
wynn1212 authored Jul 8, 2024
2 parents 4ee9700 + d841396 commit 147447a
Show file tree
Hide file tree
Showing 10 changed files with 304 additions and 154 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,11 @@ backend/out

# Make sure to ignore any instance of the loader's decky_plugin.py
decky_plugin.py

# Ignore decky CLI for building plugins
out
out/*
cli/
cli/*
cli/decky
/deck.json
10 changes: 10 additions & 0 deletions .vscode/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
CLI_LOCATION="$(pwd)/cli"
echo "Building plugin in $(pwd)"
printf "Please input sudo password to proceed.\n"

# read -s sudopass

# printf "\n"

echo $sudopass | sudo $CLI_LOCATION/decky plugin build $(pwd)
1 change: 1 addition & 0 deletions .vscode/defsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"deckpass" : "ssap",
"deckkey" : "-i ${env:HOME}/.ssh/id_rsa",
"deckdir" : "/home/deck",
"pluginname": "Pause Games",
"python.analysis.extraPaths": [
"./py_modules"
]
Expand Down
68 changes: 68 additions & 0 deletions .vscode/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env bash
PNPM_INSTALLED="$(which pnpm)"
DOCKER_INSTALLED="$(which docker)"
CLI_INSTALLED="$(pwd)/cli/decky"

# echo "$PNPM_INSTALLED"
# echo "$DOCKER_INSTALLED"
# echo "$CLI_INSTALLED"

echo "If you are using alpine linux, do not expect any support."
if [[ "$PNPM_INSTALLED" =~ "which" ]]; then
echo "pnpm is not currently installed, you can install it via your distro's package managment system or via a script that will attempt to do a manual install based on your system. If you wish to proceed with installing via the script then answer "no" (capitals do not matter) and proceed with the rest of the script. Otherwise, just hit enter to proceed and use the script."
read run_pnpm_script
if [[ "$run_pnpm_script" =~ "n" ]]; then
echo "You have chose to install pnpm via npm or your distros package manager. Please make sure to do so before attempting to build your plugin."
else
CURL_INSTALLED="$(which curl)"
WGET_INSTALLED="$(which wget)"
if [[ "$CURL_INSTALLED" =~ "which" ]]; then
printf "curl not found, attempting with wget.\n"
if [[ "$WGET_INSTALLED" =~ "which" ]]; then
printf "wget not found, please install wget or curl.\n"
printf "Could not install pnpm as curl and wget were not found.\n"
else
wget -qO- https://get.pnpm.io/install.sh | sh -
fi
else
curl -fsSL https://get.pnpm.io/install.sh | sh -
fi
fi
fi

if [[ "$DOCKER_INSTALLED" =~ "which" ]]; then
echo "Docker is not currently installed, in order build plugins with a backend you will need to have Docker installed. Please install Docker via the preferred method for your distribution."
fi

if ! test -f "$CLI_INSTALLED"; then
echo "The Decky CLI tool (binary file is just called "decky") is used to build your plugin as a zip file which you can then install on your Steam Deck to perform testing. We highly recommend you install it. Hitting enter now will run the script to install Decky CLI and extract it to a folder called cli in the current plugin directory. You can also type 'no' and hit enter to skip this but keep in mind you will not have a usable plugin without building it."
read run_cli_script
if [[ "$run_cli_script" =~ "n" ]]; then
echo "You have chosen to not install the Decky CLI tool to build your plugins. Please install this tool to build and test your plugin before submitting it to the Plugin Database."
else

SYSTEM_ARCH="$(uname -a)"

mkdir "$(pwd)"/cli
if [[ "$SYSTEM_ARCH" =~ "x86_64" ]]; then

if [[ "$SYSTEM_ARCH" =~ "Linux" ]]; then
curl -L -o "$(pwd)"/cli/decky "https://github.com/SteamDeckHomebrew/cli/releases/latest/download/decky-linux-x86_64"
fi

if [[ "$SYSTEM_ARCH" =~ "Darwin" ]]; then
curl -L -o "$(pwd)"/cli/decky "https://github.com/SteamDeckHomebrew/cli/releases/latest/download/decky-macOS-x86_64"
fi

else
echo "System Arch not found! The only supported systems are Linux x86_64 and Apple x86_64/ARM64, not $SYSTEM_ARCH"
fi

if [[ "$SYSTEM_ARCH" =~ "arm64" ]]; then
curl -L -o "$(pwd)"/cli/decky "https://github.com/SteamDeckHomebrew/cli/releases/latest/download/decky-macOS-aarch64"
fi

chmod +x "$(pwd)"/cli/decky
echo "Decky CLI tool is now installed and you can build plugins into easy zip files using the "Build Zip" Task in vscodium."
fi
fi
150 changes: 91 additions & 59 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,116 +1,148 @@
{
"version": "2.0.0",
"tasks": [
// OTHER
//PRELIMINARY SETUP TASKS
//Dependency setup task
{
"label": "checkforsettings",
"label": "depsetup",
"type": "shell",
"group": "none",
"detail": "Check that settings.json has been created",
"command": "bash -c ${workspaceFolder}/.vscode/config.sh",
"detail": "Install depedencies for basic setup",
"linux": {
"command": "${workspaceFolder}/.vscode/setup.sh",
},
// // placeholder for windows scripts, not currently planned
// "windows": {
// "command": "call -c ${workspaceFolder}\\.vscode\\setup.bat",
// },
"problemMatcher": []
},
// BUILD
//pnpm setup task to grab all needed modules
{
"label": "pnpmsetup",
"type": "shell",
"group": "build",
"group": "none",
"detail": "Setup pnpm",
"command": "pnpm i",
"command": "which pnpm && pnpm i",
"problemMatcher": []
},
//Preliminary "All-in-one" setup task
{
"label": "updatefrontendlib",
"label": "setup",
"detail": "Set up depedencies, pnpm and update Decky Frontend Library.",
"dependsOrder": "sequence",
"dependsOn": [
"depsetup",
"pnpmsetup",
"updatefrontendlib"
],
"problemMatcher": []
},
//Preliminary Deploy Config Setup
{
"label": "settingscheck",
"type": "shell",
"group": "build",
"detail": "Update deck-frontend-lib",
"command": "pnpm update decky-frontend-lib --latest",
"group": "none",
"detail": "Check that settings.json has been created",
"linux": {
"command": "${workspaceFolder}/.vscode/config.sh",
},
// // placeholder for windows scripts, not currently planned
// "windows": {
// "command": "call ${workspaceFolder}\\.vscode\\config.bat",
// },
"problemMatcher": []
},
//BUILD TASKS
{
"label": "build",
"type": "npm",
"label": "cli-build",
"group": "build",
"detail": "rollup -c",
"script": "build",
"path": "",
"detail": "Build plugin with CLI",
"linux": {
"command": "${workspaceFolder}/.vscode/build.sh",
},
// // placeholder for windows logic, not currently planned
// "windows": {
// "command": "call ${workspaceFolder}\\.vscode\\build.bat",
// },
"problemMatcher": []
},
//"All-in-one" build task
{
"label": "buildall",
"label": "build",
"group": "build",
"detail": "Build decky-plugin-template",
"dependsOrder": "sequence",
"dependsOn": [
"pnpmsetup",
"build"
"setup",
"settingscheck",
"cli-build",
],
"problemMatcher": []
},
// DEPLOY
//DEPLOY TASKS
//Copies the zip file of the built plugin to the plugins folder
{
"label": "createfolders",
"detail": "Create plugins folder in expected directory",
"label": "copyzip",
"detail": "Deploy plugin zip to deck",
"type": "shell",
"group": "none",
"dependsOn": [
"checkforsettings"
"chmodplugins"
],
"command": "ssh ${config:deckuser}@${config:deckip} -p ${config:deckport} ${config:deckkey} 'mkdir -p ${config:deckdir}/homebrew/pluginloader && mkdir -p ${config:deckdir}/homebrew/plugins'",
"command": "rsync -azp --chmod=D0755,F0755 --rsh='ssh -p ${config:deckport} ${config:deckkey}' out/ ${config:deckuser}@${config:deckip}:${config:deckdir}/homebrew/plugins",
"problemMatcher": []
},
//
{
"label": "deploy",
"detail": "Deploy dev plugin to deck",
"label": "extractzip",
"detail": "",
"type": "shell",
"group": "none",
"command": "echo '${config:deckdir}/homebrew/plugins/${config:pluginname}.zip' && ssh ${config:deckuser}@${config:deckip} -p ${config:deckport} ${config:deckkey} 'echo ${config:deckpass} | sudo -S mkdir 755 -p \"$(echo \"${config:deckdir}/homebrew/plugins/${config:pluginname}\" | sed \"s| |-|\")\" && echo ${config:deckpass} | sudo -S chown ${config:deckuser}:${config:deckuser} \"$(echo \"${config:deckdir}/homebrew/plugins/${config:pluginname}\" | sed \"s| |-|\")\" && echo ${config:deckpass} | sudo -S bsdtar -xzpf \"${config:deckdir}/homebrew/plugins/${config:pluginname}.zip\" -C \"$(echo \"${config:deckdir}/homebrew/plugins/${config:pluginname}\" | sed \"s| |-|g\")\" --strip-components=1 --fflags '",
"problemMatcher": []
},
//"All-in-one" deploy task
{
"label": "deploy",
"dependsOrder": "sequence",
"group": "none",
"dependsOn": [
"createfolders",
"chmodfolders"
"copyzip",
"extractzip"
],
"command": "rsync -azp --delete --chmod=D0755,F0755 --rsh='ssh -p ${config:deckport} ${config:deckkey}' --exclude='.git/' --exclude='.github/' --exclude='.vscode/' --exclude='node_modules/' --exclude='src/' --exclude='*.log' --exclude='.gitignore' . ${config:deckuser}@${config:deckip}:${config:deckdir}/homebrew/plugins/${workspaceFolderBasename}",
"problemMatcher": []
},
//"All-in-on" build & deploy task
{
"label": "restartloader",
"detail": "Restart the plugin loader (to load updated python code)",
"type": "shell",
"label": "builddeploy",
"detail": "Builds plugin and deploys to deck",
"dependsOrder": "sequence",
"group": "none",
"dependsOn": [],
"command": "ssh ${config:deckuser}@${config:deckip} -p ${config:deckport} ${config:deckkey} 'echo '${config:deckpass}' | sudo -S systemctl restart plugin_loader'",
"dependsOn": [
"build",
"deploy"
],
"problemMatcher": []
},
//GENERAL TASKS
//Update Decky Frontend Library, aka DFL
{
"label": "chmodfolders",
"detail": "chmods folders to prevent perms issues",
"label": "updatefrontendlib",
"type": "shell",
"group": "none",
"command": "ssh ${config:deckuser}@${config:deckip} -p ${config:deckport} ${config:deckkey} 'echo '${config:deckpass}' | sudo -S chmod -R ug+rw ${config:deckdir}/homebrew/'",
"group": "build",
"detail": "Update deck-frontend-lib aka DFL",
"command": "pnpm update decky-frontend-lib --latest",
"problemMatcher": []
},
//Used chmod plugins folder to allow copy-over of files
{
"label": "deployall",
"dependsOrder": "sequence",
"label": "chmodplugins",
"detail": "chmods plugins folder to prevent perms issues",
"type": "shell",
"group": "none",
"dependsOn": [
"deploy",
"chmodfolders"
],
"command": "ssh ${config:deckuser}@${config:deckip} -p ${config:deckport} ${config:deckkey} 'echo '${config:deckpass}' | sudo -S chmod -R ug+rw ${config:deckdir}/homebrew/plugins/'",
"problemMatcher": []
},
// ALL-IN-ONE
{
"label": "allinone",
"detail": "Build and deploy",
"dependsOrder": "sequence",
"group": "test",
"dependsOn": [
"buildall",
"deployall"
// Uncomment this line if you'd like your python code reloaded after deployment (this will restart Steam)
// ,"restartloader"
],
"problemMatcher": []
}
]
}
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ It sends the `SIGSTOP` signal to all the children of the reaper process to stop

It also allows to pause all games prior to system suspend which seems to fix some issues with crackling audio or freezing emulators.

The **Pause on focus loss** feature will automatically pause apps that are not in focus when switching between them. A bit like the Xbox quick-suspend/resume feature (without the dump to disk functionality unfortunately). If you manually change the state of an app (pause/resume) in this mode it will be stickied and not change state automatically anymore on focus change (depicted by a blue play/pause icon). To reset the stickied states, disable and re-enable **Pause on focus loss**.
The **Pause on focus loss** feature will automatically pause apps that are not in focus when switching between them. A bit like the Xbox quick-suspend/resume feature (without the dump to disk functionality unfortunately). If you manually change the state of an app (pause/resume) in this mode it will be stickied and not change state automatically anymore on focus change (depicted by a blue play/pause icon) until
it is manually changed back.

In addition to **Pause on focus loss**, **Also on overlay** will also pause apps when the Steam Overlay is on (by pressing the **STEAM** button).

Expand Down
56 changes: 7 additions & 49 deletions src/backend.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import {
Router,
ServerAPI,
AppOverview,
DisplayStatus,
sleep,
LifetimeNotification,
} from "decky-frontend-lib";
import { debounce, throttle } from "lodash";
import {
appid_from_pid,
is_paused,
pause,
pid_from_appid,
resume,
} from "./interop";
import { Settings } from "./settings";

// only the needed subset of the SteamClient
Expand Down Expand Up @@ -89,54 +95,6 @@ interface FocusChangeEvent {
};
}

var serverAPI: ServerAPI | undefined = undefined;

export function setServerAPI(s: ServerAPI) {
serverAPI = s;
}

export async function backend_call<I, O>(name: string, params: I): Promise<O> {
try {
const res = await serverAPI!.callPluginMethod<I, O>(name, params);
if (res.success) return res.result;
else {
console.error(res.result);
throw res.result;
}
} catch (e) {
console.error(e);
throw e;
}
}

export async function is_paused(pid: number): Promise<boolean> {
return backend_call<{ pid: number }, boolean>("is_paused", { pid });
}

export async function pause(pid: number): Promise<boolean> {
return backend_call<{ pid: number }, boolean>("pause", { pid });
}

export async function resume(pid: number): Promise<boolean> {
return backend_call<{ pid: number }, boolean>("resume", { pid });
}

export async function terminate(pid: number): Promise<boolean> {
return backend_call<{ pid: number }, boolean>("terminate", { pid });
}

export async function kill(pid: number): Promise<boolean> {
return backend_call<{ pid: number }, boolean>("kill", { pid });
}

export async function pid_from_appid(appid: number): Promise<number> {
return backend_call<{ appid: number }, number>("pid_from_appid", { appid });
}

export async function appid_from_pid(pid: number): Promise<number> {
return backend_call<{ pid: number }, number>("appid_from_pid", { pid });
}

let appMetaDataMap: {
[appid: number]: AppOverviewExtPG;
} = {};
Expand Down
Loading

0 comments on commit 147447a

Please sign in to comment.