Skip to content

Commit 13075c5

Browse files
committed
🚧 Fix #1
1 parent a70fdb2 commit 13075c5

File tree

6 files changed

+72
-11
lines changed

6 files changed

+72
-11
lines changed

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "exile-x",
33
"private": true,
4-
"version": "0.2.1",
4+
"version": "0.3.0",
55
"description": "A League Client Companion with automatisations",
66
"main": "dist-electron/main.js",
77
"author": "Gredon",

‎plugins/Honor.js‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,24 @@ class Honor {
88
this.endpoint = '/lol-gameflow/v1/gameflow-phase';
99
}
1010

11-
setup() {
11+
reload() {
12+
return [{ id: 'honor.player.name', keys: ['options'] }];
13+
}
14+
15+
async setup(lcu) {
1216
console.log('Honor.js loaded.');
1317

18+
const response = await lcu.request({ method: 'GET', url: `/lol-chat/v1/friends` });
19+
const friends = response.json();
20+
21+
const defaultFriend = { puuid: '', summonerId: 0, gameName: 'Select a friend' };
22+
const friendsObject = [defaultFriend, ...friends.map(({ puuid, summonerId, gameName }) => ({ puuid, summonerId, gameName }))];
23+
1424
const configuration = [
1525
{ id: 'honor.system', type: 'radio', value: 'Shotcalling', options: ['Cool', 'Shotcalling', 'GG', 'Skip'] },
1626
{ id: 'honor.player.type', type: 'radio', value: 'Best Player', options: ['Best Player', 'Random', 'Custom'] },
17-
{ id: 'honor.player.name', type: 'text', value: 'GR0236621563#EUW' }, // temp
27+
{ id: 'honor.message', type: 'paragraph', value: 'When opting for custom, it prioritizes honoring the selected friend.' },
28+
{ id: 'honor.player.name', type: 'select', value: friendsObject[0], options: friendsObject }, // temp
1829
];
1930

2031
return configuration;
@@ -65,9 +76,8 @@ class Honor {
6576

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

7383
default:

‎src/electron/main.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,22 @@ const createWindow = async () => {
5050
lcu.connect();
5151

5252
const pluginLoader = new Plugin(win, lcu);
53-
await pluginLoader.load();
5453

5554
async function startPlugins() {
5655
console.log('Loading plugins');
5756
const plugins = pluginLoader.get();
5857
for (const plugin of plugins) {
59-
// @ts-ignore
6058
await pluginLoader.execute(plugin.id);
6159
}
6260
}
6361

6462
pluginHandler(pluginLoader, win);
6563

66-
ipcMain.on('is-connected', (_, connected: boolean) => {
64+
ipcMain.on('is-connected', async (_, connected: boolean) => {
6765
console.log('isConnected', connected);
68-
if (connected) startPlugins();
66+
if (!connected) return;
67+
await pluginLoader.load();
68+
await startPlugins();
6969
});
7070

7171
ipcMain.on('settings[update]', async (_, { plugin, setting }) => {

‎src/electron/services/Plugin.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,28 @@ class Plugin {
5252
const Plugin = await require(path);
5353

5454
const plugin = new Plugin();
55-
const settings = plugin.setup();
55+
const settings = await plugin.setup(this.lcu);
5656

5757
plugin.id = pluginPath;
5858
plugin.settings = settings;
5959

6060
const storedScript = await this.store.getItem(pluginPath);
6161
if (storedScript) {
6262
const parsedScript = JSON.parse(storedScript);
63+
64+
if ('reload' in plugin) {
65+
const reloads = plugin.reload();
66+
67+
for (const { id, keys } of reloads) {
68+
for (const key of keys) {
69+
const reloadSetting = parsedScript.settings.find((set: any) => set.id === id);
70+
const freshSetting = settings.find((set: any) => set.id === id);
71+
reloadSetting[key] = freshSetting[key];
72+
}
73+
}
74+
this.store.setItem(pluginPath, JSON.stringify(parsedScript));
75+
}
76+
6377
Object.assign(plugin, parsedScript);
6478
this.scripts.set(pluginPath, plugin);
6579
continue;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { useEffect, useState } from 'react';
2+
3+
interface SelectProps {
4+
plugin: any;
5+
setting: any;
6+
toParent: (plugin: any, updatedSetting: any) => void;
7+
}
8+
9+
function Select({ plugin, setting, toParent }: SelectProps) {
10+
const [value, setValue] = useState(setting.value);
11+
12+
useEffect(() => {
13+
const updatedSettings = { ...setting, value };
14+
toParent(plugin, updatedSettings);
15+
}, [value]);
16+
17+
return (
18+
<div>
19+
<select
20+
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 "
21+
value={value.puuid}
22+
id={setting.id}
23+
onChange={(event) => setValue(setting.options.find((option: any) => option.puuid === event.target.value))}
24+
>
25+
{setting.options.map((option: any, index: number) => (
26+
<option key={index} value={option.puuid}>
27+
{option.gameName}
28+
</option>
29+
))}
30+
</select>
31+
</div>
32+
);
33+
}
34+
35+
export default Select;

‎src/ui/pages/Plugins.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Accordion from '../components/accordion/Accordion';
1111
import AccordionBody from '../components/accordion/AccordionBody';
1212
import AccordionHeader from '../components/accordion/AccordionHeader';
1313
import Paragraph from '../components/settings/Paragraph';
14+
import Select from '../components/settings/Select';
1415

1516
function Plugins() {
1617
const [plugins, setPlugins] = useState([]);
@@ -61,6 +62,7 @@ function Plugins() {
6162
{setting.type === 'text' && <Text plugin={plugin} setting={setting} toParent={handleSettings} />}
6263
{setting.type === 'button' && <Button plugin={plugin} setting={setting} toParent={handlePress} />}
6364
{setting.type === 'checkbox' && <Checkbox plugin={plugin} setting={setting} toParent={handleSettings} />}
65+
{setting.type === 'select' && <Select plugin={plugin} setting={setting} toParent={handleSettings} />}
6466
{setting.type === 'paragraph' && <Paragraph setting={setting} />}
6567
</div>
6668
))}

0 commit comments

Comments
 (0)