electron#IpcMainEvent TypeScript Examples

The following examples show how to use electron#IpcMainEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainToEmulatorMessenger.ts    From kliveide with MIT License 6 votes vote down vote up
/**
   * Initializes the listener that processes responses
   */
  constructor(public readonly window: BrowserWindow) {
    super();
    ipcMain.on(
      this.responseChannel,
      (_ev: IpcMainEvent, response: ResponseMessage) =>
        this.processResponse(response)
    );
  }
Example #2
Source File: code-runner.ts    From electron-playground with MIT License 6 votes vote down vote up
// 在主进程执行electron的代码
export function addCodeRunnerListener() {
  ipcMain.on('ACTION_CODE', (event: IpcMainEvent, fnStr: string) => {
    try {
      const mockConsole = new MockConsole()
      const fn = new Function(
        'exports',
        'require',
        'module',
        '__filename',
        '__dirname',
        'console',
        `return function(){
              try{
                ${fnStr}
              }catch(error){
                console.error('程序执行错误',error)
              }
             }`,
      )(exports, nativeRequire, module, __filename, __dirname, mockConsole)
      const result = fn()
      if (result) {
        mockConsole.log(result)
      }
      event.returnValue = mockConsole.logs
    } catch (err) {
      console.log('执行动态代码错误', err)
    }
  })
}
Example #3
Source File: index.ts    From electron-playground with MIT License 6 votes vote down vote up
(async () => {
  await app.whenReady()
  ipcMain.on('OPEN_WINDOW', (event: IpcMainEvent, optionsProps: OpenWindowOptions) => {
    const { name } = optionsProps
    createWindow(name)

    event.returnValue = 1
  })

  ipcMain.on('CLOSE_WINDOW', (e, options) => {
    const win = BrowserWindow.fromWebContents(e.sender)
    win?.close()
  })

  ipcMain.on('MAXIMIZE_WINDOW', (e, options) => {
    const win = BrowserWindow.fromWebContents(e.sender)
    console.log(win?.isMaximized())
    win?.isMaximized() ? win?.unmaximize() : win?.maximize()
  })

  ipcMain.on('MINIMIZE_WINDOW', (e, options) => {
    const win = BrowserWindow.fromWebContents(e.sender)
    win?.isMinimized() ? win?.restore() : win?.minimize()
  })
})()
Example #4
Source File: index.tsx    From mysterium-vpn-desktop with MIT License 6 votes vote down vote up
ipcMain.on(MainIpcListenChannels.OpenSecureFormPaymentWindow, async (event: IpcMainEvent, secureForm: string) => {
    const securePaymentWindow = new BrowserWindow({
        frame: true,
        fullscreen: false,
        fullscreenable: false,
        resizable: true,
        width: 770,
        height: 820,
        x: (mainWindow?.getBounds().x ?? 0) + 40,
        y: mainWindow?.getBounds().y,
    })
    return await securePaymentWindow.loadURL("data:text/html;charset=UTF-8," + encodeURIComponent(secureForm))
})
Example #5
Source File: PlacementChannel.ts    From nodemaker with MIT License 6 votes vote down vote up
public async handle(
    event: IpcMainEvent,
    { filesToPlace }: PlacementChannelArgument
  ) {
    process.chdir("..");

    const filePlacer = new FilePlacer();

    const result =
      filesToPlace === "functionality"
        ? await filePlacer.placeNodeFunctionalityFiles()
        : await filePlacer.placeNodeDocumentationFiles();

    process.chdir("client");

    event.sender.send(this.name, result);
  }
Example #6
Source File: telemetry.ts    From desktop with MIT License 6 votes vote down vote up
export function initializeTelemetry(): void {
  setDefaultComponentId(`gatsby-desktop`)
  setGatsbyCliVersion(app.getVersion())
  startBackgroundUpdate()
  store = new Store<IConfigType>()

  const telemetryEnabled = store.get(`telemetryOptIn`)

  if (telemetryEnabled === false) {
    console.log(`running with telemetry disabled`)
    trackCli(`RUNNING_WITH_TELEMETRY_DISABLED`)
  } else {
    trackCli(`GATSBY_DESKTOP_STARTED`)
    console.log(`telemetry enabled or not chosen`, { telemetryEnabled })
  }
  ipcMain.on(
    `telemetry-trackFeatureIsUsed`,
    (event: IpcMainEvent, name: string): void =>
      telemetryTrackFeatureIsUsed(name)
  )
  ipcMain.on(
    `telemetry-trackEvent`,
    (
      event: IpcMainEvent,
      input: string | Array<string>,
      tags?: ITelemetryTagsPayload
    ): void => trackEvent(input, tags)
  )
}
Example #7
Source File: window.ts    From noteworthy with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
	 * Wraps window.webContents.send() in a Promise. Expects the render
	 * process to send back a response after handling the message.
	 * 
	 * This is needed because unlike `ipcRenderer`, electron `WebContents`
	 * has no invoke() method for when we expect a message result.  See:
	 *
	 *
	 */
	async invoke<T>(channel:string, ...args:any[]):Promise<T> {
		return new Promise<T>((resolve, reject) => {
			// generate unique id for event
			let responseId = `RENDER_DID_HANDLE::${channel}::${randomId()}`;
			// send message from main --> render
			this.window.webContents.send(channel, responseId, ...args);
			// expect response -- promise won't resolve otherwise
			/** @todo (7/12/20) accept timeout (seconds) as argument? */
			ipcMain.once(responseId, (evt:IpcMainEvent, success:boolean, result:any) => {
				if(success) { resolve(result); }
				else        { reject(result);  }
			});
		});
	}
Example #8
Source File: main-store.ts    From kliveide with MIT License 6 votes vote down vote up
/**
   * Initializes the listener that processes responses
   */
  constructor(public readonly window: BrowserWindow) {
    super();
    ipcMain.on(
      this.responseChannel,
      (_ev: IpcMainEvent, response: ResponseMessage) =>
        this.processResponse(response)
    );
  }
Example #9
Source File: MainToIdeMessenger.ts    From kliveide with MIT License 6 votes vote down vote up
/**
   * Initializes the listener that processes responses
   */
  constructor(public readonly window: BrowserWindow) {
    super();
    ipcMain.on(
      this.responseChannel,
      (_ev: IpcMainEvent, response: ResponseMessage) =>
        this.processResponse(response)
    );
  }
Example #10
Source File: MainToEmuForwarder.ts    From kliveide with MIT License 6 votes vote down vote up
/**
   * Initializes the listener that processes responses
   */
  constructor(public readonly window: BrowserWindow) {
    super();
    ipcMain.on(
      this.responseChannel,
      (_ev: IpcMainEvent, response: ResponseMessage) =>
        this.processResponse(response)
    );
  }
Example #11
Source File: DocsgenChannel.ts    From nodemaker with MIT License 5 votes vote down vote up
public async handle(event: IpcMainEvent, paramsBundle: DocsgenParamsBundle) {
    process.chdir("..");
    const generator = new NodeDocsGenerator(paramsBundle);
    const result = await generator.run();
    process.chdir("client");

    event.sender.send(this.name, result);
  }
Example #12
Source File: EmptyChannel.ts    From nodemaker with MIT License 5 votes vote down vote up
public async handle(event: IpcMainEvent) {
    process.chdir("..");
    const emptier = new DirectoryEmptier();
    const result = await emptier.run();
    process.chdir("client");

    event.sender.send(this.name, result);
  }
Example #13
Source File: ExampleChannel.ts    From nodemaker with MIT License 5 votes vote down vote up
public async handle(event: IpcMainEvent) {
    event.sender.send(this.name, "hello my name is erin");
  }
Example #14
Source File: NodegenChannel.ts    From nodemaker with MIT License 5 votes vote down vote up
public async handle(event: IpcMainEvent, paramsBundle: NodegenParamsBundle) {
    process.chdir("..");
    const generator = new NodeFilesGenerator(paramsBundle);
    const result = await generator.run();
    process.chdir("client");

    event.sender.send(this.name, result);
  }
Example #15
Source File: PackgenChannel.ts    From nodemaker with MIT License 5 votes vote down vote up
public async handle(event: IpcMainEvent, metaParameters: MetaParameters) {
    process.chdir("..");
    const generator = new PackageJsonGenerator(metaParameters);
    const result = await generator.run();
    process.chdir("client");

    event.sender.send(this.name, result);
  }
Example #16
Source File: overlay-window.ts    From awakened-poe-trade with MIT License 5 votes vote down vote up
export function overlayOnEvent<Name extends ipc.IpcEvent['name']> (
  name: Name,
  cb: (e: IpcMainEvent, payload: ipc.IpcEventPayload<Name>) => void
) {
  ipcMain.on(name, cb)
}
Example #17
Source File: index.tsx    From mysterium-vpn-desktop with MIT License 5 votes vote down vote up
ipcMain.on(MainIpcListenChannels.OpenSupportChat, async (event: IpcMainEvent, id: string) => {
    if (chatWindow == null) {
        chatWindow = await createChatWindow(id)
    }
    chatWindow.show()
})