-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
executable file
·67 lines (60 loc) · 1.76 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// main.js - Assigned IP address viewer entry point file
//
// Copyright (c) 2016 Takel Hinomoto
// This file is provided under the MIT license.
const electron = require('electron');
const app = electron.app;
const ipcMain = electron.ipcMain;
const os = require('os');
app.on('ready', () =>
{
let mainWindow = new electron.BrowserWindow({width: 800, height: 600, show: false});
let dirName = __dirname.replace(/\\/g, '/');
mainWindow.loadURL('file://' + dirName + '/index.html');
mainWindow.once('ready-to-show', () =>
{
mainWindow.show();
});
// Dispose mainWindow reference on the window closed.
mainWindow.on('closed', () =>
{
mainWindow = null
});
let webContents = mainWindow.webContents;
webContents.on('did-finish-load', () =>
{
// After this timing. We can send messages to the renderer process.
// webContents.send('main-to-renderer', 'ping');
});
});
// Terminate the app on all windows are closed.
// except OS-X for traditional conventional reason.
app.on('window-all-closed', () =>
{
if (process.platform !== 'darwin')
{
app.quit();
}
});
ipcMain.on('r2mIpAddressRequest', (event, arg) =>
{
// console.log('r2mIpAddressRequest has come.');
const networkInterfaces = os.networkInterfaces();
for (let interfaceDevice in networkInterfaces)
{
networkInterfaces[interfaceDevice].forEach((whatDescribed) =>
{
// console.log(whatDescribed);
if (whatDescribed.internal) { return; }
switch(whatDescribed.family)
{
case 'IPv4':
event.sender.send('m2rIpAddressResponse', { 'type': 'v4', 'name': interfaceDevice, 'address': whatDescribed.address });
break;
case 'IPv6':
event.sender.send('m2rIpAddressResponse', { 'type': 'v6', 'name': interfaceDevice, 'address': whatDescribed.address });
break;
}
});
}
});