🔥 Use uuid (#393)

This commit is contained in:
Albin Ekblom 2016-07-25 20:01:01 +02:00 committed by Guillermo Rauch
parent cb84548623
commit c88c93a622
3 changed files with 16 additions and 18 deletions

View file

@ -1,7 +1,7 @@
const { app, BrowserWindow, shell, Menu } = require('electron'); const { app, BrowserWindow, shell, Menu } = require('electron');
const createRPC = require('./rpc'); const createRPC = require('./rpc');
const createMenu = require('./menu'); const createMenu = require('./menu');
const genUid = require('uid2'); const uuid = require('uuid');
const { resolve } = require('path'); const { resolve } = require('path');
const isDev = require('electron-is-dev'); const isDev = require('electron-is-dev');
const AutoUpdater = require('./auto-updater'); const AutoUpdater = require('./auto-updater');
@ -251,8 +251,5 @@ app.on('ready', () => {
}); });
function initSession (opts, fn) { function initSession (opts, fn) {
genUid(20, (err, uid) => { fn(uuid.v4(), new Session(opts));
if (err) throw err;
fn(uid, new Session(opts));
});
} }

View file

@ -16,7 +16,7 @@
"mkdirp": "0.5.1", "mkdirp": "0.5.1",
"ms": "0.7.1", "ms": "0.7.1",
"shell-env": "0.1.2", "shell-env": "0.1.2",
"uid2": "0.0.3" "uuid": "^2.0.2"
}, },
"eslintConfig": { "eslintConfig": {
"extends": "standard", "extends": "standard",

View file

@ -1,6 +1,6 @@
const { EventEmitter } = require('events'); const { EventEmitter } = require('events');
const { ipcMain } = require('electron'); const { ipcMain } = require('electron');
const genUid = require('uid2'); const uuid = require('uuid');
class Server { class Server {
@ -8,18 +8,19 @@ class Server {
this.win = win; this.win = win;
this.ipcListener = this.ipcListener.bind(this); this.ipcListener = this.ipcListener.bind(this);
this.emitter = new EventEmitter(); 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` if (this.destroyed) return;
// to support reloading the window and re-initializing
// the channel const uid = uuid.v4();
this.wc.on('did-finish-load', () => { this.id = uid;
this.wc.send('init', 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);
}); });
} }