Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
youliso committed May 26, 2024
1 parent fe75457 commit 2f9e154
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 100 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@youliso/electronic",
"version": "2.3.1",
"version": "2.4.1",
"description": "electron modules",
"scripts": {
"build": "rollup -c rollup.config.mjs && node build.mjs",
Expand Down
16 changes: 8 additions & 8 deletions src/ipc/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,57 @@ import { AppChannel, LogChannel, MachineChannel } from '../preload/channel';
* @param args
*/
export function logInfo(...args: any): void {
window.ipc.send(LogChannel.info, args);
window.electronic.send(LogChannel.info, args);
}

/**
* 日志(error)
* @param args
*/
export function logError(...args: any): void {
window.ipc.send(LogChannel.error, args);
window.electronic.send(LogChannel.error, args);
}

/**
* app退出
*/
export function quit() {
window.ipc.send(AppChannel.quit);
window.electronic.send(AppChannel.quit);
}

/**
* app重启
* @param once 是否立即重启
*/
export function relaunch(once: boolean): void {
return window.ipc.send(AppChannel.relaunch, once);
return window.electronic.send(AppChannel.relaunch, once);
}

/**
* app常用信息
* @returns
*/
export async function getAppInfo(): Promise<AppInfo> {
return await window.ipc.invoke(AppChannel.getInfo);
return await window.electronic.invoke(AppChannel.getInfo);
}

/**
* app常用获取路径
*/
export async function getAppPath(key: AppPathKey): Promise<string> {
return await window.ipc.invoke(AppChannel.getPath, key);
return await window.electronic.invoke(AppChannel.getPath, key);
}

/**
* app打开url
*/
export async function openUrl(url: string): Promise<void> {
return await window.ipc.invoke(AppChannel.openUrl, url);
return await window.electronic.invoke(AppChannel.openUrl, url);
}

/**
* 获取设备唯一吗
*/
export async function getMachineGuid(): Promise<string> {
return await window.ipc.invoke(MachineChannel.get);
return await window.electronic.invoke(MachineChannel.get);
}
4 changes: 2 additions & 2 deletions src/ipc/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { ClipboardChannel } from '../preload/channel';
* @param type
*/
export async function clipboardReadText(type?: 'selection' | 'clipboard'): Promise<string> {
return await window.ipc.invoke(ClipboardChannel.readText, { type });
return await window.electronic.invoke(ClipboardChannel.readText, { type });
}

/**
* 将 text 作为纯文本写入剪贴板。
* @param text
*/
export async function clipboardWriteText(text: string): Promise<void> {
return await window.ipc.invoke(ClipboardChannel.writeText, { text });
return await window.electronic.invoke(ClipboardChannel.writeText, { text });
}
20 changes: 10 additions & 10 deletions src/ipc/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,44 @@ import { FileChannel } from '../preload/channel';
* @param fileName
*/
export async function fileBySuffix(path: string, fileName: string) {
return await window.ipc.invoke(FileChannel.suffix, { path, fileName });
return await window.electronic.invoke(FileChannel.suffix, { path, fileName });
}

/**
* 创建目录和内部文件
* */
export async function mkdir(path: string, options?: MakeDirectoryOptions) {
return await window.ipc.invoke(FileChannel.mkdir, { path, options });
return await window.electronic.invoke(FileChannel.mkdir, { path, options });
}

/**
* 删除目录和内部文件
* */
export async function delDir(path: string) {
return await window.ipc.invoke(FileChannel.deldir, { path });
return await window.electronic.invoke(FileChannel.deldir, { path });
}

/**
* 删除文件
* */
export async function unlink(path: string) {
return await window.ipc.invoke(FileChannel.unlink, { path });
return await window.electronic.invoke(FileChannel.unlink, { path });
}

/**
* 检查文件是否存在于当前目录中、以及是否可写
* @return 0 不存在 1 只可读 2 存在可读写
*/
export async function access(path: string) {
return await window.ipc.invoke(FileChannel.access, { path });
return await window.electronic.invoke(FileChannel.access, { path });
}

/**
* 文件重命名
* @return 0 失败 1 成功
*/
export async function rename(path: string, newPath: string) {
return await window.ipc.invoke(FileChannel.rename, { path, newPath });
return await window.electronic.invoke(FileChannel.rename, { path, newPath });
}

/**
Expand All @@ -56,7 +56,7 @@ export async function readFile(
path: string,
options?: { encoding?: BufferEncoding; flag?: string }
) {
return await window.ipc.invoke(FileChannel.readFile, { path, options });
return await window.electronic.invoke(FileChannel.readFile, { path, options });
}

/**
Expand All @@ -65,7 +65,7 @@ export async function readFile(
* @param index
*/
export async function readLine(path: string, index?: number): Promise<string | any[]> {
return await window.ipc.invoke(FileChannel.readLine, { path, index });
return await window.electronic.invoke(FileChannel.readLine, { path, index });
}

/**
Expand All @@ -77,7 +77,7 @@ export async function writeFile(
data: string | Buffer,
options?: { encoding?: BufferEncoding; mode?: number | string; flag?: string }
) {
return await window.ipc.invoke(FileChannel.writeFile, { path, data, options });
return await window.electronic.invoke(FileChannel.writeFile, { path, data, options });
}

/**
Expand All @@ -89,5 +89,5 @@ export async function appendFile(
data: string | Uint8Array,
options?: { encoding?: BufferEncoding; mode?: number | string; flag?: string }
) {
return await window.ipc.invoke(FileChannel.appendFile, { path, data, options });
return await window.electronic.invoke(FileChannel.appendFile, { path, data, options });
}
21 changes: 21 additions & 0 deletions src/ipc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,24 @@ export * from './session';
export * from './shortcut';
export * from './store';
export * from './window';

/**
* 主进程消息监听
*/
export function ipcRendererOn(channel: string, listener: (...args: any[]) => void) {
window.electronic.on(channel, listener);
}

/**
* 主进程消息监听(触发后销毁)
*/
export function ipcRendererOnce(channel: string, listener: (...args: any[]) => void) {
window.electronic.once(channel, listener);
}

/**
* 监听销毁
*/
export function ipcRemoveAllListeners(channel: string) {
window.electronic.removeAllListeners(channel);
}
10 changes: 5 additions & 5 deletions src/ipc/path.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { PathChannel } from '../preload/channel';

export async function sep(): Promise<string> {
return await window.ipc.invoke(PathChannel.sep);
return await window.electronic.invoke(PathChannel.sep);
}

export async function isAbsolute(path: string): Promise<string> {
return await window.ipc.invoke(PathChannel.isAbsolute, path);
return await window.electronic.invoke(PathChannel.isAbsolute, path);
}

export async function dirname(path: string): Promise<string> {
return await window.ipc.invoke(PathChannel.dirname, path);
return await window.electronic.invoke(PathChannel.dirname, path);
}

export async function normalize(path: string): Promise<string> {
return await window.ipc.invoke(PathChannel.normalize, path);
return await window.electronic.invoke(PathChannel.normalize, path);
}

export async function basename(path: string): Promise<string> {
return await window.ipc.invoke(PathChannel.basename, path);
return await window.electronic.invoke(PathChannel.basename, path);
}
8 changes: 4 additions & 4 deletions src/ipc/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ export function sessionHeadersSet(
url: string,
value: { [key: string]: string }
) {
window.ipc.send(SessionChannel.setHeaders, { type, url, value });
window.electronic.send(SessionChannel.setHeaders, { type, url, value });
}

/**
* 获取 cookies
* @param args
*/
export function sessionCookiesGet(args: CookiesGetFilter) {
return window.ipc.invoke(SessionChannel.getCookies, args);
return window.electronic.invoke(SessionChannel.getCookies, args);
}

/**
* 设置 cookies
* @param args
*/
export async function sessionCookiesSet(args: CookiesSetDetails) {
return window.ipc.invoke(SessionChannel.setCookies, args);
return window.electronic.invoke(SessionChannel.setCookies, args);
}

/**
Expand All @@ -34,5 +34,5 @@ export async function sessionCookiesSet(args: CookiesSetDetails) {
* @param name
*/
export async function sessionCookiesRemove(url: string, name: string) {
return window.ipc.invoke(SessionChannel.unCookies, { url, name });
return window.electronic.invoke(SessionChannel.unCookies, { url, name });
}
8 changes: 4 additions & 4 deletions src/ipc/shortcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ShortcutChannel } from '../preload/channel';
* @param listener
*/
export function shortcutOn(listener: (args: any) => void) {
window.ipc.on(`shortcut-back`, listener);
window.electronic.on(`shortcut-back`, listener);
}

/**
Expand All @@ -15,23 +15,23 @@ export function shortcutOn(listener: (args: any) => void) {
* @param key
*/
export async function shortcut(name: string, key: string | string[]): Promise<void> {
return await window.ipc.invoke(ShortcutChannel.register, { name, key });
return await window.electronic.invoke(ShortcutChannel.register, { name, key });
}

/**
* 清除快捷键
* @param key
*/
export async function shortcutUn(key?: string): Promise<void> {
return await window.ipc.invoke(ShortcutChannel.unregister, key);
return await window.electronic.invoke(ShortcutChannel.unregister, key);
}

/**
* 获取已注册快捷键
* @param key
*/
export async function shortcutGet(key?: string): Promise<Accelerator> {
return await window.ipc.invoke(ShortcutChannel.get, key);
return await window.electronic.invoke(ShortcutChannel.get, key);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/ipc/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { StoreChannel } from '../preload/channel';
* @param value 值
*/
export function setStore(key: string, value: unknown): Promise<void> {
return window.ipc.invoke(StoreChannel.set, {
return window.electronic.invoke(StoreChannel.set, {
key,
value
});
Expand All @@ -17,5 +17,5 @@ export function setStore(key: string, value: unknown): Promise<void> {
* @param key 键
*/
export function getStore<T>(key: string): Promise<T> {
return window.ipc.invoke(StoreChannel.get, { key });
return window.electronic.invoke(StoreChannel.get, { key });
}
10 changes: 5 additions & 5 deletions src/ipc/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { UpdateChannel } from '../preload/channel';
* 更新监听
*/
export function updateOn(listener: (args: UpdateMessage) => void) {
window.ipc.on('update-back', listener);
window.electronic.on('update-back', listener);
}

/**
* 关闭监听
*/
export function updateListenersRemove() {
window.ipc.removeAllListeners('update-back');
window.electronic.removeAllListeners('update-back');
}

/**
Expand All @@ -21,20 +21,20 @@ export function updateListenersRemove() {
* @param url 更新地址(不传用默认地址)
*/
export function updateCheck(isDel: boolean = true, autoDownload: boolean = false, url?: string) {
window.ipc.send(UpdateChannel.check, { isDel, autoDownload, url });
window.electronic.send(UpdateChannel.check, { isDel, autoDownload, url });
}

/**
* 下载更新 (如果autoDownload选项设置为 false,则可以使用此方法
*/
export function updateDownload() {
window.ipc.send(UpdateChannel.download);
window.electronic.send(UpdateChannel.download);
}

/**
* 关闭程序进行更新
* @param isSilent 是否静默更新
*/
export function updateInstall(isSilent: boolean) {
window.ipc.send(UpdateChannel.install, isSilent);
window.electronic.send(UpdateChannel.install, isSilent);
}
Loading

0 comments on commit 2f9e154

Please sign in to comment.