generated from SteamDeckHomebrew/decky-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
292 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { PanelSectionRow, ToggleField } from "decky-frontend-lib"; | ||
import { setAppState, useAppState } from "../../util/state"; | ||
|
||
export default function ConfigurationSection() { | ||
const appState = useAppState(); | ||
|
||
return ( | ||
<> | ||
<PanelSectionRow> | ||
<ToggleField | ||
label="Sync after closing a game" | ||
checked={appState.auto_backup_enabled === "true"} | ||
onChange={(e) => setAppState("auto_backup_enabled", e ? "true" : "false", true)} | ||
/> | ||
</PanelSectionRow> | ||
<PanelSectionRow> | ||
<ToggleField | ||
disabled={appState.auto_backup_enabled !== "true"} | ||
label="Toast after auto sync" | ||
checked={appState.auto_backup_toast_enabled === "true"} | ||
onChange={(e) => setAppState("auto_backup_toast_enabled", e ? "true" : "false", true)} | ||
/> | ||
</PanelSectionRow> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React, { PropsWithChildren } from "react"; | ||
|
||
export default function DeckyStoreButton({ icon, children }: PropsWithChildren<{ icon: React.ReactElement }>) { | ||
return ( | ||
<div style={{ display: "flex", alignItems: "center", justifyContent: "space-between" }}> | ||
{icon} | ||
<div>{children}</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,74 @@ | ||
import { | ||
ButtonItem, | ||
DialogBody, | ||
DialogControlsSection, | ||
DialogControlsSectionHeader, | ||
DialogHeader, | ||
Dropdown, | ||
ModalRoot, | ||
SimpleModal, | ||
showModal, | ||
} from "decky-frontend-lib"; | ||
import { ButtonItem, ConfirmModal, Dropdown, showModal } from "decky-frontend-lib"; | ||
import { useAppState } from "../../util/state"; | ||
import { FC, VFC } from "react"; | ||
import { FC, VFC, useEffect, useMemo, useState } from "react"; | ||
import { backupGame } from "../../util/apiClient"; | ||
import DeckyStoreButton from "./DeckyStoreButton"; | ||
import { FaSave } from "react-icons/fa"; | ||
|
||
const SelectPreviousGameDropdown: FC<{ onChange: (gameName: string) => void }> = ({ onChange }) => { | ||
|
||
const SelectPreviousGameDropdown: FC<{ onSelected: (gameName: string) => void }> = ({ onSelected }) => { | ||
const { recent_games } = useAppState(); | ||
const [selected, setSelected] = useState<string>(); | ||
|
||
useEffect(() => { | ||
if (recent_games[0]) update(recent_games[0]); | ||
}, [recent_games]); | ||
|
||
const update = (game: string) => { | ||
setSelected(game); | ||
onSelected(game); | ||
}; | ||
|
||
const data = useMemo(() => { | ||
if (recent_games.length === 0) { | ||
return [{ label: "N/A - Open a supported game for it to show up here", data: undefined }]; | ||
} | ||
|
||
return recent_games.map((g) => ({ label: g, data: g })); | ||
}, [recent_games]); | ||
|
||
return <Dropdown rgOptions={data} selectedOption={selected} onChange={(e) => update(e.data)} />; | ||
}; | ||
|
||
const SyncConfirmationModal: VFC<{ closeModal: () => void }> = ({ closeModal }) => { | ||
const SyncConfirmationModal: VFC<{ closeModal?: () => void }> = ({ closeModal }) => { | ||
const [selectedGame, setSelectedGame] = useState<string>(); | ||
|
||
return ( | ||
<ModalRoot closeModal={closeModal}> | ||
<DialogHeader>Select game to backup</DialogHeader> | ||
<DialogBody> | ||
<Dropdown rgOptions={[{ label: "", data: 1 }]} /> | ||
<DialogControlsSection> | ||
<DialogControlsSectionHeader>Syncthing Process Log</DialogControlsSectionHeader> | ||
<ButtonItem>Show Current Log</ButtonItem> | ||
</DialogControlsSection> | ||
</DialogBody> | ||
</ModalRoot> | ||
<ConfirmModal | ||
strTitle="Select recently played game" | ||
onOK={() => { | ||
backupGame(selectedGame!); | ||
}} | ||
bOKDisabled={!selectedGame} | ||
closeModal={closeModal} | ||
> | ||
<SelectPreviousGameDropdown onSelected={setSelectedGame} /> | ||
</ConfirmModal> | ||
); | ||
}; | ||
|
||
export default function SyncNowButton() { | ||
const { ludusavi_enabled } = useAppState(); | ||
const { ludusavi_enabled, syncing } = useAppState(); | ||
|
||
return ( | ||
<ButtonItem layout="below" disabled={ludusavi_enabled === "false"} onClick={(e: Event) => showModal(<SyncConfirmationModal />)}> | ||
Sync Now | ||
<ButtonItem layout="below" disabled={ludusavi_enabled === "false" || syncing} onClick={() => showModal(<SyncConfirmationModal />)}> | ||
<style> | ||
{` | ||
.dcs-rotate { | ||
animation: dcsrotate 1s infinite cubic-bezier(0.46, 0.03, 0.52, 0.96); | ||
} | ||
@keyframes dcsrotate { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(359deg); | ||
} | ||
} | ||
`} | ||
</style> | ||
<DeckyStoreButton icon={<FaSave className={syncing ? "dcs-rotate" : ""} />}>Sync Now</DeckyStoreButton> | ||
</ButtonItem> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.