How to use electron-better-ipc - 10 common examples

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 atomiclabs / hyperdex / app / index.js View on Github external
if (!mainWindow) {
		mainWindow = createMainWindow();
	}
});

app.on('window-all-closed', () => {
	app.quit();
});

app.on('before-quit', () => {
	if (rendererState.isLoggedIn) {
		config.set('windowState', mainWindow.getNormalBounds());
	}
});

ipc.answerRenderer('start-marketmaker', async seedPhrase => {
	// We have to do this dance as IPC doesn't correctly serialize errors.
	try {
		await marketmaker.start({seedPhrase});
	} catch (error) {
		logger.error('Failed to start Marketmaker:', error);
		throw error;
	}

	return marketmaker.port;
});

ipc.answerRenderer('stop-marketmaker', async () => {
	await marketmaker.stop();
});

ipc.answerRenderer('set-active-view-on-dom-ready', view => {
github deadcoder0904 / wip-desktop / src / main / index.js View on Github external
app.on("activate", () => {
  // on macOS it is common to re-create a window even after all windows have been closed
  if (mainWindow === null) {
    mainWindow = createMainWindow(mainWindow);
  }
});

// create main BrowserWindow when electron is ready
app.on("ready", () => {
  mainWindow = createMainWindow(mainWindow);
  createMenu();
  new AppUpdater();
});

answerRenderer("app-quit", () => {
  app.quit();
});

answerRenderer("app-minimize", () => {
  if (!mainWindow.isMinimized()) {
    mainWindow.minimize();
  } else {
    mainWindow.restore();
  }
});

answerRenderer("app-maximize", () => {
  if (!mainWindow.isFullScreen()) {
    mainWindow.setFullScreen(true);
  } else {
    mainWindow.setFullScreen(false);
github WhiteMinds / LiveAutoRecord / src / main / index.js View on Github external
mainWindow.on('close', (event) => {
    if (store.recordingChannels.length > 0) {
      // 有录制中的视频, 将关闭过程转交给主窗口
      event.preventDefault()
      ipc.callRenderer(mainWindow, IPCMsg.OpenCloseTip)
    } else {
      // 主窗口关闭直接强制退出, 后面要兼容mac的话应该还要再修改
      app.quit()
    }
  })
github pacocoursey / Opus / src / renderer.js View on Github external
// Init all the modules
theme.init();
quill.init();
editor.init();
sidebar.init();
contextMenu.init();
footer.init();

ipcRenderer.on('message', (e, d) => {
  const { method, module, parameters } = d;
  modules[module][method](parameters);
});

// Save editor contents
ipc.answerMain('save', async () => {
  editor.save();
  return true;
});

window.onbeforeunload = (e) => {
  const changes = store.get('changes');

  if (changes) {
    const choice = dialog.showMessageBox({
      type: 'question',
      buttons: ['Save', 'Cancel', 'Don\'t Save'],
      title: 'Confirm',
      message: `${store.get('path')} has changes, do you want to save them?`,
      detail: 'Your changes will be lost if you close this file without saving.',
      icon: `${app.image}`,
    });
github WhiteMinds / LiveAutoRecord / src / renderer / App.vue View on Github external
async init () {
        log.info('Initializing config module...')
        await config.init()

        if (this.$route.name === Route.Player) {
          // 播放器不需要加载其他内容
          this.starting = false
          return
        }

        log.info('Initializing close tip handler...')
        ipc.answerMain(IPCMsg.OpenCloseTip, this.OpenCloseTip)

        log.info('Initializing database module...')
        await db.init()

        log.info('Initializing ffmpeg configuration...')
        ffmpeg.setFfmpegPath(ffmpegStatic.path.replace('app.asar', 'app.asar.unpacked'))

        log.info('Loading channels...')
        this.$store.channels = await db.Channel.findAll()

        recorder.init()

        this.starting = false
      },
      onMenuSelect (name) {
github rethinkdb / rethinkdb-desktop / app / main / db / index.js View on Github external
const connectResult = await connect({ host, port, username, password })
  // connection created - we can start pushing updates
  startLiveStats()
  startClusterReadWriteChanges()
  return connectResult
})

ipc.answerRenderer(QUERIES_CHANNEL_NAME, async query => {
  return queryResolver(query)
})

ipc.answerRenderer(ACTIONS_CHANNEL_NAME, async action => {
  return actionResolver(action)
})

ipc.answerRenderer(EVAL_QUERY_CHANNEL_NAME, async code => {
  return evalQuery(code)
})
github rethinkdb / rethinkdb-desktop / app / main / db / index.js View on Github external
const ipc = require('electron-better-ipc')
const { connect } = require('./driver')
const evalQuery = require('./evalQuery')
const { startLiveStats } = require('./models/stats')
const { startClusterReadWriteChanges } = require('./models/cluster')
const queryResolver = require('./resolvers/queryResolver')
const actionResolver = require('./resolvers/actionResolver')
const url = require('../helpers/url')
const {
  CONNECT_CHANNEL_NAME,
  QUERIES_CHANNEL_NAME,
  ACTIONS_CHANNEL_NAME,
  EVAL_QUERY_CHANNEL_NAME
} = require('../../shared/channels')

ipc.answerRenderer(CONNECT_CHANNEL_NAME, async ({ name, address, username, password }) => {
  const { host, port } = url.extract(address)
  const connectResult = await connect({ host, port, username, password })
  // connection created - we can start pushing updates
  startLiveStats()
  startClusterReadWriteChanges()
  return connectResult
})

ipc.answerRenderer(QUERIES_CHANNEL_NAME, async query => {
  return queryResolver(query)
})

ipc.answerRenderer(ACTIONS_CHANNEL_NAME, async action => {
  return actionResolver(action)
})
github atomiclabs / hyperdex / app / index.js View on Github external
// We have to do this dance as IPC doesn't correctly serialize errors.
	try {
		await marketmaker.start({seedPhrase});
	} catch (error) {
		logger.error('Failed to start Marketmaker:', error);
		throw error;
	}

	return marketmaker.port;
});

ipc.answerRenderer('stop-marketmaker', async () => {
	await marketmaker.stop();
});

ipc.answerRenderer('set-active-view-on-dom-ready', view => {
	mainWindow.webContents.once('dom-ready', () => {
		mainWindow.webContents.send('set-active-view', view);
	});
});
github pacocoursey / Opus / src / intro / intro.js View on Github external
async function transition(increment = 1) {
  const newIndex = index + increment;

  if (newIndex >= content.children.length
      || newIndex >= sections.children.length
      || newIndex < 0) {
    await ipc.callMain('closeIntroWindow');
    return;
  }

  index += increment;

  // Change the button to show "Finish" instead of "Next"
  if (index === content.children.length - 1) {
    button.textContent = 'Finish';
  } else {
    button.textContent = 'Next';
  }

  if (index > 0) {
    back.classList.add('active');
  } else {
    back.classList.remove('active');
github pacocoursey / Opus / src / helpers.js View on Github external
async click() {
            // If called from splash window, send a message to show spinner
            if (BrowserWindow.getFocusedWindow() === splashWindow) {
              ipc.callRenderer(splashWindow, 'showSpinner');
            }

            const res = await openWindow();

            if (res) {
              closeSplashWindow();
            }
          },
        },