generated from SteamDeckHomebrew/decky-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from mengmeet/toast
Add toast
- Loading branch information
Showing
9 changed files
with
138 additions
and
7 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
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
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,62 @@ | ||
import { Module, findModuleChild } from "decky-frontend-lib"; | ||
import { Backend } from "."; | ||
import { ReactNode } from "react"; | ||
import { FaSuperpowers } from "react-icons/fa"; | ||
|
||
//#region Find SteamOS modules | ||
const findModule = (property: string) => { | ||
return findModuleChild((m: Module) => { | ||
if (typeof m !== "object") return undefined; | ||
for (let prop in m) { | ||
try { | ||
if (m[prop][property]) return m[prop]; | ||
} catch { | ||
return undefined; | ||
} | ||
} | ||
}); | ||
}; | ||
// @ts-ignore | ||
const NavSoundMap = findModule("ToastMisc"); | ||
//#endregion | ||
|
||
export interface NotifyProps { | ||
message: ReactNode; | ||
title?: ReactNode; | ||
logo?: ReactNode; | ||
icon?: ReactNode; | ||
showToast?: boolean; | ||
playSound?: boolean; | ||
sound?: number; | ||
duration?: number; | ||
} | ||
|
||
export class SteamUtils { | ||
//#region Notification Wrapper | ||
static async notify({ | ||
title, | ||
message, | ||
logo, | ||
icon, | ||
showToast, | ||
playSound, | ||
sound, | ||
duration, | ||
}: NotifyProps) { | ||
let toastData = { | ||
title: title || "PowerControl", | ||
body: message, | ||
logo: logo, | ||
icon: icon || <FaSuperpowers />, | ||
duration: duration, | ||
sound: sound || NavSoundMap?.ToastMisc, | ||
playSound: playSound || false, | ||
showToast: showToast || false, | ||
}; | ||
Backend.getServerAPI().toaster.toast(toastData); | ||
} | ||
|
||
static async simpleToast(message: string, duration?: number) { | ||
this.notify({ message, showToast: true, duration }); | ||
} | ||
} |