mirror of
https://github.com/SteamDeckHomebrew/decky-loader.git
synced 2026-07-11 21:11:58 +00:00
feat(MoreCustomizableToasts): Allow plugin developers to customize some toast properties (#268)
* Use settingsStore directly * Change toast etype, add showToast/playSound * Update DFL and rebase
This commit is contained in:
@@ -41,7 +41,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"decky-frontend-lib": "^3.7.14",
|
"decky-frontend-lib": "^3.14.0",
|
||||||
"react-file-icon": "^1.2.0",
|
"react-file-icon": "^1.2.0",
|
||||||
"react-icons": "^4.4.0",
|
"react-icons": "^4.4.0",
|
||||||
"react-markdown": "^8.0.3",
|
"react-markdown": "^8.0.3",
|
||||||
|
|||||||
Generated
+4
-4
@@ -10,7 +10,7 @@ specifiers:
|
|||||||
'@types/react-file-icon': ^1.0.1
|
'@types/react-file-icon': ^1.0.1
|
||||||
'@types/react-router': 5.1.18
|
'@types/react-router': 5.1.18
|
||||||
'@types/webpack': ^5.28.0
|
'@types/webpack': ^5.28.0
|
||||||
decky-frontend-lib: ^3.7.14
|
decky-frontend-lib: ^3.14.0
|
||||||
husky: ^8.0.1
|
husky: ^8.0.1
|
||||||
import-sort-style-module: ^6.0.0
|
import-sort-style-module: ^6.0.0
|
||||||
inquirer: ^8.2.4
|
inquirer: ^8.2.4
|
||||||
@@ -30,7 +30,7 @@ specifiers:
|
|||||||
typescript: ^4.7.4
|
typescript: ^4.7.4
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
decky-frontend-lib: 3.7.14
|
decky-frontend-lib: 3.14.0
|
||||||
react-file-icon: 1.2.0_wcqkhtmu7mswc6yz4uyexck3ty
|
react-file-icon: 1.2.0_wcqkhtmu7mswc6yz4uyexck3ty
|
||||||
react-icons: 4.4.0_react@16.14.0
|
react-icons: 4.4.0_react@16.14.0
|
||||||
react-markdown: 8.0.3_vshvapmxg47tngu7tvrsqpq55u
|
react-markdown: 8.0.3_vshvapmxg47tngu7tvrsqpq55u
|
||||||
@@ -944,8 +944,8 @@ packages:
|
|||||||
dependencies:
|
dependencies:
|
||||||
ms: 2.1.2
|
ms: 2.1.2
|
||||||
|
|
||||||
/decky-frontend-lib/3.7.14:
|
/decky-frontend-lib/3.14.0:
|
||||||
resolution: {integrity: sha512-ShAoP3VqiwkJYukDBHsOF9fk7wYw0VaKpHw6j9WdzLxwZwBcg0J7QBNIFYP3nfA0UgEwSJVEg/22kONiplipmA==}
|
resolution: {integrity: sha512-cBGgS960ftGgpF/oDlRj02nISWq7rwKHIUzG7RJeHchLmz/M4W4OwDL2/oEYO+0WeSx/AWRHTIfLU27jdHiZYQ==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/decode-named-character-reference/1.0.2:
|
/decode-named-character-reference/1.0.2:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Patch, ToastData, afterPatch, findInReactTree, sleep } from 'decky-frontend-lib';
|
import { Module, Patch, ToastData, afterPatch, findInReactTree, findModuleChild, sleep } from 'decky-frontend-lib';
|
||||||
import { ReactNode } from 'react';
|
import { ReactNode } from 'react';
|
||||||
|
|
||||||
import Toast from './components/Toast';
|
import Toast from './components/Toast';
|
||||||
@@ -7,6 +7,7 @@ import Logger from './logger';
|
|||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
__TOASTER_INSTANCE: any;
|
__TOASTER_INSTANCE: any;
|
||||||
|
settingsStore: any;
|
||||||
NotificationStore: any;
|
NotificationStore: any;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,7 +17,7 @@ class Toaster extends Logger {
|
|||||||
// private toasterState: DeckyToasterState = new DeckyToasterState();
|
// private toasterState: DeckyToasterState = new DeckyToasterState();
|
||||||
private node: any;
|
private node: any;
|
||||||
private rNode: any;
|
private rNode: any;
|
||||||
private settingsModule: any;
|
private audioModule: any;
|
||||||
private finishStartup?: () => void;
|
private finishStartup?: () => void;
|
||||||
private ready: Promise<void> = new Promise((res) => (this.finishStartup = res));
|
private ready: Promise<void> = new Promise((res) => (this.finishStartup = res));
|
||||||
private toasterPatch?: Patch;
|
private toasterPatch?: Patch;
|
||||||
@@ -127,6 +128,17 @@ class Toaster extends Logger {
|
|||||||
this.rNode.stateNode.forceUpdate();
|
this.rNode.stateNode.forceUpdate();
|
||||||
delete this.rNode.stateNode.shouldComponentUpdate;
|
delete this.rNode.stateNode.shouldComponentUpdate;
|
||||||
|
|
||||||
|
this.audioModule = findModuleChild((m: Module) => {
|
||||||
|
if (typeof m !== 'object') return undefined;
|
||||||
|
for (let prop in m) {
|
||||||
|
try {
|
||||||
|
if (m[prop].PlayNavSound && m[prop].RegisterCallbackOnPlaySound) return m[prop];
|
||||||
|
} catch {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this.log('Initialized');
|
this.log('Initialized');
|
||||||
this.finishStartup?.();
|
this.finishStartup?.();
|
||||||
}
|
}
|
||||||
@@ -135,24 +147,31 @@ class Toaster extends Logger {
|
|||||||
// toast.duration = toast.duration || 5e3;
|
// toast.duration = toast.duration || 5e3;
|
||||||
// this.toasterState.addToast(toast);
|
// this.toasterState.addToast(toast);
|
||||||
await this.ready;
|
await this.ready;
|
||||||
const settings = this.settingsModule?.settings;
|
|
||||||
let toastData = {
|
let toastData = {
|
||||||
nNotificationID: window.NotificationStore.m_nNextTestNotificationID++,
|
nNotificationID: window.NotificationStore.m_nNextTestNotificationID++,
|
||||||
rtCreated: Date.now(),
|
rtCreated: Date.now(),
|
||||||
eType: 15,
|
eType: toast.eType || 11,
|
||||||
nToastDurationMS: toast.duration || (toast.duration = 5e3),
|
nToastDurationMS: toast.duration || (toast.duration = 5e3),
|
||||||
data: toast,
|
data: toast,
|
||||||
decky: true,
|
decky: true,
|
||||||
};
|
};
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
toastData.data.appid = () => 0;
|
toastData.data.appid = () => 0;
|
||||||
|
if (toast.sound === undefined) toast.sound = 6;
|
||||||
|
if (toast.playSound === undefined) toast.playSound = true;
|
||||||
|
if (toast.showToast === undefined) toast.showToast = true;
|
||||||
if (
|
if (
|
||||||
(settings?.bDisableAllToasts && !toast.critical) ||
|
(window.settingsStore.settings.bDisableAllToasts && !toast.critical) ||
|
||||||
(settings?.bDisableToastsInGame && !toast.critical && window.NotificationStore.BIsUserInGame())
|
(window.settingsStore.settings.bDisableToastsInGame &&
|
||||||
|
!toast.critical &&
|
||||||
|
window.NotificationStore.BIsUserInGame())
|
||||||
)
|
)
|
||||||
return;
|
return;
|
||||||
window.NotificationStore.m_rgNotificationToasts.push(toastData);
|
if (toast.playSound) this.audioModule?.PlayNavSound(toast.sound);
|
||||||
window.NotificationStore.DispatchNextToast();
|
if (toast.showToast) {
|
||||||
|
window.NotificationStore.m_rgNotificationToasts.push(toastData);
|
||||||
|
window.NotificationStore.DispatchNextToast();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit() {
|
deinit() {
|
||||||
|
|||||||
Reference in New Issue
Block a user