🐛 Fix EADDRINUSE errors on Linux/Mac
Clean up last socket on Linux-based systems to avoid EADDRINUSE errors poping up.
This commit is contained in:
parent
63ce2b7871
commit
49b98d447b
20
App.js
20
App.js
|
@ -8,6 +8,9 @@ var ipc = require('ipc');
|
|||
var net = require('net');
|
||||
var util = require('util');
|
||||
var events = require('events');
|
||||
var path = require('path');
|
||||
var os = require('os');
|
||||
var fs = require('fs');
|
||||
|
||||
/**
|
||||
* App
|
||||
|
@ -32,7 +35,10 @@ function App() {
|
|||
|
||||
util.inherits(App, events.EventEmitter);
|
||||
module.exports = App;
|
||||
App.socket = '\\\\.\\pipe\\piano-sock';
|
||||
|
||||
// create pipe on Windows and socks on Linux-based environments
|
||||
App.socket = (process.platform === 'win32') ?
|
||||
'\\\\.\\pipe\\piano-sock' : path.join(os.tmpdir(), 'piano.sock');
|
||||
|
||||
/**
|
||||
* Add a new window
|
||||
|
@ -129,6 +135,18 @@ App.prototype.chainOptions = function (callback) {
|
|||
App.prototype.startServer = function () {
|
||||
var server;
|
||||
|
||||
if (process.platform !== 'win32') {
|
||||
// try to unlink older socket if it exists, if it doesn't,
|
||||
// ignore ENOENT errors
|
||||
try {
|
||||
fs.unlinkSync(App.socket);
|
||||
} catch (e) {
|
||||
if (e.code !== 'ENOENT') {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
server = net.createServer(function (connection) {
|
||||
connection.on('data', function (data) {
|
||||
this.windows[0].focus();
|
||||
|
|
Loading…
Reference in New Issue