This repository has been archived by the owner on Mar 26, 2023. It is now read-only.
generated from cawa-93/vite-electron-builder
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
81 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
export interface DialogsControllers { | ||
import type {HostBase, MethodOnlyHost} from './Host'; | ||
|
||
|
||
interface DialogsControllersBase extends HostBase { | ||
showError: (title: string, content: string) => void | ||
} | ||
|
||
|
||
export type DialogsControllers = MethodOnlyHost<DialogsControllersBase> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type {ClearIndex, Fn, NonFunctionKeys} from '../utils'; | ||
|
||
|
||
export type HostBase = Record<string, Fn> | ||
export type MethodOnlyHost<T extends HostBase> = Omit<ClearIndex<T>, NonFunctionKeys<ClearIndex<T>>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
export interface WindowControllers { | ||
import type {HostBase, MethodOnlyHost} from './Host'; | ||
|
||
|
||
interface WindowControllersBase extends HostBase { | ||
minimize: () => void | ||
maximize: () => void | ||
unmaximize: () => void | ||
close: () => void | ||
isMaximized: () => boolean | ||
} | ||
|
||
|
||
export type WindowControllers = MethodOnlyHost<WindowControllersBase> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import type {WindowControllers} from './WindowControllers'; | ||
import type {DialogsControllers} from './DialogsControllers'; | ||
import type {HostBase} from './Host'; | ||
import type {ClearIndex} from '../utils'; | ||
|
||
export interface IpcNameHostsMap { | ||
|
||
|
||
interface IpcNameHostsMapBase extends Record<string, HostBase> { | ||
'WindowControllers': WindowControllers | ||
'DialogsControllers': DialogsControllers | ||
} | ||
|
||
|
||
export type IpcNameHostsMap = ClearIndex<IpcNameHostsMapBase> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,55 @@ | ||
export type Promisified<T> = { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
readonly [P in keyof T]: T[P] extends (...a: any[]) => any ? (...a: Parameters<T[P]>) => Promise<ReturnType<T[P]>> : Promise<T[P]>; | ||
readonly [P in keyof T]: T[P] extends Fn ? (...a: Parameters<T[P]>) => Promise<ReturnType<T[P]>> : Promise<T[P]>; | ||
} | ||
|
||
/** | ||
* NonUndefined | ||
* @see https://github.com/piotrwitek/utility-types#nonundefineda | ||
* @desc Exclude undefined from set `A` | ||
* @example | ||
* // Expect: "string | null" | ||
* SymmetricDifference<string | null | undefined>; | ||
*/ | ||
export type NonUndefined<A> = A extends undefined ? never : A; | ||
|
||
|
||
/** | ||
* FunctionKeys | ||
* @see https://github.com/piotrwitek/utility-types#functionkeyst | ||
* @desc Get union type of keys that are functions in object type `T` | ||
* @example | ||
* type MixedProps = {name: string; setName: (name: string) => void; someKeys?: string; someFn?: (...args: any) => any;}; | ||
* | ||
* // Expect: "setName | someFn" | ||
* type Keys = FunctionKeys<MixedProps>; | ||
*/ | ||
export declare type FunctionKeys<T extends Record<string, unknown>> = { | ||
[K in keyof T]-?: NonUndefined<T[K]> extends Fn ? K : never; | ||
}[keyof T]; | ||
|
||
|
||
|
||
/** | ||
* NonFunctionKeys | ||
* @see https://github.com/piotrwitek/utility-types#nonfunctionkeyst | ||
* @desc Get union type of keys that are non-functions in object type `T` | ||
* @example | ||
* type MixedProps = {name: string; setName: (name: string) => void; someKeys?: string; someFn?: (...args: any) => any;}; | ||
* | ||
* // Expect: "name | someKey" | ||
* type Keys = NonFunctionKeys<MixedProps>; | ||
*/ | ||
export declare type NonFunctionKeys<T extends Record<string, unknown>> = { | ||
[K in keyof T]-?: NonUndefined<T[K]> extends Fn ? never : K; | ||
}[keyof T]; | ||
|
||
|
||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export type Fn = (...args: any[]) => any | ||
|
||
|
||
|
||
export type ClearIndex<T> = { | ||
[P in keyof T as string extends P ? never : number extends P ? never : P]: T[P] | ||
}; |