This repository has been archived by the owner on Jan 24, 2023. It is now read-only.
forked from tubedev2000/micropool-miner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
202 lines (166 loc) · 5.17 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// Modules to control application life and create native browser window
const {app, BrowserWindow, ipcMain} = require('electron')
const storage = require('electron-json-storage');
const contextMenu = require('electron-context-menu');
const path = require('path');
const bonjour = require('nbonjour').create();
const os = require('os');
var emb_miner_status = 0;
global.minerconfig = {
poolport:25650,
poolhost:'',
mining_login:'',
emb_miner:2
};
function isDev() {
return process.mainModule.filename.indexOf('app.asar') === -1;
}
function Log() {}
Log.prototype.log = function (level,message) {if(mainWindow)mainWindow.webContents.send('log', [level,message]);}
Log.prototype.info = function (message) {this.log('info',message);}
Log.prototype.error = function (message) {this.log('error',message);}
Log.prototype.debug = function (message) {this.log('debug',message);}
const logger = new Log();
//process.on("uncaughtException", function(error) {
//logger.error(error.toString());
//});
contextMenu({
showInspectElement: false,
showSearchWithGoogle: false
});
let mainWindow;
function loadstorage(key,callback)
{
storage.has(key,function(error,haskey) {
if(!error && haskey)
{
storage.get(key,function(error,object) {
if(!error && object)
{
callback(false,object);
}
else
{
callback(true);
}
});
}
else
{
callback(true);
}
});
}
var miner_child;
function start_miner() {
var appRootDir = require('app-root-dir').get();
var minerpath;
if(os.type() == 'Linux')
{
if(isDev()){
minerpath = appRootDir + '/dist/bin/linux/miner';
}else{
appRootDir = path.dirname(appRootDir);
minerpath = appRootDir + '/bin/miner';
}
}
else
{
if(isDev()){
minerpath = appRootDir + '\\dist\\bin\\win\\miner.exe';
}else{
appRootDir = path.dirname(appRootDir);
minerpath = appRootDir + '\\bin\\miner.exe';
}
}
const spawn = require( 'child_process' ).spawn;
miner_child = spawn( minerpath, ['-w','0','--algo','cuckaroo29b','--server',global.minerconfig.poolhost+':'+global.minerconfig.poolport,'--user',global.minerconfig.mining_login]); //add whatever switches you need here, test on command line first
miner_child.stdout.on( 'data', data => {
data = data.toString().replace(/^\s+|\s+$/g, '');
mainWindow.webContents.send('log_daemon', data);
});
miner_child.stderr.on( 'data', data => {
logger.error( data );
});
}
function scan(){
bonjour.find({ type: 'telnet' }, function (service) {
if(service.name.startsWith('micropool')) {
mainWindow.webContents.send('add_remote_micropool',service.referer.address, service.port);
}
});
}
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({
title: 'Bittube Miner',
width: 1000,
height: 800,
minWidth: 800,
minHeight: 310,
webPreferences: {nodeIntegration: true},
icon: __dirname + '/build/icon_small.png'
})
//mainWindow.webContents.openDevTools();
mainWindow.setMenu(null);
mainWindow.loadFile('index.html');
ipcMain.on('run',(event,arg) => {
if(arg[0] === "scan_for_micropool") scan();
});
ipcMain.on('init',() => {
loadstorage('poolport',function(error,object) {
if(!error) global.minerconfig.poolport = object;
loadstorage('poolhost',function(error,object) {
if(!error) global.minerconfig.poolhost = object;
loadstorage('mining_login',function(error,object) {
if(!error) global.minerconfig.mining_login = object;
loadstorage('emb_miner',function(error,object) {
if(!error) global.minerconfig.emb_miner = object;
mainWindow.webContents.send('set','poolhost', global.minerconfig.poolhost);
mainWindow.webContents.send('set','poolport', global.minerconfig.poolport);
mainWindow.webContents.send('set','mining_login', global.minerconfig.mining_login);
mainWindow.webContents.send('set','emb_miner', global.minerconfig.emb_miner);
bonjour.find({ type: 'telnet' }, function (service) {
if(service.name.startsWith('micropool')) {
mainWindow.webContents.send('add_remote_micropool',service.referer.address, service.port);
}
});
if(global.minerconfig.emb_miner == 1) {
start_miner();
}
});
});
});
});
});
ipcMain.on('set',(event,arg) => {
if(arg[0] === "mining_login") global.minerconfig.mining_login=arg[1];
if(arg[0] === "poolport") global.minerconfig.poolport=arg[1];
if(arg[0] === "poolhost") global.minerconfig.poolhost=arg[1];
if(arg[0] === "emb_miner"){
if(arg[1] != global.minerconfig.emb_miner) {
global.minerconfig.emb_miner=arg[1];
if(global.minerconfig.emb_miner == 1) {
start_miner();
}else{
if(miner_child)miner_child.kill();
}
}
}
storage.set(arg[0],arg[1]);
});
mainWindow.on('closed', function () {
mainWindow = null
})
}
app.on('ready', createWindow)
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', function () {
if (mainWindow === null) {
createWindow()
}
})