How to use the electron-better-ipc.ipcMain.answerRenderer function in electron-better-ipc

To help you get started, we’ve selected a few electron-better-ipc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github npezza93 / archipelago / app / main / pty-manager.js View on Github external
}
  }

  const create = () => {
    return new Promise(resolve => {
      const pty = new Pty(profileManager)
      pty.onExit(() => kill(pty.id))
      ipc.once(`pty-kill-${pty.id}`, () => kill(pty.id))

      resolve(pty)
    })
  }

  let preppedPty = create()

  const disposeOfCreate = ipc.answerRenderer('pty-create', async ({sessionId, sessionWindowId}) => {
    const pty = await preppedPty
    ptys[pty.id] = pty
    pty.created(sessionId, sessionWindowId)
    preppedPty = create()

    return pty.id
  })

  app.on('before-quit', () => {
    disposeOfCreate()
    Object.keys(ptys).forEach(kill)
  })
}
github wulkano / kap / main / export-list.js View on Github external
getExport(createdAt) {
    return this.exports.find(exp => exp.createdAt === createdAt);
  }

  openExport(createdAt) {
    track('export/history/opened/recording');
    const exp = this.getExport(createdAt);
    if (exp) {
      openEditorWindow(exp.previewPath, {recordedFps: exp.originalFps, originalFilePath: exp.inputPath});
    }
  }
}

let exportList;

ipc.answerRenderer('get-exports', () => exportList.getExports());

ipc.answerRenderer('export', options => exportList.addExport(options));

ipc.answerRenderer('cancel-export', createdAt => exportList.cancelExport(createdAt));

ipc.answerRenderer('open-export', createdAt => exportList.openExport(createdAt));

ipc.answerRenderer('export-snapshot', saveSnapshot);

ipc.on('drag-export', async (event, createdAt) => {
  const exportItem = exportList.getExport(createdAt);
  const file = exportItem && exportItem.data.filePath;

  if (file && fs.existsSync(file)) {
    event.sender.startDrag({
      file,
github npezza93 / archipelago / app / main / profile-manager.js View on Github external
bindListeners() {
    this.addIpcSubscription(
      ipc.answerRenderer('change-setting', ({property, value}) => {
        this.set(property, value)
        for (const window of BrowserWindow.getAllWindows()) {
          ipc.callRenderer(window, 'setting-changed', {property, value})
        }
      })
    )
    this.addIpcSubscription(
      ipc.answerRenderer('set-profile-name', ({id, name}) => {
        this.find(id).name = name
      })
    )
    this.addIpcSubscription(
      ipc.answerRenderer('set-active-profile', id => {
        this.activeProfileId = id
      })
    )
    this.addIpcSubscription(
      ipc.answerRenderer('create-profile', () => {
        const newProfileId = this.create()
        const profiles = this.rawProfiles

        return {profiles, activeProfileId: newProfileId}
      })
    )
github wulkano / kap / main / preferences.js View on Github external
return new Promise(resolve => {
    ipc.answerRenderer('preferences-ready', () => {
      prefsWindow.show();
      resolve(prefsWindow);
    });
  });
};

const closePrefsWindow = () => {
  if (prefsWindow) {
    prefsWindow.close();
  }
};

ipc.answerRenderer('open-preferences', openPrefsWindow);

module.exports = {
  openPrefsWindow,
  closePrefsWindow
};
github wulkano / kap / main / export-list.js View on Github external
openExport(createdAt) {
    track('export/history/opened/recording');
    const exp = this.getExport(createdAt);
    if (exp) {
      openEditorWindow(exp.previewPath, {recordedFps: exp.originalFps, originalFilePath: exp.inputPath});
    }
  }
}

let exportList;

ipc.answerRenderer('get-exports', () => exportList.getExports());

ipc.answerRenderer('export', options => exportList.addExport(options));

ipc.answerRenderer('cancel-export', createdAt => exportList.cancelExport(createdAt));

ipc.answerRenderer('open-export', createdAt => exportList.openExport(createdAt));

ipc.answerRenderer('export-snapshot', saveSnapshot);

ipc.on('drag-export', async (event, createdAt) => {
  const exportItem = exportList.getExport(createdAt);
  const file = exportItem && exportItem.data.filePath;

  if (file && fs.existsSync(file)) {
    event.sender.startDrag({
      file,
      icon: await getDragIcon(exportItem.imagePath)
    });
  }
});
github npezza93 / archipelago / app / main / index.js View on Github external
}
})

subscriptions.add(profileManager.onDidChange('vibrancy', value =>
  windows.forEach(win => {
    if (!win.isDestroyed()) {
      win.setVibrancy(value)
    }
  })
))

subscriptions.add(profileManager.onDidChange('singleTabMode', resetApplicationMenu))
subscriptions.add(profileManager.onDidChange('name', resetApplicationMenu))
subscriptions.add(profileManager.onActiveProfileChange(resetApplicationMenu))
subscriptions.add(new Disposable(
  ipc.answerRenderer('open-hamburger-menu', args => Menu.getApplicationMenu().popup(args))
))
subscriptions.add(new Disposable(
  ipc.answerRenderer('search-next', ({query, options}) => {
    ipc.callRenderer(currentTerminalWindow, 'search-next', {query, options})
  })
))
subscriptions.add(new Disposable(
  ipc.answerRenderer('search-previous', ({query, options}) => {
    ipc.callRenderer(currentTerminalWindow, 'search-previous', {query, options})
  })
))

const darkModeChange = () => {
  ipc.sendToRenderers('dark-mode-changed')
}
github garrylachman / ElectroCRUD / src / backend / ipc / views.ipc.ts View on Github external
public listen() {
        ipcMain.answerRenderer(IPC_CHANNEL_LIST_OF_TABLES, (req: JsonValue) => this.listOfTables(req));
        ipcMain.answerRenderer(IPC_CHANNEL_TABLE_INFO, (req: JsonValue) => this.tableInfo(req));
        ipcMain.answerRenderer(IPC_CHANNEL_READ_DATA, (req: JsonValue) => this.readData(req));
        ipcMain.answerRenderer(IPC_CHANNEL_UPDATE_DATA, (req: JsonValue) => this.updateData(req));
        ipcMain.answerRenderer(IPC_CHANNEL_INSERT_DATA, (req: JsonValue) => this.insertData(req));
        ipcMain.answerRenderer(IPC_CHANNEL_DELETE_DATA, (req: JsonValue) => this.deleteData(req));
        ipcMain.answerRenderer(IPC_CHANNEL_READ_WIDGET_DATA, (req: JsonValue) => this.readWidgetData(req));
    }
github wulkano / kap / main / export-options.js View on Github external
return options.sort(sortFunc);
};

const updateExportOptions = () => {
  const editors = getEditors();
  const exportOptions = getExportOptions();
  for (const editor of editors) {
    ipc.callRenderer(editor, 'export-options', exportOptions);
  }

  setOptions(exportOptions);
};

plugins.setUpdateExportOptions(updateExportOptions);

ipc.answerRenderer('update-usage', ({format, plugin}) => {
  const usage = exportUsageHistory.get(format);
  const now = Date.now();

  usage.plugins[plugin] = now;
  usage.lastUsed = now;
  exportUsageHistory.set(format, usage);
  updateExportOptions();
});

const initializeExportOptions = () => {
  setOptions(getExportOptions());
};

module.exports = {
  getExportOptions,
  updateExportOptions,
github npezza93 / archipelago / app / main / profile-manager.js View on Github external
bindListeners() {
    this.addIpcSubscription(
      ipc.answerRenderer('change-setting', ({property, value}) => {
        this.set(property, value)
        for (const window of BrowserWindow.getAllWindows()) {
          ipc.callRenderer(window, 'setting-changed', {property, value})
        }
      })
    )
    this.addIpcSubscription(
      ipc.answerRenderer('set-profile-name', ({id, name}) => {
        this.find(id).name = name
      })
    )
    this.addIpcSubscription(
      ipc.answerRenderer('set-active-profile', id => {
        this.activeProfileId = id
      })
    )
github wulkano / kap / main / editor.js View on Github external
});

  editorWindow.webContents.on('did-finish-load', async () => {
    ipc.callRenderer(editorWindow, 'export-options', exportOptions);
    await ipc.callRenderer(editorWindow, 'file', {filePath, fps, originalFilePath, isNewRecording});
    editorWindow.show();
  });
};

const setOptions = options => {
  exportOptions = options;
};

const getEditors = () => editors.values();

ipc.answerRenderer('save-original', async ({inputPath}) => {
  const now = moment();

  const {filePath} = await dialog.showSaveDialog(BrowserWindow.getFocusedWindow(), {
    defaultPath: `Kapture ${now.format('YYYY-MM-DD')} at ${now.format('H.mm.ss')}.mp4`
  });

  if (filePath) {
    await pify(fs.copyFile)(inputPath, filePath, fs.constants.COPYFILE_FICLONE);
  }
});

const checkForAnyBlockingEditors = () => {
  if (editorsWithNotSavedDialogs.size > 0) {
    const [path] = editorsWithNotSavedDialogs.keys();
    editors.get(path).focus();
    return true;