Skip to content

Commit

Permalink
Merge pull request #42 from EMERALD0874/dev
Browse files Browse the repository at this point in the history
add window object for external control, as well as user vars
  • Loading branch information
beebls authored Jun 4, 2023
2 parents f65bfd3 + cfc5ca3 commit 251f8c7
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 22 deletions.
4 changes: 2 additions & 2 deletions audio_remoteinstall.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio, json, tempfile, os
from audio_utils import Result, Log
from audio_utils import AUDIO_LOADER_VERSION
from audio_utils import AUDIO_LOADER_VERSION, DECKY_HOME
import aiohttp

async def run(command : str) -> str:
Expand Down Expand Up @@ -45,7 +45,7 @@ async def install(id : str, base_url : str) -> Result:

Log(f"Unzipping {themeZipPath}")
try:
await run(f"unzip -o \"{themeZipPath}\" -d \"/home/deck/homebrew/sounds\"")
await run(f"unzip -o \"{themeZipPath}\" -d \"{DECKY_HOME}/sounds\"")
except Exception as e:
return Result(False, str(e))

Expand Down
4 changes: 3 additions & 1 deletion audio_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

Logger = getLogger("AUDIO_LOADER")
AUDIO_LOADER_VERSION = 2
DECKY_HOME = os.environ["DECKY_HOME"] # /home/user/homebrew
DECKY_USER_HOME = os.environ["DECKY_USER_HOME"] # /home/user

def Log(text : str):
Logger.info(f"[AUDIO_LOADER] {text}")
Expand All @@ -23,7 +25,7 @@ def to_dict(self):
return {"success": self.success, "message": self.message}

def store_path() -> str:
return os.path.join("/home/deck/homebrew/sounds", "STORE")
return os.path.join(DECKY_HOME, "sounds", "STORE")

def store_reads() -> dict:
path = store_path()
Expand Down
14 changes: 7 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

sys.path.append(os.path.dirname(__file__))

from audio_utils import store_read as util_store_read, store_write as util_store_write, AUDIO_LOADER_VERSION
from audio_utils import store_read as util_store_read, store_write as util_store_write, AUDIO_LOADER_VERSION, DECKY_HOME, DECKY_USER_HOME
from audio_remoteinstall import install

starter_config_data = {
Expand Down Expand Up @@ -111,7 +111,7 @@ async def download_theme_from_url(self, id : str, url : str) -> dict:
return (await install(id, url)).to_dict()

async def get_config(self) -> object:
configPath = "/home/deck/homebrew/sounds/config.json"
configPath = f"{DECKY_HOME}/sounds/config.json"

Log("Audio Loader - Fetching config file at {}".format(configPath))
if (os.path.exists(configPath)):
Expand All @@ -122,7 +122,7 @@ async def get_config(self) -> object:
return data

async def set_config(self, configObj: object):
configPath = "/home/deck/homebrew/sounds/config.json"
configPath = f"{DECKY_HOME}/sounds/config.json"

Log("Audio Loader - Setting config file at {}".format(configPath))
if (os.path.exists(configPath)):
Expand Down Expand Up @@ -189,10 +189,10 @@ async def store_write(self, key : str, val : str) -> dict:
return Result(True).to_dict()

async def _load(self):
packsPath = "/home/deck/homebrew/sounds"
symlinkPath = "/home/deck/.local/share/Steam/steamui/sounds_custom"

configPath = "/home/deck/homebrew/sounds/config.json"
packsPath = f"{DECKY_HOME}/sounds"
symlinkPath = f"{DECKY_USER_HOME}/.local/share/Steam/steamui/sounds_custom"
configPath = f"{DECKY_HOME}/sounds/config.json"

Log("Audio Loader - Finding sound packs...")
self.soundPacks = []
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"dependencies": {
"@types/lodash": "^4.14.191",
"decky-frontend-lib": "^3.19.2",
"decky-frontend-lib": "^3.21.0",
"lodash": "^4.17.21",
"react-icons": "^4.4.0"
},
Expand Down
7 changes: 6 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ export default defineConfig({
styles(),
],
context: "window",
external: ["react", "react-dom"],
external: [
"react",
"react-dom",
// "decky-frontend-lib"
],
output: {
file: "dist/index.js",
globals: {
react: "SP_REACT",
"react-dom": "SP_REACTDOM",
// "decky-frontend-lib": "DFL",
},
format: "iife",
exports: "default",
Expand Down
1 change: 1 addition & 0 deletions src/components/PackDisplayCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const PackDisplayCard: FC<{
backgroundImage: imageURLCreator(),
backgroundColor: "#21323d",
position: "absolute",
backgroundPosition: "center",
top: "10%",
left: "0",
width: "80%",
Expand Down
35 changes: 34 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({}) => {
newMenuMusic.play();
newMenuMusic.loop = true;
newMenuMusic.volume = musicVolume;
const setVolume = (value: number) => {
newMenuMusic.volume = value;
};
// Update menuMusic in globalState after every change so that it reflects the changes the next time it checks
// @ts-ignore
window.AUDIOLOADER_MENUMUSIC = {
play: newMenuMusic.play.bind(newMenuMusic),
pause: newMenuMusic.pause.bind(newMenuMusic),
origVolume: newMenuMusic.volume,
setVolume: setVolume.bind(this),
};
setGlobalState("menuMusic", newMenuMusic);
}
}
Expand Down Expand Up @@ -214,7 +225,9 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({}) => {
step={0.01}
onChange={(value) => {
setGlobalState("musicVolume", value);
menuMusic.volume = value;
menuMusic.origVolume = value;
// @ts-ignore
window.AUDIOLOADER_MENUMUSIC.volume = value;
const configObj = {
selected_pack: activeSound,
selected_music: selectedMusic,
Expand Down Expand Up @@ -423,6 +436,16 @@ export default definePlugin((serverApi: ServerAPI) => {
menuMusic.play();
menuMusic.loop = true;
menuMusic.volume = configMusicVolume;
const setVolume = (value: number) => {
menuMusic.volume = value;
};
// @ts-ignore
window.AUDIOLOADER_MENUMUSIC = {
play: menuMusic.play.bind(menuMusic),
pause: menuMusic.pause.bind(menuMusic),
origVolume: menuMusic.volume,
setVolume: setVolume.bind(this),
};
console.log("play and loop ran", menuMusic);
setGlobalState("menuMusic", menuMusic);
}
Expand Down Expand Up @@ -484,7 +507,17 @@ export default definePlugin((serverApi: ServerAPI) => {
newMenuMusic.play();
newMenuMusic.loop = true;
newMenuMusic.volume = musicVolume;
const setVolume = (value: number) => {
newMenuMusic.volume = value;
};
// Update menuMusic in globalState after every change so that it reflects the changes the next time it checks
// @ts-ignore
window.AUDIOLOADER_MENUMUSIC = {
play: newMenuMusic.play.bind(newMenuMusic),
pause: newMenuMusic.pause.bind(newMenuMusic),
origVolume: newMenuMusic.volume,
setVolume: setVolume.bind(this),
};
setGlobalState("menuMusic", newMenuMusic);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/pack-manager/SettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const SettingsPage: VFC = () => {
<span>
See the DeckThemes Discord server for support.
<br />
discord.gg/HsU72Kfnpf
deckthemes.com/discord
</span>
</div>
<div>
Expand All @@ -143,7 +143,7 @@ export const SettingsPage: VFC = () => {
Create and Submit Your Own Packs
</h2>
<span>
Instructions for theme creation/submission are available
Instructions for theme creation/submission are available on
DeckThemes' docs website.
<br />
docs.deckthemes.com
Expand Down

0 comments on commit 251f8c7

Please sign in to comment.