File tree Expand file tree Collapse file tree 6 files changed +47
-8
lines changed
screens/Settings/CoreExtensions/ExtensionsCatalog Expand file tree Collapse file tree 6 files changed +47
-8
lines changed Original file line number Diff line number Diff line change @@ -58,3 +58,36 @@ export enum FileSystemRoute {
5858 getResourcePath = 'getResourcePath' ,
5959 exists = 'exists' ,
6060}
61+
62+ export type ApiFunction = ( ...args : any [ ] ) => any
63+
64+ export type AppRouteFunctions = {
65+ [ K in AppRoute ] : ApiFunction
66+ }
67+
68+ export type AppEventFunctions = {
69+ [ K in AppEvent ] : ApiFunction
70+ }
71+
72+ export type DownloadRouteFunctions = {
73+ [ K in DownloadRoute ] : ApiFunction
74+ }
75+
76+ export type DownloadEventFunctions = {
77+ [ K in DownloadEvent ] : ApiFunction
78+ }
79+
80+ export type ExtensionRouteFunctions = {
81+ [ K in ExtensionRoute ] : ApiFunction
82+ }
83+
84+ export type FileSystemRouteFunctions = {
85+ [ K in FileSystemRoute ] : ApiFunction
86+ }
87+
88+ export type APIRoutes = AppRouteFunctions &
89+ AppEventFunctions &
90+ DownloadRouteFunctions &
91+ DownloadEventFunctions &
92+ ExtensionRouteFunctions &
93+ FileSystemRouteFunctions
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ const Providers = (props: PropsWithChildren) => {
5353 useEffect ( ( ) => {
5454 if ( setupCore ) {
5555 // Electron
56- if ( window && window . core . api ) {
56+ if ( window && window . core ? .api ) {
5757 setupExtensions ( )
5858 } else {
5959 // Host
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ export class ExtensionManager {
5858 * @returns An array of extensions.
5959 */
6060 async getActive ( ) : Promise < Extension [ ] > {
61- const res = await window . core . api ?. getActiveExtensions ( )
61+ const res = await window . core ? .api ?. getActiveExtensions ( )
6262 if ( ! res || ! Array . isArray ( res ) ) return [ ]
6363
6464 const extensions : Extension [ ] = res . map (
@@ -119,7 +119,7 @@ export class ExtensionManager {
119119 if ( typeof window === 'undefined' ) {
120120 return
121121 }
122- const res = await window . core . api ?. installExtension ( extensions )
122+ const res = await window . core ? .api ?. installExtension ( extensions )
123123 if ( res . cancelled ) return false
124124 return res . map ( async ( ext : any ) => {
125125 const extension = new Extension ( ext . name , ext . url , ext . active )
@@ -138,7 +138,7 @@ export class ExtensionManager {
138138 if ( typeof window === 'undefined' ) {
139139 return
140140 }
141- return window . core . api ?. uninstallExtension ( extensions , reload )
141+ return window . core ? .api ?. uninstallExtension ( extensions , reload )
142142 }
143143}
144144
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ export function useGetAppVersion() {
88 } , [ ] )
99
1010 const getAppVersion = ( ) => {
11- window . core . api ?. appVersion ( ) . then ( ( version : string | undefined ) => {
11+ window . core ? .api ?. appVersion ( ) . then ( ( version : string | undefined ) => {
1212 setVersion ( version ?? '' )
1313 } )
1414 }
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ const ExtensionCatalog = () => {
6767 // Send the filename of the to be installed extension
6868 // to the main process for installation
6969 const installed = await extensionManager . install ( [ extensionFile ] )
70- if ( installed ) window . core . api ?. relaunch ( )
70+ if ( installed ) window . core ? .api ?. relaunch ( )
7171 }
7272
7373 /**
@@ -80,7 +80,7 @@ const ExtensionCatalog = () => {
8080 // Send the filename of the to be uninstalled extension
8181 // to the main process for removal
8282 const res = await extensionManager . uninstall ( [ name ] )
83- if ( res ) window . core . api ?. relaunch ( )
83+ if ( res ) window . core ? .api ?. relaunch ( )
8484 }
8585
8686 /**
Original file line number Diff line number Diff line change 1+ import { APIRoutes } from '@janhq/core'
2+
13/* eslint-disable @typescript-eslint/no-explicit-any */
24export { }
35
46declare global {
57 declare const PLUGIN_CATALOG : string
68 declare const VERSION : string
9+ interface Core {
10+ api : APIRoutes
11+ events : EventEmitter
12+ }
713 interface Window {
8- core ?: any | undefined
14+ core ?: Core | undefined
915 electronAPI ?: any | undefined
1016 }
1117}
You can’t perform that action at this time.
0 commit comments