-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
358681c
commit 2cf3af9
Showing
65 changed files
with
1,033 additions
and
239 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...process-communication/renderer-to-main.ts β ...ation/to-main-process/renderer-to-main.ts
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
45 changes: 45 additions & 0 deletions
45
src/inter-process-communication/to-renderer-process/main-to-renderer.ts
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,45 @@ | ||
/** | ||
* This module provides a nice interface to send messages from main process to renderer process. | ||
*/ | ||
|
||
import log from '../../log'; | ||
import { getMainWindow } from '../../main-process/main-window'; | ||
import { getViewByName } from '../../main-process/views'; | ||
import { | ||
AgentRendererMessage, | ||
MainWindowRendererMessage, | ||
ProxyRendererMessage, | ||
RendererMessage, | ||
SettingsRendererMessage, | ||
} from '../../types/messaging'; | ||
import { ViewName } from '../../types/views'; | ||
|
||
export const sendFromMainWindowToRenderer = ({ type, data }: MainWindowRendererMessage): void => { | ||
_sendToRenderer({ data, type }); | ||
}; | ||
|
||
export const sendFromAgentViewToRenderer = ({ type, data }: AgentRendererMessage): void => { | ||
_sendToRenderer({ data, type }, ViewName.AGENT); | ||
}; | ||
|
||
export const sendFromProxyViewToRenderer = ({ type, data }: ProxyRendererMessage): void => { | ||
_sendToRenderer({ data, type }, ViewName.PROXY); | ||
}; | ||
|
||
export const sendFromSettingsViewToRenderer = ({ type, data }: SettingsRendererMessage): void => { | ||
_sendToRenderer({ data, type }, ViewName.SETTINGS); | ||
}; | ||
|
||
const _sendToRenderer = ({ type, data }: RendererMessage, viewName?: ViewName): void => { | ||
try { | ||
const viewOrWindow = viewName ? getViewByName(viewName) : getMainWindow(); | ||
const webContents = viewOrWindow?.webContents; | ||
if (!webContents) { | ||
throw new Error('No webContents found'); | ||
} | ||
log.debug('Sending to renderer', { data, type, viewName }); | ||
webContents.send(type, data); | ||
} catch (e) { | ||
log.error('Error in send to renderer', { data, type, viewName }, e); | ||
} | ||
}; |
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,59 @@ | ||
import https from 'https'; | ||
|
||
import { HttpsProxyAgent } from 'hpagent'; | ||
|
||
import log from '../../log'; | ||
|
||
export enum HttpsProxyAgentType { | ||
DEFAULT = 'default', | ||
PROXY = 'proxy', | ||
} | ||
|
||
let agent: https.Agent | HttpsProxyAgent | null | undefined; | ||
|
||
export const getHttpsAgent = (): https.Agent | HttpsProxyAgent | undefined => { | ||
if (!agent) { | ||
useDefaultHttpsAgent(); | ||
} | ||
return agent; | ||
}; | ||
|
||
const httpsAgentOptions = { | ||
keepAlive: true, | ||
keepAliveMsecs: 1000, | ||
maxFreeSockets: 256, | ||
maxSockets: 256, | ||
rejectUnauthorized: false, | ||
}; | ||
|
||
export const useProxyHttpsAgent = (proxyUrl: string): void => { | ||
_destroyAgent(); | ||
log.info('Using proxy HTTPS agent', { proxyUrl }); | ||
agent = _createProxyHttpsAgent(proxyUrl); | ||
}; | ||
|
||
const _createProxyHttpsAgent = (proxyUrl: string): HttpsProxyAgent => { | ||
return new HttpsProxyAgent({ | ||
...httpsAgentOptions, | ||
proxy: proxyUrl, | ||
scheduling: 'lifo', | ||
}); | ||
}; | ||
|
||
export const useDefaultHttpsAgent = (): void => { | ||
_destroyAgent(); | ||
log.info('Using default HTTPS agent'); | ||
agent = _createDefaultHttpsAgent(); | ||
}; | ||
|
||
const _createDefaultHttpsAgent = (): https.Agent => { | ||
return new https.Agent(httpsAgentOptions); | ||
}; | ||
|
||
const _destroyAgent = (): void => { | ||
if (agent) { | ||
log.info('Destroying HTTPS agent'); | ||
agent.destroy(); | ||
agent = null; | ||
} | ||
}; |
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
Oops, something went wrong.