Modified SupportedSites.tsx: - Added ImageWithPlaceholder import and IPC service import to fetch site icons. - Implemented SiteIcon component that loads site icon via ipcServices.app.getSiteIcon and handles errors/cancellation. - Updated layout: adjusted grid to include lg:grid-cols-3 and restructured list items into anchor cards with icon, label, external link icon, and description with truncation. These changes are focused on UI improvements for the SupportedSites page and fetching site icons from the main process.
58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import os from 'node:os'
|
|
import { app, BrowserWindow, dialog } from 'electron'
|
|
import { type IpcContext, IpcMethod, IpcService } from 'electron-ipc-decorator'
|
|
|
|
class AppService extends IpcService {
|
|
static readonly groupName = 'app'
|
|
|
|
@IpcMethod()
|
|
getVersion(_context: IpcContext): string {
|
|
return app.getVersion()
|
|
}
|
|
|
|
@IpcMethod()
|
|
getPlatform(_context: IpcContext): string {
|
|
return os.platform()
|
|
}
|
|
|
|
@IpcMethod()
|
|
quit(_context: IpcContext): void {
|
|
app.quit()
|
|
}
|
|
|
|
@IpcMethod()
|
|
async showMessageBox(
|
|
_context: IpcContext,
|
|
options: Electron.MessageBoxOptions
|
|
): Promise<Electron.MessageBoxReturnValue> {
|
|
const window = BrowserWindow.getFocusedWindow()
|
|
if (window) {
|
|
return dialog.showMessageBox(window, options)
|
|
}
|
|
|
|
return dialog.showMessageBox(options)
|
|
}
|
|
|
|
@IpcMethod()
|
|
async getSiteIcon(_context: IpcContext, domain: string): Promise<string | null> {
|
|
try {
|
|
const iconUrl = `https://unavatar.io/${domain}`
|
|
const response = await fetch(iconUrl)
|
|
if (!response.ok) {
|
|
return null
|
|
}
|
|
|
|
const arrayBuffer = await response.arrayBuffer()
|
|
const buffer = Buffer.from(arrayBuffer)
|
|
const contentType = response.headers.get('content-type') || 'image/png'
|
|
const base64 = buffer.toString('base64')
|
|
return `data:${contentType};base64,${base64}`
|
|
} catch (error) {
|
|
console.error('Failed to fetch site icon:', error)
|
|
return null
|
|
}
|
|
}
|
|
}
|
|
|
|
export { AppService }
|