-
Notifications
You must be signed in to change notification settings - Fork 76
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
git
committed
Sep 21, 2024
1 parent
cc8379a
commit b3f1383
Showing
42 changed files
with
9,041 additions
and
101 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
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 was deleted.
Oops, something went wrong.
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,63 @@ | ||
import {AppRuntime} from "../env"; | ||
import {ipcMain} from "electron"; | ||
import {StrUtil} from "../../lib/util"; | ||
|
||
const init = () => { | ||
|
||
} | ||
|
||
type NameType = 'main' | string | ||
type EventType = 'APP_READY' | 'CUSTOM' | ||
|
||
const send = (name: NameType, type: EventType, data: any = {}, id?: string): boolean => { | ||
id = id || StrUtil.randomString(32) | ||
const payload = {id, type, data} | ||
if (name === 'main') { | ||
if (!AppRuntime.mainWindow) { | ||
return false | ||
} | ||
AppRuntime.mainWindow?.webContents.send('MAIN_PROCESS_MESSAGE', payload) | ||
} else { | ||
if (!AppRuntime.windows[name]) { | ||
return false | ||
} | ||
AppRuntime.windows[name]?.webContents.send('MAIN_PROCESS_MESSAGE', payload) | ||
} | ||
return true | ||
} | ||
|
||
ipcMain.handle('event:send', async (_, name: NameType, type: EventType, data: any) => { | ||
send(name, type, data) | ||
}) | ||
|
||
ipcMain.handle('event:callCustom', async (_, name: string, type: string, data: any, option: any) => { | ||
option = Object.assign({timeout: 10}, option) | ||
return new Promise((resolve, reject) => { | ||
const id = StrUtil.randomString(32) | ||
const timer = setTimeout(() => { | ||
ipcMain.removeListener(listenerKey, listener) | ||
resolve({code: -1, msg: 'timeout'}) | ||
}, option.timeout * 1000) | ||
const listener = (_, result) => { | ||
clearTimeout(timer) | ||
resolve(result) | ||
return true | ||
} | ||
const listenerKey = 'event:callCustom:' + id | ||
ipcMain.once(listenerKey, listener) | ||
if (!send(name, 'CUSTOM', {type, data}, id)) { | ||
clearTimeout(timer) | ||
ipcMain.removeListener(listenerKey, listener) | ||
resolve({code: -1, msg: 'send failed'}) | ||
} | ||
}) | ||
}) | ||
|
||
export default { | ||
init, | ||
send | ||
} | ||
|
||
export const Events = { | ||
send | ||
} |
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,19 @@ | ||
import {ipcRenderer} from "electron"; | ||
|
||
const init = () => { | ||
|
||
} | ||
|
||
const send = (name: string, type: string, data: any = {}) => { | ||
ipcRenderer.invoke('event:send', name, type, data).then() | ||
} | ||
|
||
const callCustom = async (name: string, customType: string, data: any, option: any) => { | ||
return ipcRenderer.invoke('event:callCustom', name, customType, data, option) | ||
} | ||
|
||
export default { | ||
init | ||
init, | ||
send, | ||
callCustom | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {ipcMain} from "electron"; | ||
import {Page} from "../../page"; | ||
|
||
const open = async (name: string, option: any) => { | ||
return await Page.open(name, option) | ||
} | ||
|
||
ipcMain.handle('page:open', async (event, name: string, option: any) => { | ||
return open(name, option) | ||
}) | ||
|
||
export default { | ||
open | ||
} |
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,10 @@ | ||
import {ipcRenderer} from "electron"; | ||
|
||
|
||
const open = async (name: string, option: any) => { | ||
return ipcRenderer.invoke('page:open', name, option) | ||
} | ||
|
||
export default { | ||
open | ||
} |
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
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,41 @@ | ||
import {Events} from "../mapi/event/main"; | ||
import {AppEnv, AppRuntime} from "../mapi/env"; | ||
import {PageThirdPartyImageBeautifier} from "./thirdPartyImageBeautifier"; | ||
import {BrowserWindow, shell} from "electron"; | ||
import {rendererPath} from "../util/path-main"; | ||
|
||
const Pages = { | ||
'thirdPartyImageBeautifier': PageThirdPartyImageBeautifier, | ||
} | ||
|
||
export const Page = { | ||
ready(name: string) { | ||
Events.send(name, 'APP_READY', { | ||
name, | ||
AppEnv | ||
}) | ||
}, | ||
openWindow: (name: string, win: BrowserWindow, fileName: string) => { | ||
rendererPath(win, fileName); | ||
AppRuntime.windows[name] = win | ||
win.webContents.setWindowOpenHandler(({url}) => { | ||
if (url.startsWith('https:') || url.startsWith('http:')) { | ||
shell.openExternal(url).then() | ||
} | ||
return {action: 'deny'} | ||
}) | ||
win.on('close', () => { | ||
delete AppRuntime.windows[name] | ||
}) | ||
return new Promise((resolve, reject) => { | ||
win.webContents.on("did-finish-load", () => { | ||
Page.ready(name); | ||
resolve(undefined); | ||
}); | ||
}); | ||
}, | ||
open: async (name: string, option: any) => { | ||
return Pages[name].open(option) | ||
} | ||
} | ||
|
Oops, something went wrong.