Skip to content

Commit 0f818ea

Browse files
committed
Updated adding apps UI
1 parent 20df81f commit 0f818ea

File tree

26 files changed

+648
-183
lines changed

26 files changed

+648
-183
lines changed

DeskThingServer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "deskthing",
3-
"version": "0.11.13",
3+
"version": "0.11.14",
44
"description": "A DeskThing server UI to interface with the DeskThing car thing app",
55
"main": "./out/main/index.js",
66
"author": "Riprod",

DeskThingServer/src/main/services/ipc/releasesIpc.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ export const releaseHandler = async (
7272
return []
7373
}
7474
break
75+
case IPC_RELEASE_TYPES.GET_REPO_ASSETS:
76+
try {
77+
const result = await releaseStore.getAllRepositories()
78+
logger.debug(`Got ${result.length} repositories!`)
79+
return result
80+
} catch (error) {
81+
logger.error(`Unable to get repositories ${handleError(error)}`)
82+
return []
83+
}
84+
break
7585
case IPC_RELEASE_TYPES.GET_APPS:
7686
try {
7787
return await releaseStore.getAppReleases()

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ export async function handleReleaseJSONFileMigration0108(
250250
* @param newRelease - the new release to be migrated
251251
* @param pastRelease - the past release to use to fill in missing information
252252
* @param appId - the ID of the app to use to fill in missing information
253-
*
254253
*/
255254
export const handleReleaseJSONMigration = async <
256255
T extends ClientLatestJSONLatest | AppLatestJSONLatest | MultiReleaseJSONLatest

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export const createAppReleaseFile = async (force = false): Promise<AppReleaseFil
196196
const adaptedRelease = await handleReleaseJSONMigration(latestJSON)
197197

198198
if (adaptedRelease.meta_type == 'client')
199-
throw new Error(`Received meta type 'app' when expecting Multi or Client`)
199+
throw new Error(`Received meta type 'client' when expecting Multi or App`)
200200

201201
if (adaptedRelease.meta_type == 'multi') {
202202
update('Converting multi-release to release server format', 60)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { storeProvider } from '@server/stores/storeProvider'
2+
import { GithubRepository } from '@shared/types'
3+
4+
export const fetchRepoSummary = async (repoUrl: string): Promise<GithubRepository> => {
5+
const githubStore = await storeProvider.getStore('githubStore')
6+
7+
const summary = await githubStore.getRepository(repoUrl)
8+
9+
if (summary) return summary
10+
11+
throw new Error('Repository not found')
12+
}

DeskThingServer/src/main/stores/githubStore.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import logger from '@server/utils/logger'
2-
import { CacheableStore, GithubAsset, CacheEntry, GithubRelease } from '@shared/types'
2+
import {
3+
CacheableStore,
4+
GithubAsset,
5+
CacheEntry,
6+
GithubRelease,
7+
GithubRepository
8+
} from '@shared/types'
39
import { isCacheValid } from '@server/services/releases/releaseValidation'
410
import { GithubStoreClass } from '@shared/stores/githubStore'
511
import { handleError } from '@server/utils/errorHandler'
@@ -211,7 +217,7 @@ export class GithubStore implements CacheableStore, GithubStoreClass {
211217
;[, owner, repo] = match
212218
}
213219

214-
return `https://api.github.com/repos/${owner}/${repo}/releases`
220+
return `https://api.github.com/repos/${owner}/${repo}`
215221
} catch (error) {
216222
logger.error(`Failed to convert repository URL to API endpoint: ${repoUrl}`, {
217223
function: 'convertToApiUrl',
@@ -229,7 +235,7 @@ export class GithubStore implements CacheableStore, GithubStoreClass {
229235
*/
230236
public getAllReleases = async (repoUrl: string, force?: boolean): Promise<GithubRelease[]> => {
231237
try {
232-
const apiUrl = this.convertToApiUrl(repoUrl)
238+
const apiUrl = this.convertToApiUrl(repoUrl) + '/releases'
233239
logger.debug(`Converted url ${repoUrl} to ${apiUrl}`)
234240

235241
// Checking the cache first
@@ -294,6 +300,31 @@ export class GithubStore implements CacheableStore, GithubStoreClass {
294300
}
295301
}
296302

303+
public getRepository = async (repoUrl: string): Promise<GithubRepository | undefined> => {
304+
try {
305+
const apiUrl = this.convertToApiUrl(repoUrl)
306+
307+
const response = await this.queueRequest(apiUrl)
308+
309+
if (!response.ok) {
310+
logger.error(`Failed to fetch repository ${repoUrl}: ${response.statusText}`, {
311+
function: 'getRepository',
312+
source: 'githubStore'
313+
})
314+
return undefined
315+
}
316+
317+
const data = (await response.json()) as GithubRepository
318+
return data
319+
} catch (error) {
320+
logger.error(`Error fetching repository ${repoUrl}. ${handleError(error)}!`, {
321+
function: 'getRepository',
322+
source: 'githubStore'
323+
})
324+
throw error
325+
}
326+
}
327+
297328
public checkUrlValidity = async (url: string): Promise<boolean> => {
298329
try {
299330
// Check if we already validated this URL recently

DeskThingServer/src/main/stores/releaseStore.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
CacheableStore,
1212
ClientLatestServer,
1313
ClientReleaseFile01111,
14+
GithubRepository,
1415
ProgressChannel,
1516
StagedAppManifest
1617
} from '@shared/types'
@@ -39,6 +40,7 @@ import {
3940
} from '@server/services/releases/releaseUtils'
4041
import { storeProvider } from './storeProvider'
4142
import { ClientManifest, GitRepoUrl, LOGGING_LEVELS } from '@deskthing/types'
43+
import { fetchRepoSummary } from '@server/services/releases/repoSummary'
4244

4345
/**
4446
* Temporarily holds the entire repo response information in memory unless manually refreshed
@@ -343,6 +345,31 @@ export class ReleaseStore
343345
return clients.repositories
344346
}
345347

348+
public getAllRepositories = async (): Promise<GithubRepository[]> => {
349+
const totalRepos = await this.getAvailableRepositories()
350+
const githubRepos: GithubRepository[] = []
351+
352+
for (const repo of totalRepos) {
353+
try {
354+
const summary = await fetchRepoSummary(repo)
355+
githubRepos.push(summary)
356+
} catch (err) {
357+
logger.warn(`Failed to fetch summary for repo ${repo}: ${handleError(err)}`, {
358+
error: err as Error,
359+
function: 'getAllRepositories',
360+
source: 'releaseStore'
361+
})
362+
}
363+
}
364+
365+
logger.info(`Fetched ${githubRepos.length} out of ${totalRepos.length} repositories`, {
366+
function: 'getAllRepositories',
367+
source: 'releaseStore'
368+
})
369+
370+
return githubRepos
371+
}
372+
346373
public getAppReleases = async (): Promise<AppLatestServer[] | undefined> => {
347374
const apps = await this.getAppReleaseFile()
348375
if (!apps) return undefined

DeskThingServer/src/main/windows/mainWindow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function createMainWindow(): BrowserWindow {
3535
responseHeaders: {
3636
...details.responseHeaders,
3737
'Content-Security-Policy': [
38-
"default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: deskthing: http://localhost:* https://thingify.tools https://*.thingify.tools; connect-src 'self' https://api.github.com https://thingify.tools;"
38+
"default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: deskthing: http://localhost:* https://thingify.tools https://*.thingify.tools https://avatars.githubusercontent.com; connect-src 'self' https://api.github.com https://thingify.tools;"
3939
]
4040
}
4141
})

DeskThingServer/src/preload/api/ipcReleases.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
import {
99
AppLatestServer,
1010
ClientDownloadReturnData,
11-
ClientLatestServer
11+
ClientLatestServer,
12+
GithubRepository
1213
} from '@shared/types/releases'
1314
import { ipcRenderer } from 'electron'
1415

@@ -27,6 +28,10 @@ export const releases = {
2728
type: IPC_RELEASE_TYPES.ADD_REPOSITORY,
2829
payload: repoUrl
2930
}),
31+
getAllRepositories: async (): Promise<GithubRepository[]> => await sendCommand({
32+
kind: IPC_HANDLERS.RELEASE,
33+
type: IPC_RELEASE_TYPES.GET_REPO_ASSETS
34+
}),
3035
getApps: async (): Promise<AppLatestServer[]> =>
3136
await sendCommand({
3237
kind: IPC_HANDLERS.RELEASE,

DeskThingServer/src/renderer/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
77
<meta
88
http-equiv="Content-Security-Policy"
9-
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' http://localhost:* https://thingify.tools data: deskthing:;"
9+
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' https://avatars.githubusercontent.com http://localhost:* https://thingify.tools data: deskthing:;"
1010
/>
1111
</head>
1212
<body style="overflow: hidden; background-color: black">

0 commit comments

Comments
 (0)