Skip to content

Commit 92ecc28

Browse files
committed
Added app discovery + fixed config logic
1 parent a99cc2a commit 92ecc28

File tree

4 files changed

+142
-14
lines changed

4 files changed

+142
-14
lines changed

DeskThingServer/src/main/services/client/clientService.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ export const getClientManifest = async (): Promise<ClientManifest | null> => {
115115
// TODO: Client validation
116116
return JSON.parse(data) as ClientManifest
117117
} catch (error) {
118-
logger.error('Error getting client manifest:', {
119-
error: error as Error
118+
logger.error('(nonfatal) Error getting client manifest:', {
119+
error: error as Error,
120+
store: 'releaseUtils',
121+
method: 'getClientManifest'
120122
})
121123
return null
122124
}

DeskThingServer/src/main/services/releases/releaseUtils.ts

Lines changed: 109 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,8 @@ export async function handleRefreshReleaseFile<T extends 'app' | 'client'>(
459459

460460
const repositories = releaseFile.repositories || []
461461

462+
const updatedAppReleases: AppLatestServer[] = []
463+
462464
try {
463465
update(`Fetching the new list of available apps`, 80)
464466
const githubStore = await storeProvider.getStore('githubStore')
@@ -486,13 +488,62 @@ export async function handleRefreshReleaseFile<T extends 'app' | 'client'>(
486488
repositories.push(...newRepos)
487489
}
488490

489-
update(`Found ${repositories.length} apps with ${newRepos.length} new repositories`, 95)
491+
update(`Found ${repositories.length} apps with ${newRepos.length} new repositories`, 90)
490492

491493
// Now just as a bonus, see if there are any new app IDs included in the multi release
492494
// TODO: Actually do that for the love of *** I'll never be done with having to update my stupid release logic
493495
// I'm debating if I should re-couple the multi release wit the individual releases cuz release discovery is *stupid* and I think I would rather *die*
494496
// send help
495497

498+
// Now just quickly go over the available apps and see if there are any new ones
499+
500+
// First get an easily mappable list of existing app IDs
501+
const existingAppIds = migratedReleases.map((release) => release.id)
502+
503+
// Then iterate over the server's app IDs and find any new ones
504+
505+
if (
506+
'fileIds' in latestJSON &&
507+
Array.isArray(latestJSON.fileIds) &&
508+
latestJSON.fileIds.length > 0
509+
) {
510+
const newAppIds = latestJSON.fileIds.filter((id) => !existingAppIds.includes(id))
511+
512+
if (newAppIds.length > 0) {
513+
// If there are new ones, then add those just like the addMultiReleaseServer does
514+
update(`Found ${newAppIds.length} new app IDs`, 93)
515+
516+
const results = await Promise.allSettled(
517+
newAppIds.map(async (fileId) =>
518+
convertIdToReleaseServer(fileId, appsRepo, allReleases)
519+
) ?? []
520+
)
521+
522+
// Get the successful results
523+
const apps = results
524+
.filter((result) => result.status === 'fulfilled')
525+
.map((result) => result.value) as AppLatestServer[]
526+
527+
// Handle logging the errors
528+
results
529+
.filter((result): result is PromiseRejectedResult => result.status === 'rejected')
530+
.forEach((result, index) => {
531+
const fileId = newAppIds[index]
532+
logger.warn(
533+
`Unable to convert ${fileId} to a full release using ${appsRepo} because ${handleError(result.reason)}`,
534+
{ function: 'refreshReleaseFile', source: 'handleRefreshReleaseFile' }
535+
)
536+
})
537+
538+
updatedAppReleases.push(...apps)
539+
}
540+
}
541+
542+
// If there are new ones, then add those just like the addMultiReleaseServer does
543+
544+
// Add those to the current working structure
545+
546+
// Stonks?
496547
} catch (error) {
497548
logger.warn(`Error fetching releases for ${appsRepo}: ${handleError(error)}`)
498549
update(`Failed to find new repos, reverting and continuing anyways`, 95)
@@ -502,7 +553,7 @@ export async function handleRefreshReleaseFile<T extends 'app' | 'client'>(
502553
version: '0.11.11',
503554
type: 'app',
504555
repositories: releaseFile.repositories,
505-
releases: migratedReleases as AppLatestServer[],
556+
releases: [...updatedAppReleases, ...(migratedReleases as AppLatestServer[])],
506557
timestamp: Date.now()
507558
}
508559
update('Saving app release file', 100)
@@ -543,8 +594,10 @@ export async function handleRefreshReleaseFile<T extends 'app' | 'client'>(
543594

544595
const repositories = releaseFile.repositories || []
545596

597+
const updatedClientReleases: ClientLatestServer[] = []
598+
546599
try {
547-
update(`Fetching the new list of available apps`, 80)
600+
update(`Fetching the new list of available clients`, 80)
548601
const githubStore = await storeProvider.getStore('githubStore')
549602
const allReleases = await githubStore.getAllReleases(clientRepo, force)
550603

@@ -570,7 +623,58 @@ export async function handleRefreshReleaseFile<T extends 'app' | 'client'>(
570623
repositories.push(...newRepos)
571624
}
572625

573-
update(`Found ${repositories.length} apps with ${newRepos.length} new repositories`, 95)
626+
update(`Found ${repositories.length} apps with ${newRepos.length} new repositories`, 90)
627+
628+
// Now just as a bonus, see if there are any new app IDs included in the multi release
629+
// TODO: Actually do that for the love of *** I'll never be done with having to update my stupid release logic
630+
// I'm debating if I should re-couple the multi release wit the individual releases cuz release discovery is *stupid* and I think I would rather *die*
631+
// send help
632+
633+
// Now just quickly go over the available apps and see if there are any new ones
634+
635+
// First get an easily mappable list of existing app IDs
636+
const existingAppIds = migratedReleases.map((release) => release.id)
637+
638+
// Then iterate over the server's app IDs and find any new ones
639+
640+
if (
641+
'fileIds' in latestJSON &&
642+
Array.isArray(latestJSON.fileIds) &&
643+
latestJSON.fileIds.length > 0
644+
) {
645+
const newAppIds = latestJSON.fileIds.filter((id) => !existingAppIds.includes(id))
646+
647+
if (newAppIds.length > 0) {
648+
// If there are new ones, then add those just like the addMultiReleaseServer does
649+
update(`Found ${newAppIds.length} new app IDs`, 93)
650+
651+
const results = await Promise.allSettled(
652+
newAppIds.map(async (fileId) =>
653+
convertIdToReleaseServer(fileId, clientRepo, allReleases)
654+
) ?? []
655+
)
656+
657+
// Get the successful results
658+
const apps = results
659+
.filter((result) => result.status === 'fulfilled')
660+
.map((result) => result.value) as ClientLatestServer[]
661+
662+
// Handle logging the errors
663+
results
664+
.filter((result): result is PromiseRejectedResult => result.status === 'rejected')
665+
.forEach((result, index) => {
666+
const fileId = newAppIds[index]
667+
logger.warn(
668+
`Unable to convert ${fileId} to a full release using ${clientRepo} because ${handleError(result.reason)}`,
669+
{ function: 'refreshReleaseFile', source: 'handleRefreshReleaseFile' }
670+
)
671+
})
672+
673+
update(`Found ${apps.length} new apps`, 95)
674+
675+
updatedClientReleases.push(...apps)
676+
}
677+
}
574678
} catch (error) {
575679
logger.warn(`Error fetching releases for ${clientRepo}: ${handleError(error)}`)
576680
update(`Failed to find new repos, reverting and continuing anyways`, 95)
@@ -580,7 +684,7 @@ export async function handleRefreshReleaseFile<T extends 'app' | 'client'>(
580684
version: '0.11.11',
581685
type: 'client',
582686
repositories: repositories,
583-
releases: migratedReleases as ClientLatestServer[],
687+
releases: [...updatedClientReleases, ...(migratedReleases as ClientLatestServer[])],
584688
timestamp: Date.now()
585689
}
586690
update('Saving client release file', 100)

DeskThingServer/src/main/stores/platforms/superbird/adbService.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export class ADBService implements ADBServiceClass {
2626
reject: (error: unknown) => void
2727
}[]
2828
} = {}
29+
private connectionPort: number = 8891 // Default port for ADB connections
2930
private blacklist: string[] = []
3031

3132
constructor() {
@@ -41,6 +42,12 @@ export class ADBService implements ADBServiceClass {
4142
settingStore.on('adb_blacklist', (blacklist) => {
4243
this.blacklist = blacklist || []
4344
})
45+
46+
settingStore.on('device_devicePort', (port) => {
47+
if (port && typeof port === 'number') {
48+
this.connectionPort = port
49+
}
50+
})
4451
}
4552

4653
public async sendCommand(command: string, deviceId?: string): Promise<string> {
@@ -204,8 +211,10 @@ export class ADBService implements ADBServiceClass {
204211
const manifestData = await this.getDeviceManifest(deviceId)
205212
return manifestData?.version || '0.0.0'
206213
} catch (error) {
207-
logger.error('Error getting device manifest version:', {
208-
error: error as Error
214+
logger.error('(nonfatal) Error getting device manifest version!', {
215+
error: error as Error,
216+
store: 'adbService',
217+
method: 'getDeviceManifestVersion'
209218
})
210219
return '0.0.0'
211220
}
@@ -225,7 +234,16 @@ export class ADBService implements ADBServiceClass {
225234
): Promise<void> {
226235
progressBus.start(ProgressChannel.CONFIGURE_DEVICE, 'Configure Device', 'Opening port')
227236

228-
await this.openPort(deviceId, port)
237+
const result = await new Promise((resolve) => {
238+
this.openPort(deviceId, port)
239+
.then(() => resolve(true))
240+
.catch(() => resolve(false))
241+
})
242+
progressBus.update(
243+
ProgressChannel.CONFIGURE_DEVICE,
244+
`Port opened ${result ? 'successfully' : 'unsuccessfully'}`,
245+
5
246+
)
229247

230248
progressBus.update(ProgressChannel.CONFIGURE_DEVICE, 'Finding Client', 10)
231249

@@ -257,10 +275,14 @@ export class ADBService implements ADBServiceClass {
257275
this.configureDevice(deviceId, port, forcePush, attempts + 1)
258276
}
259277

278+
// Successfully downloaded the latest client, can move on
279+
260280
progressBus.update(ProgressChannel.CONFIGURE_DEVICE, 'Getting device version', 20)
261281

262282
const deviceVersion = await this.getDeviceManifestVersion(deviceId)
283+
263284
progressBus.update(ProgressChannel.CONFIGURE_DEVICE, 'Getting device manifest', 30)
285+
264286
const clientManifest = await getClientManifest()
265287

266288
progressBus.update(ProgressChannel.CONFIGURE_DEVICE, 'Checking for updates', 40)
@@ -278,7 +300,7 @@ export class ADBService implements ADBServiceClass {
278300
name: 'Car Thing',
279301
id: 4,
280302
ip: 'localhost',
281-
port: 8891
303+
port: this.connectionPort
282304
}
283305
})
284306

@@ -289,7 +311,7 @@ export class ADBService implements ADBServiceClass {
289311
name: 'Car Thing',
290312
id: 4,
291313
ip: 'localhost',
292-
port: 8891
314+
port: this.connectionPort
293315
}
294316
})
295317

DeskThingServer/src/renderer/src/components/Client/Connection.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {
22
IconCarThingSmall,
33
IconComputer,
4-
IconLogs,
54
IconMobile,
65
IconRefresh,
6+
IconWrench,
77
IconX
88
} from '@renderer/assets/icons'
99
import { ProgressChannel } from '@shared/types'
@@ -186,7 +186,7 @@ const ConnectionComponent: React.FC<ConnectionComponentProps> = ({ client }) =>
186186
className="group hover:bg-zinc-900 gap-2"
187187
onClick={() => setEnabled(true)}
188188
>
189-
<IconLogs />
189+
<IconWrench />
190190
</Button>
191191

192192
<Button

0 commit comments

Comments
 (0)