Skip to content

Commit

Permalink
🚧 Fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
sl-miguel committed Dec 27, 2023
1 parent a70fdb2 commit 13075c5
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "exile-x",
"private": true,
"version": "0.2.1",
"version": "0.3.0",
"description": "A League Client Companion with automatisations",
"main": "dist-electron/main.js",
"author": "Gredon",
Expand Down
20 changes: 15 additions & 5 deletions plugins/Honor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,24 @@ class Honor {
this.endpoint = '/lol-gameflow/v1/gameflow-phase';
}

setup() {
reload() {
return [{ id: 'honor.player.name', keys: ['options'] }];
}

async setup(lcu) {
console.log('Honor.js loaded.');

const response = await lcu.request({ method: 'GET', url: `/lol-chat/v1/friends` });
const friends = response.json();

const defaultFriend = { puuid: '', summonerId: 0, gameName: 'Select a friend' };
const friendsObject = [defaultFriend, ...friends.map(({ puuid, summonerId, gameName }) => ({ puuid, summonerId, gameName }))];

const configuration = [
{ id: 'honor.system', type: 'radio', value: 'Shotcalling', options: ['Cool', 'Shotcalling', 'GG', 'Skip'] },
{ id: 'honor.player.type', type: 'radio', value: 'Best Player', options: ['Best Player', 'Random', 'Custom'] },
{ id: 'honor.player.name', type: 'text', value: 'GR0236621563#EUW' }, // temp
{ id: 'honor.message', type: 'paragraph', value: 'When opting for custom, it prioritizes honoring the selected friend.' },
{ id: 'honor.player.name', type: 'select', value: friendsObject[0], options: friendsObject }, // temp
];

return configuration;
Expand Down Expand Up @@ -65,9 +76,8 @@ class Honor {

case 'Custom':
const customPlayer = getSetting('honor.player.name');
const [customName, customTag] = customPlayer.value.split('#');
const response = await lcu.request({ method: 'GET', url: `/lol-summoner/v1/summoners?name=${customName}%23${customTag}` });
player = await response.json();
console.log('CUSTOM PLAYER / FRIEND', customPlayer.value);
player = customPlayer.value;
break;

default:
Expand Down
8 changes: 4 additions & 4 deletions src/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ const createWindow = async () => {
lcu.connect();

const pluginLoader = new Plugin(win, lcu);
await pluginLoader.load();

async function startPlugins() {
console.log('Loading plugins');
const plugins = pluginLoader.get();
for (const plugin of plugins) {
// @ts-ignore
await pluginLoader.execute(plugin.id);
}
}

pluginHandler(pluginLoader, win);

ipcMain.on('is-connected', (_, connected: boolean) => {
ipcMain.on('is-connected', async (_, connected: boolean) => {
console.log('isConnected', connected);
if (connected) startPlugins();
if (!connected) return;
await pluginLoader.load();
await startPlugins();
});

ipcMain.on('settings[update]', async (_, { plugin, setting }) => {
Expand Down
16 changes: 15 additions & 1 deletion src/electron/services/Plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,28 @@ class Plugin {
const Plugin = await require(path);

const plugin = new Plugin();
const settings = plugin.setup();
const settings = await plugin.setup(this.lcu);

plugin.id = pluginPath;
plugin.settings = settings;

const storedScript = await this.store.getItem(pluginPath);
if (storedScript) {
const parsedScript = JSON.parse(storedScript);

if ('reload' in plugin) {
const reloads = plugin.reload();

for (const { id, keys } of reloads) {
for (const key of keys) {
const reloadSetting = parsedScript.settings.find((set: any) => set.id === id);
const freshSetting = settings.find((set: any) => set.id === id);
reloadSetting[key] = freshSetting[key];
}
}
this.store.setItem(pluginPath, JSON.stringify(parsedScript));
}

Object.assign(plugin, parsedScript);
this.scripts.set(pluginPath, plugin);
continue;
Expand Down
35 changes: 35 additions & 0 deletions src/ui/components/settings/Select.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useEffect, useState } from 'react';

interface SelectProps {
plugin: any;
setting: any;
toParent: (plugin: any, updatedSetting: any) => void;
}

function Select({ plugin, setting, toParent }: SelectProps) {
const [value, setValue] = useState(setting.value);

useEffect(() => {
const updatedSettings = { ...setting, value };
toParent(plugin, updatedSettings);
}, [value]);

return (
<div>
<select
className="mb-2 mt-1 flex h-8 w-full items-center justify-between overflow-hidden rounded-md border border-gray px-3 focus:outline-black "
value={value.puuid}
id={setting.id}
onChange={(event) => setValue(setting.options.find((option: any) => option.puuid === event.target.value))}
>
{setting.options.map((option: any, index: number) => (
<option key={index} value={option.puuid}>
{option.gameName}
</option>
))}
</select>
</div>
);
}

export default Select;
2 changes: 2 additions & 0 deletions src/ui/pages/Plugins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Accordion from '../components/accordion/Accordion';
import AccordionBody from '../components/accordion/AccordionBody';
import AccordionHeader from '../components/accordion/AccordionHeader';
import Paragraph from '../components/settings/Paragraph';
import Select from '../components/settings/Select';

function Plugins() {
const [plugins, setPlugins] = useState([]);
Expand Down Expand Up @@ -61,6 +62,7 @@ function Plugins() {
{setting.type === 'text' && <Text plugin={plugin} setting={setting} toParent={handleSettings} />}
{setting.type === 'button' && <Button plugin={plugin} setting={setting} toParent={handlePress} />}
{setting.type === 'checkbox' && <Checkbox plugin={plugin} setting={setting} toParent={handleSettings} />}
{setting.type === 'select' && <Select plugin={plugin} setting={setting} toParent={handleSettings} />}
{setting.type === 'paragraph' && <Paragraph setting={setting} />}
</div>
))}
Expand Down

0 comments on commit 13075c5

Please sign in to comment.