How to use the electron-better-ipc.answerMain 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 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 pacocoursey / Opus / src / splash / splash.js View on Github external
function initListeners() {
  // Listen for message to toggle theme
  ipcRenderer.on('message', (e, d) => {
    const { method, module } = d;

    if (module === 'theme' && method === 'toggle') {
      document.body.classList.toggle('dark');
      const isDark = document.body.classList.contains('dark');
      settings.set('intro.dark', isDark);
    }
  });

  // Listen for message to show spinner
  ipc.answerMain('showSpinner', async () => {
    spinner.classList.add('active');
  });

  // Send message to main process to prompt for a folder.
  footer.addEventListener('click', async () => {
    spinner.classList.add('active');
    const res = await ipc.callMain('openProject');
    if (!res) spinner.classList.remove('active');
  });

  // Open GitHub page when each link is clicked.
  document.querySelectorAll('.link').forEach((link) => {
    link.addEventListener('click', () => {
      shell.openExternal('https://github.com/pacocoursey/Opus/');
    });
  });
github atomiclabs / hyperdex / app / renderer / containers / App.js View on Github external
appContainer.subscribe(() => {
	// TODO: This can be removed when the update issue is fixed in Electron:
	// https://github.com/electron/electron/issues/12636
	if (appContainer.state.activeView === prevState.activeView) {
		return;
	}

	prevState = appContainer.state;

	ipc.send('app-container-state-updated', appContainer.state);
});

// We send an initial event so it can show the correct menu state after logging out
ipc.send('app-container-state-updated', appContainer.state);

ipc.answerMain('current-portfolio-id', () => appContainer.state.portfolio.id);

window.addEventListener('beforeunload', () => {
	ipc.callMain('stop-marketmaker');
});

export default appContainer;
github deadcoder0904 / wip-desktop / src / components / Titlebar / index.js View on Github external
componentDidMount() {
    answerMain("window-blur", () => {
      this.setState(prevState => ({
        isBlur: !prevState.isBlur,
      }));
    });
  }
github rethinkdb / rethinkdb-desktop / app / renderer / service / ipc.js View on Github external
export const liveStats = callback => {
  ipc.answerMain(STATS_CHANNEL_NAME, data => callback(data))
}
github npezza93 / archipelago / app / about / index.js View on Github external
const {is, api} = require('electron-util')
const ipc = require('electron-better-ipc')

if (!is.macos) {
  const {createElement} = require('react')
  const {render} = require('react-dom')
  const TrafficLights = require('../common/traffic-lights')

  render(
    createElement(TrafficLights), document.querySelector('#traffic-lights')
  )
}

document.querySelector('#version').innerText = `v${api.app.getVersion()}`

ipc.answerMain('close-current-tab', () => window.close())
github WhiteMinds / LiveAutoRecord / src / renderer / modules / config.js View on Github external
async init () {
      let data = await ipc.callMain(IPCMsg.GetConfig)
      this.setData(data)

      ipc.answerMain(IPCMsg.SetConfig, this.setData)
    },
    async setData (data) {
github npezza93 / archipelago / app / settings / index.js View on Github external
ReactDOM.render(
  React.createElement(TrafficLights),
  document.querySelector('#titlebar')
)

document.querySelector('#hamburger').addEventListener('click', () => {
  profilesContainer.style.left = '0px'
  return backdrop.classList.add('active')
})

backdrop.addEventListener('click', () => {
  profilesContainer.style.left = '-275px'
  return backdrop.classList.remove('active')
})

ipc.answerMain('close-current-tab', () => window.close())
github rethinkdb / rethinkdb-desktop / app / renderer / service / ipc.js View on Github external
export const liveClusterReadWrite = callback => {
  ipc.answerMain(CLUSTER_CHANNEL_NAME, data => callback(data))
}