Skip to content

Commit

Permalink
add ability to mute built in controller support
Browse files Browse the repository at this point in the history
  • Loading branch information
antheas committed Jul 24, 2024
1 parent b4e4dab commit 47e2182
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
22 changes: 22 additions & 0 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ const createMainWindow = async () => {
if (line.startsWith("action:")) {
processAction(line.trim().substring(7));
return;
} else if (line.includes("cmd:mute")) {
console.error(`Disabling built-in controller support.`);
mainWindow.webContents.executeJavaScript(
`window.electronUtils.setControllerApi(false);`
);
return;
} else if (line.includes("cmd:unmute")) {
console.error(`Enabling built-in controller support.`);
mainWindow.webContents.executeJavaScript(
`window.electronUtils.setControllerApi(true);`
);
return;
} else if (!line.startsWith("cmd:open_")) return;

if (line.includes("open_qam_if_closed")) {
Expand Down Expand Up @@ -264,6 +276,16 @@ const createMainWindow = async () => {
const processCmd = (cmd) => {
let uiType = null;
switch (cmd) {
case "mute":
console.error(`Disabling built-in controller support.`);
mainWindow.webContents.executeJavaScript(
`window.electronUtils.setControllerApi(false);`
);
case "unmute":
console.error(`Enabling built-in controller support.`);
mainWindow.webContents.executeJavaScript(
`window.electronUtils.setControllerApi(true);`
);
case "open_qam_if_closed":
// Preopen qam when the qam button is pressed a second
// time to minimize delay
Expand Down
5 changes: 5 additions & 0 deletions src/model/controller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DiscreteSetting, MultipleSetting, NumberSetting } from "./common";
import local from "./local";
import hhdSlice, {
selectAppType,
selectControllersApi,
selectFocusedPath,
selectFocusedSetting,
selectHasSelection,
Expand Down Expand Up @@ -250,6 +251,10 @@ export const setupGamepadEventListener = () => {
state = {}; // Prevent freezing state
return;
}
if (!selectControllersApi(sstate)) {
state = {};
return;
}

for (const [gidx, gp] of navigator.getGamepads().entries()) {
if (!gp) continue;
Expand Down
4 changes: 4 additions & 0 deletions src/model/electron.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ export const sendGamepadEvent = (ev: string) => {
store.dispatch(hhdSlice.actions.setController(true));
handleGamepadCommands([ev]);
};

export const setControllerApi = (enabled: boolean) => {
store.dispatch(hhdSlice.actions.setControllerApi(enabled));
};
9 changes: 9 additions & 0 deletions src/model/slice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ interface AppState {
prevUiType: PrevUiType;
appType: AppType;
controller: boolean;
controllersApi: boolean;
visible: boolean;
login: boolean;
state: State;
Expand All @@ -92,6 +93,7 @@ const initialState = {
prevUiType: "init",
appType: "web",
controller: false,
controllersApi: true,
visible: true,
login: true,
state: {},
Expand Down Expand Up @@ -154,6 +156,9 @@ const slice = createSlice({
store.uiType = "qam";
}
},
setControllerApi: (store, action: PayloadAction<boolean>) => {
store.controllersApi = action.payload;
},
setAppType: (store, action: PayloadAction<AppType>) => {
store.appType = action.payload;
if (action.payload === "overlay") store.controller = true;
Expand Down Expand Up @@ -506,6 +511,10 @@ export const selectState = (state: RootState) => {
return state.hhd.state;
};

export const selectControllersApi = (state: RootState) => {
return state.hhd.controllersApi;
};

export const selectSettingState = (path: string) => {
return (state: RootState) => {
return get(state.hhd.state, path, null);
Expand Down

0 comments on commit 47e2182

Please sign in to comment.