Skip to content

Commit b07d162

Browse files
committed
fix: Flex scaling from last commit
feat: Component row render
1 parent 2de488f commit b07d162

File tree

8 files changed

+120
-74
lines changed

8 files changed

+120
-74
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export const DownloadExtCommand = 'core-manager.download-extension';
22
export const UninstallExtCommand = 'core-manager.uninstall-extension';
3+
export const ReadInstalledComponents = 'core-manager.read-installed-components';
Lines changed: 48 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
import axios from 'axios';
22
import { XMLParser } from 'fast-xml-parser';
33
import { useAppSelector } from 'flashpoint-launcher-renderer-ext/hooks';
4-
import fs from 'fs';
5-
import path from 'path';
4+
import { runCommand } from 'flashpoint-launcher-renderer-ext/utils';
65
import { useEffect, useState } from 'react';
6+
import { ReadInstalledComponents } from '../commands';
77
import { selectComponentRootUrls } from '../select';
88

99
export function ComponentSubsection() {
1010
const [remoteInfo, setRemoteInfo] = useState<ManagerComponentRemoteInfo[]>([]);
11-
const [installedInfo, setInstalledInfo] = useState<Record<string, ManagerInstalledComponentInfo>>({});
11+
const [installedInfo, setInstalledInfo] = useState<ManagerInstalledComponentInfo[]>([]);
1212
const [ready, setReady] = useState(false);
13-
const componentsPath = useAppSelector(state => path.join(state.main.config.flashpointPath, 'Components'));
1413
const remoteComponentUrlsRaw = useAppSelector(selectComponentRootUrls);
1514

1615
useEffect(() => {
17-
readInstalledComponents(componentsPath)
16+
readInstalledComponents()
1817
.then((data) => {
1918
setInstalledInfo(data);
2019
setReady(true);
2120
})
22-
}, [componentsPath]);
21+
}, []);
2322

2423
useEffect(() => {
2524
const repoUrls = remoteComponentUrlsRaw
@@ -33,60 +32,61 @@ export function ComponentSubsection() {
3332
})
3433
}, [remoteComponentUrlsRaw]);
3534

36-
const componentList: Record<string, ManagerComponent> = {};
37-
if (ready) {
38-
for (const key in installedInfo) {
39-
componentList[key] = {
40-
installed: installedInfo[key],
41-
canUpdate: false,
42-
updateDiff: 0,
43-
};
35+
const componentList: ManagerComponent[] = installedInfo.map(comp => {
36+
return {
37+
id: comp.id,
38+
installed: comp,
39+
canUpdate: false,
40+
updateDiff: 0
4441
}
42+
});
43+
if (ready) {
4544
for (const remote of remoteInfo) {
46-
const comp = componentList[remote.id];
47-
if (comp) {
45+
const existingIdx = componentList.findIndex(c => c.id === c.id);
46+
if (existingIdx === -1) {
47+
componentList.push({
48+
id: remote.id,
49+
remote,
50+
canUpdate: true,
51+
updateDiff: remote.installSize
52+
});
53+
} else {
54+
const comp = componentList[existingIdx];
4855
comp.remote = remote;
4956
const installedSize = comp.installed ? comp.installed.size : 0;
5057
const installedHash = comp.installed ? comp.installed.hash : '';
5158
if (installedHash.toLowerCase() !== remote.hash.toLowerCase()) {
5259
comp.canUpdate = true;
5360
comp.updateDiff = installedSize - remote.installSize;
5461
}
55-
} else {
56-
componentList[remote.id] = {
57-
remote,
58-
canUpdate: true,
59-
updateDiff: remote.installSize
60-
}
6162
}
6263
}
6364
}
6465

66+
return <div className='manager-page-subsection'>
67+
<div className='manager-page-subsection-header'>Components</div>
68+
<div className='manager-page-subsection-list simple-scroll'>
69+
{ componentList.length > 0 ? componentList.map((comp, index) => {
70+
return (
71+
<ComponentRow
72+
comp={comp}
73+
index={index} />
74+
);
75+
}) : <div>Loading...</div>}
76+
</div>
77+
</div>;
6578
}
6679

67-
async function readInstalledComponents(componentsPath: string): Promise<Record<string, ManagerInstalledComponentInfo>> {
68-
await fs.promises.mkdir(componentsPath, { recursive: true });
69-
const files = await fs.promises.readdir(componentsPath);
70-
const components: Record<string, ManagerInstalledComponentInfo> = {};
71-
for (const file of files) {
72-
try {
73-
const filePath = path.join(componentsPath, file);
74-
const content = await fs.promises.readFile(filePath, { encoding: 'utf-8' });
75-
const lines = content.split('\n');
76-
const [hash, size] = lines[0].split(' ');
77-
if (hash.length !== 8) {
78-
throw 'Hash length invalid';
79-
}
80-
components[file] = {
81-
size: parseInt(size),
82-
hash,
83-
fileCount: lines.length - 1
84-
};
85-
} catch (err) {
86-
log.error('Manager', 'Failed to read component: ' + file);
87-
}
88-
}
89-
return components;
80+
function ComponentRow({ comp, index }: ComponentRowProps) {
81+
return (
82+
<div className='manager-component-row'>
83+
{comp.id}
84+
</div>
85+
);
86+
}
87+
88+
async function readInstalledComponents(): Promise<ManagerInstalledComponentInfo[]> {
89+
return runCommand(ReadInstalledComponents);
9090
}
9191

9292
async function getRemoteFromIndex(indexUrl: string): Promise<ManagerComponentRemoteInfo[]> {
@@ -141,27 +141,7 @@ async function getRemoteFromIndex(indexUrl: string): Promise<ManagerComponentRem
141141
return components;
142142
}
143143

144-
type ManagerComponent = {
145-
installed?: ManagerInstalledComponentInfo;
146-
remote?: ManagerComponentRemoteInfo;
147-
canUpdate: boolean;
148-
updateDiff: number;
149-
}
150-
151-
type ManagerInstalledComponentInfo = {
152-
size: number;
153-
hash: string;
154-
fileCount: number;
155-
}
156-
157-
type ManagerComponentRemoteInfo = {
158-
id: string;
159-
title: string;
160-
description: string;
161-
dateModified: string;
162-
downloadSize: number;
163-
installSize: number;
164-
path: string;
165-
hash: string;
166-
downloadUrl: string;
144+
export type ComponentRowProps = {
145+
comp: ManagerComponent;
146+
index: number;
167147
}

extensions/core-manager/src/components/ManagerPage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { LeftSidebarItem } from 'flashpoint-launcher-renderer';
22
import { LeftSidebar, StateWrapper } from 'flashpoint-launcher-renderer-ext/components';
33
import { useState } from 'react';
4+
import { ComponentSubsection } from './ComponentSubsection';
45
import { ExtensionSubsection } from './ExtensionSubsection';
56
import { SubsectionSettings } from './SettingsSubsection';
67

@@ -45,7 +46,7 @@ export default function ManagerPage() {
4546
<ExtensionSubsection/>
4647
</StateWrapper>
4748
<StateWrapper show={subsection === 'support-packs'}>
48-
<SubsectionSupportPacks/>
49+
<ComponentSubsection/>
4950
</StateWrapper>
5051
<StateWrapper show={subsection === 'utilities'}>
5152
<SubsectionUtilities/>

extensions/core-manager/src/extension.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,44 @@
11
import axios from 'axios';
2-
import { commands, Disposable, ExtensionContext, installExtension, log, registerDisposable, uninstallExtension } from 'flashpoint-launcher';
2+
import { commands, config, Disposable, ExtensionContext, installExtension, log, registerDisposable, uninstallExtension } from 'flashpoint-launcher';
33
import fs from 'node:fs';
44
import os from 'node:os';
55
import path from 'node:path';
6-
import { DownloadExtCommand, UninstallExtCommand } from './commands';
6+
import { DownloadExtCommand, ReadInstalledComponents, UninstallExtCommand } from './commands';
77

88
export async function activate(context: ExtensionContext): Promise<void> {
99
const register = (disp: Disposable) => {
1010
registerDisposable(context.subscriptions, disp);
1111
};
1212

13+
register(
14+
commands.registerCommand(ReadInstalledComponents, async () => {
15+
const componentsPath = path.join(config.flashpointPath, 'Components');
16+
await fs.promises.mkdir(componentsPath, { recursive: true });
17+
const files = await fs.promises.readdir(componentsPath);
18+
const components: ManagerInstalledComponentInfo[] = [];
19+
for (const file of files) {
20+
try {
21+
const filePath = path.join(componentsPath, file);
22+
const content = await fs.promises.readFile(filePath, { encoding: 'utf-8' });
23+
const lines = content.split('\n');
24+
const [hash, size] = lines[0].split(' ');
25+
if (hash.length !== 8) {
26+
throw 'Hash length invalid';
27+
}
28+
components.push({
29+
id: file,
30+
size: parseInt(size),
31+
hash,
32+
fileCount: lines.length - 1
33+
});
34+
} catch (err) {
35+
log.error('Failed to read component: ' + file);
36+
}
37+
}
38+
return components;
39+
})
40+
);
41+
1342
register(
1443
commands.registerCommand(DownloadExtCommand, async (extId: string, url: string) => {
1544
// Uninstall extension if it exists
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
type ManagerComponent = {
2+
id: string;
3+
installed?: ManagerInstalledComponentInfo;
4+
remote?: ManagerComponentRemoteInfo;
5+
canUpdate: boolean;
6+
updateDiff: number;
7+
}
8+
9+
type ManagerInstalledComponentInfo = {
10+
id: string;
11+
size: number;
12+
hash: string;
13+
fileCount: number;
14+
}
15+
16+
type ManagerComponentRemoteInfo = {
17+
id: string;
18+
title: string;
19+
description: string;
20+
dateModified: string;
21+
downloadSize: number;
22+
installSize: number;
23+
path: string;
24+
hash: string;
25+
downloadUrl: string;
26+
}

extensions/core-manager/static/core-manager.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
flex-grow: 1;
4242
}
4343

44+
.manager-component-row,
4445
.manager-extension-row {
4546
padding: 0.5rem;
4647
display: flex;

src/renderer/components/SplashScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function SplashScreen(props: SplashScreenProps) {
6262
) : undefined;
6363

6464
return (
65-
<div style={{ width: '100%', height: '100%', display: 'flex', flexDirection: 'column', position: 'relative' }}>
65+
<div className='main-wrapper'>
6666
{splashScreen}
6767
{loadedAll ? props.children : undefined}
6868
</div>

static/window/styles/core.css

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,17 +445,25 @@ body {
445445
width: 100%;
446446
height: 100%;
447447
}
448+
.main-wrapper {
449+
width: 100%;
450+
flex-grow: 1;
451+
display: flex;
452+
flex-direction: column;
453+
position: relative;
454+
overflow: hidden;
455+
}
448456
.main {
449457
display: flex;
450458
width: 100%;
451-
height: 100%;
452-
flex: 1;
459+
flex-grow: 1;
453460
overflow: hidden;
454461
}
455462

456463

457464
/* ------ TitleBar ------ */
458465
.title-bar {
466+
flex-shrink: 0;
459467
padding: 4px 0 0 4px;
460468
-webkit-user-select: none; /* Disable text selection */
461469
z-index: 1001; /* Hacky way of displaying it in from of the splash screen. */

0 commit comments

Comments
 (0)