Skip to content

Commit

Permalink
Fix character creation detection
Browse files Browse the repository at this point in the history
  • Loading branch information
pboutin committed Sep 7, 2024
1 parent 03cbc73 commit 36c5cb3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
4 changes: 0 additions & 4 deletions src/electron/dofus-windows-adapters/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ const listDofusWindows = () => {
GetClassName(hwnd, windowClassBuffer, windowClassBuffer.length);
const windowClass = koffi.decode(windowClassBuffer, 'char', 100);

if (windowName.includes('Infah')) {
console.log(windowName, windowClass);
}

const match = windowName.match(/(.+) - (Dofus )?2\./);
if (!match) return true;

Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,8 @@ export interface KeyboardShortcut {
keybind: string;
argument?: string;
}

export interface DofusWindow {
windowName: string;
character: string;
}
12 changes: 10 additions & 2 deletions src/ui/hooks/use-ipc-renderer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { useCallback, useEffect, useState } from 'react';

import { GenericModel, Character, KeyboardShortcut, Team, InstantiatedCharacter, Config } from '../../types';
import {
GenericModel,
Character,
KeyboardShortcut,
Team,
InstantiatedCharacter,
Config,
DofusWindow,
} from '../../types';

const ipcRenderer = window.require('electron').ipcRenderer;

Expand Down Expand Up @@ -155,7 +163,7 @@ export function useConfig() {
}

export function useDofusWindows() {
const [dofusWindows, setDofusWindows] = useState<string[]>([]);
const [dofusWindows, setDofusWindows] = useState<DofusWindow[]>([]);

useEffect(() => {
ipcRenderer.invoke('dofusWindows:fetchAll').then(setDofusWindows);
Expand Down
10 changes: 5 additions & 5 deletions src/ui/windows/settings/characters/character-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const CharacterForm = ({ character, onChange, onSubmit, onCancel }: Props) => {

const pendingDofusWindows = useMemo(() => {
return dofusWindows.filter(
(characterName) => !existingCharacters.some((character) => character.name === characterName),
(dofusWindow) => !existingCharacters.some((character) => character.name === dofusWindow.character),
);
}, [dofusWindows, existingCharacters]);

Expand All @@ -43,14 +43,14 @@ const CharacterForm = ({ character, onChange, onSubmit, onCancel }: Props) => {
</div>

<div className="flex gap-2 flex-wrap">
{pendingDofusWindows.map((characterName) => (
{pendingDofusWindows.map((dofusWindow) => (
<button
key={characterName}
key={dofusWindow.character}
type="button"
className="btn btn-xs btn-primary"
onClick={() => onChange({ ...character, name: characterName })}
onClick={() => onChange({ ...character, name: dofusWindow.character })}
>
{characterName}
{dofusWindow.character}
</button>
))}
</div>
Expand Down

0 comments on commit 36c5cb3

Please sign in to comment.