From c88c93a622b0d1f2f6c80ae2f7412605094efef0 Mon Sep 17 00:00:00 2001 From: Albin Ekblom Date: Mon, 25 Jul 2016 20:01:01 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Use=20uuid=20(#393)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/index.js | 7 ++----- app/package.json | 2 +- app/rpc.js | 25 +++++++++++++------------ 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/app/index.js b/app/index.js index 731aaa02..6a1acd7f 100644 --- a/app/index.js +++ b/app/index.js @@ -1,7 +1,7 @@ const { app, BrowserWindow, shell, Menu } = require('electron'); const createRPC = require('./rpc'); const createMenu = require('./menu'); -const genUid = require('uid2'); +const uuid = require('uuid'); const { resolve } = require('path'); const isDev = require('electron-is-dev'); const AutoUpdater = require('./auto-updater'); @@ -251,8 +251,5 @@ app.on('ready', () => { }); function initSession (opts, fn) { - genUid(20, (err, uid) => { - if (err) throw err; - fn(uid, new Session(opts)); - }); + fn(uuid.v4(), new Session(opts)); } diff --git a/app/package.json b/app/package.json index 61fdb2bd..a99d34c8 100644 --- a/app/package.json +++ b/app/package.json @@ -16,7 +16,7 @@ "mkdirp": "0.5.1", "ms": "0.7.1", "shell-env": "0.1.2", - "uid2": "0.0.3" + "uuid": "^2.0.2" }, "eslintConfig": { "extends": "standard", diff --git a/app/rpc.js b/app/rpc.js index d41835e0..db198777 100644 --- a/app/rpc.js +++ b/app/rpc.js @@ -1,6 +1,6 @@ const { EventEmitter } = require('events'); const { ipcMain } = require('electron'); -const genUid = require('uid2'); +const uuid = require('uuid'); class Server { @@ -8,18 +8,19 @@ class Server { this.win = win; this.ipcListener = this.ipcListener.bind(this); this.emitter = new EventEmitter(); - genUid(10, (err, uid) => { - if (this.destroyed) return; - if (err) return this.emitter.emit('error', err); - this.id = uid; - ipcMain.on(uid, this.ipcListener); - // we intentionally subscribe to `on` instead of `once` - // to support reloading the window and re-initializing - // the channel - this.wc.on('did-finish-load', () => { - this.wc.send('init', uid); - }); + if (this.destroyed) return; + + const uid = uuid.v4(); + this.id = uid; + + ipcMain.on(uid, this.ipcListener); + + // we intentionally subscribe to `on` instead of `once` + // to support reloading the window and re-initializing + // the channel + this.wc.on('did-finish-load', () => { + this.wc.send('init', uid); }); }