node-ddk
Version:
252 lines (227 loc) • 7.94 kB
TypeScript
export namespace NODEDDK {
// @ Rectangle
export type Rectangle = {
x: number,
y: number,
width: number,
height: number,
}
//
export type OsType = "Linux" | "Windows" | "Darwin" | "Other"
// @通用
export type generalFunction = () => any
// @ 渲染进程启动参数
export type WindowType = {
type: string,
minWidth?: number,
minHeight?: number,
resizable?: boolean,
minimizable?: boolean,
minimize?: boolean,
maximizable?: boolean,
maximize?: boolean,
transparent?: boolean,
fullscreenable?: boolean,
fullscreen?: boolean,
alwaysOnTop?: boolean,
frame?: boolean,
menu?: boolean,
skipTaskbar?: boolean,
kiosk?: boolean,
focus?: boolean,
needCenter?: boolean,
x?: number,
y?: number,
width?: number,
height?: number,
hide?: boolean,
backgroundColor?: string,
navigate?: boolean,
zoomFactor?: number,
hasShadow?: boolean,
windowStateType?: string,
devTools?: boolean,
autoDevTools?: boolean,
}
// @
export type NewWindowInfo = {
uniqueId: string,
args: any,
} & WindowType
// @
export type WindowInfo = {
webContentsId: number,
appName: string,
appVersion: string,
devMode: boolean,
} & NewWindowInfo
// @ 菜单条目
export type MenuEvent = {
ctrlKey: boolean,
metaKey: boolean,
shiftKey: boolean,
altKey: boolean,
triggeredByAccelerator: boolean,
}
export type MenuItemClick = (ev: MenuEvent) => any
export type MenuItem = {
type?: "normal" | "separator" | "submenu" | "checkbox" | "radio",
label: string,
click?: MenuItemClick,
role?: string,
submenu?: MenuItem[],
enabled?: boolean,
separator?: boolean,
checked?: boolean,
}
// @ 打开本地文件/url
export type OpenLocalFileOptions = {
path: string,
}
export type OpenLocalFileChecker = (attrs: OpenLocalFileOptions) => Promise<boolean>
export type OpenUrlOptions = {
url: string,
}
export type OpenUrlChecker = (attrs: OpenUrlOptions) => Promise<boolean>
//
export type FileProtocolRealpathOptions = {
path: string,
}
export type FileProtocolRealpath = (options: FileProtocolRealpathOptions) => Promise<string>
export type FileProtocolOptions = {
protocol: string,
realpath: FileProtocolRealpath,
}
//
export type FileInfo = {
status: "OK" | "none" | "error",
type: "file" | "directory" | "other",
size: number,
ctime: number,
mtime: number,
}
//
export type FindInPageOptions = {
text: string,
findNext?: boolean,
forward?: boolean,
matchCase?: boolean,
}
export type FindInPageResult = {
matches: number,
sn: number,
}
// @
export type sessionPathOptions = {
path: string,
}
// @ appStart 回调函数
export type afterAppStartHanlder = () => Promise<any>
// @interface 具体的功能模块, 请求
export type ModuleMainRequest = {
fromWindowUniqueId?: string,
toWindowUniqueId?: string,
module: string,
data: any,
timeout: number, // 秒
notify: null | undefined | ((data: any) => any),
}
export type ModuleMainLocalRequest = {
toWindowUniqueId?: string,
module: string,
data: any,
timeout?: number, // 秒
notify?: (data: any) => any,
}
// @interface 具体的功能模块, 返回
export type ModuleMainResponse = {
fromWindowUniqueId?: string,
toWindowUniqueId?: string,
status?: string,
data: any,
}
// @interface 模块处理函数
export type ModuleMainResolve = (res: ModuleMainResponse) => void
export type ModuleMainHandler = (req: ModuleMainRequest) => Promise<ModuleMainResponse>
}
declare const _default: {
app: {
isPackaged: boolean;
getHomeDir: () => string;
getPublicDir: () => string;
osType: () => NODEDDK.OsType;
osIsDarwin: () => boolean;
osIsWindows: () => boolean;
osIsLinux: () => boolean;
setOpenFile: (cb: (fn: string) => void) => void;
start: () => Promise<void>;
quit: () => void;
setFavicon: (path: string) => void;
getPathInPublic: (p: string) => string;
getDevMode: () => boolean;
setSessionPath: (options: NODEDDK.sessionPathOptions) => void;
setDataPath: (options: NODEDDK.sessionPathOptions) => void;
getDataPath: () => string;
getAppPath: () => string;
getAppName: () => string;
setAppName: (name: string) => void;
getSystemAppDataPath: () => string;
encryptString: (s: string) => string;
decryptString: (s: string) => string;
};
session: {
getDefaultSession: () => Electron.Session;
getPartitionSession: (id: string) => Electron.Session;
getPersistPartitionSession: (id: string) => Electron.Session;
getFileSession: () => Electron.Session;
getHttpSession: () => Electron.Session;
};
ipc: {
registerListenModule: (name: string, handler: NODEDDK.ModuleMainHandler) => void;
request: (requestMsg: NODEDDK.ModuleMainLocalRequest) => Promise<NODEDDK.ModuleMainResponse>;
sendMessage: (module: string, data: any) => void;
sendMessageToWindow: (w: Electron.BrowserWindow | null | string, module: string, data: any) => void;
};
window: {
setWindowTypes: (menus?: NODEDDK.WindowType[]) => void;
createWindow: (nwi: NODEDDK.NewWindowInfo) => Electron.BrowserWindow;
getWindowInfoByWebContentsId: (webContentsId?: number) => NODEDDK.WindowInfo | null;
getWindowInfoByUniqueId: (uniqueId: string | undefined) => NODEDDK.WindowInfo | null;
getWindowByWebContentsId: (id: number | undefined) => Electron.BrowserWindow | null;
getWindowByUniqueId: (uniqueId: string | undefined) => Electron.BrowserWindow | null;
getUniqueIdByWebContentsId: (webContentsId?: number) => string;
getMainWindow: () => Electron.BrowserWindow | null;
getMainRawWindow: () => Electron.BrowserWindow | null;
getWindowFromModuleRequest: (req: NODEDDK.ModuleMainRequest) => Electron.BrowserWindow | undefined;
};
menu: {
setMenuByWindowType: (type: string, menus?: NODEDDK.MenuItem[]) => void;
removeMenuByWindowType: (type: string) => void;
setGlobalMenu: (menus?: NODEDDK.MenuItem[]) => void;
removeGlobalMenu: () => void;
};
tray: {
getTray: () => Electron.CrossProcessExports.Tray;
setDefaultImage: (path: string) => void;
setContextMenu: (menuList: NODEDDK.MenuItem[]) => void;
setToolTip: (tip: string) => void;
setOnClick: (fn: NODEDDK.generalFunction) => void;
setShowMainWindowOnClick: () => void;
setHideMainWindowOnClick: () => void;
setShowHideSwitchMainWindowOnClick: () => void;
activeTray: () => void;
};
systemNotification: {
setIcon: (path: string) => void;
};
shell: {
registerOpenLocalFileChecker: (checker: NODEDDK.OpenLocalFileChecker) => void;
registerOpenUrlChecker: (checker: NODEDDK.OpenUrlChecker) => void;
openLocalFile: (attrs: NODEDDK.OpenLocalFileOptions) => Promise<boolean>;
openUrl: (attrs: NODEDDK.OpenUrlOptions) => Promise<boolean>;
};
protocol: {
registerFileProtocol: (options: NODEDDK.FileProtocolOptions) => void;
};
};
export default _default;