Skip to content
This repository was archived by the owner on Sep 5, 2020. It is now read-only.

Commit

Permalink
fixed startup crash 'object destroyed'
Browse files Browse the repository at this point in the history
  • Loading branch information
frozeman committed Feb 29, 2016
1 parent b1f3e6e commit ebc6097
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 56 deletions.
28 changes: 17 additions & 11 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var ipcPath = getIpcPath();
global.appName = 'Mist';

global.production = false;
global.mode = 'mist';
global.mode = 'wallet';

global.mainWindow = null;
global.windows = {};
Expand Down Expand Up @@ -154,6 +154,7 @@ app.on('before-quit', function(event){
// app.commandLine.appendSwitch('ignore-cpu-blacklist');
// }

var appStartWindow;

// This method will be called when Electron has done everything
// initialization and ready for creating browser windows.
Expand Down Expand Up @@ -261,7 +262,7 @@ app.on('ready', function() {
const checkNodeSync = require('./modules/checkNodeSync.js');
const net = require('net');
const socket = new net.Socket();
var intervalId = null;
var intervalId = startingTimeout = null;
var count = 0;


Expand All @@ -279,7 +280,7 @@ app.on('ready', function() {
count++;

// STARTING NODE
if(appStartWindow && appStartWindow.webContents)
if(appStartWindow)
appStartWindow.webContents.send('startScreenText', 'mist.startScreen.startingNode');

// read which node is used on this machine
Expand All @@ -297,8 +298,10 @@ app.on('ready', function() {
console.log('Network: ', global.network);

// If nothing else happens, show an error message in 60 seconds
var startingTimeout = setTimeout(function(){
appStartWindow.webContents.send('startScreenText', 'mist.startScreen.nodeNotStarted');
startingTimeout = setTimeout(function(){
console.log('KILLLLLLLLL', appStartWindow.webContents.isDestroyed());
if(appStartWindow)
appStartWindow.webContents.send('startScreenText', 'mist.startScreen.nodeNotStarted');
}, 60000);

var node = ethereumNodes.startNode(nodeType, (global.network === 'test'), function(e){
Expand All @@ -307,15 +310,16 @@ app.on('ready', function() {
// TRY TO CONNECT EVERY 500MS
if(!e) {
intervalId = setInterval(function(){
count++;

if(socket)
socket.connect({path: ipcPath});
count++;

// timeout after 10 seconds
if(count >= 60) {
clearTimeout(startingTimeout);

if(appStartWindow && appStartWindow.webContents && !appStartWindow.webContents.isDestroyed())
if(appStartWindow)
appStartWindow.webContents.send('startScreenText', 'mist.startScreen.nodeConnectionTimeout', ipcPath);

clearInterval(intervalId);
Expand All @@ -328,26 +332,27 @@ app.on('ready', function() {
// NO Binary
} else {

if(appStartWindow && appStartWindow.webContents) {
clearTimeout(startingTimeout);
if(appStartWindow) {
appStartWindow.webContents.send('startScreenText', 'mist.startScreen.nodeBinaryNotFound');
}

clearTimeout(startingTimeout);
clearSocket(socket, true);
}
});
}
});
socket.on('connect', function(data){
console.log('Geth connection FOUND');
if(appStartWindow && appStartWindow.webContents) {
if(appStartWindow) {
if(count === 0)
appStartWindow.webContents.send('startScreenText', 'mist.startScreen.runningNodeFound');
else
appStartWindow.webContents.send('startScreenText', 'mist.startScreen.startedNode');
}

clearInterval(intervalId);
clearTimeout(startingTimeout);

// update menu, to show node switching possibilities
appMenu();
Expand All @@ -356,7 +361,8 @@ app.on('ready', function() {
// -> callback splash screen finished
function(e){

appStartWindow.webContents.send('startScreenText', 'mist.startScreen.startedNode');
if(appStartWindow)
appStartWindow.webContents.send('startScreenText', 'mist.startScreen.startedNode');
clearSocket(socket);
startMainWindow(appStartWindow);

Expand Down
13 changes: 7 additions & 6 deletions modules/checkNodeSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module.exports = function(appStartWindow, callbackSplash, callbackOnBoarding){

// if still needs syncing
} else {
if(appStartWindow && appStartWindow.webContents)
if(appStartWindow && appStartWindow.webContents && !appStartWindow.webContents.isDestroyed())
appStartWindow.webContents.send('startScreenText', 'mist.startScreen.nodeSyncing', {
currentBlock: +result.number
});
Expand All @@ -119,7 +119,7 @@ module.exports = function(appStartWindow, callbackSplash, callbackOnBoarding){
// create timeout for private chains, where no one is mining
if(!timeoutId) {
timeoutId = setTimeout(function(){
if(appStartWindow && appStartWindow.webContents) {
if(appStartWindow && appStartWindow.webContents && !appStartWindow.webContents.isDestroyed()) {
appStartWindow.webContents.send('startScreenText', 'mist.startScreen.privateChainTimeout');

ipc.on('backendAction_startApp', function() {
Expand All @@ -142,11 +142,12 @@ module.exports = function(appStartWindow, callbackSplash, callbackOnBoarding){
clearTimeout(timeoutId);
timeoutId = null;

// remove the private chain button again
appStartWindow.webContents.send('startScreenText', 'mist.startScreen.privateChainTimeoutClear');

if(appStartWindow && appStartWindow.webContents)
if(appStartWindow && appStartWindow.webContents && !appStartWindow.webContents.isDestroyed()) {
// remove the private chain button again
appStartWindow.webContents.send('startScreenText', 'mist.startScreen.privateChainTimeoutClear');
appStartWindow.webContents.send('startScreenText', 'mist.startScreen.nodeSyncing', result);
}

}

}
Expand Down
2 changes: 1 addition & 1 deletion modules/ethereumNodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ module.exports = {
modalWindow = null;
ipc.removeAllListeners('backendAction_unlockedMasterPassword');

} else if(modalWindow) {
} else if(modalWindow && modalWindow.webContents && !modalWindow.webContents.isDestroyed()) {
modalWindow.webContents.send('data', {masterPasswordWrong: true});
}
};
Expand Down
4 changes: 2 additions & 2 deletions modules/ipc/ipcProviderBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,8 @@ module.exports = function(){
}


// if(event.sender.returnValue)
// event.sender.returnValue = socket.ipcSocket.writable;
if(event.sender.returnValue)
event.sender.returnValue = socket.ipcSocket.writable;
// else
// event.sender.send('ipcProvider-setWritable', socket.ipcSocket.writable);
});
Expand Down
3 changes: 3 additions & 0 deletions modules/ipcCommunicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ ipc.on('backendAction_sendToOwner', function(e, error, value) {

if(global.windows[windowId]) {
global.windows[windowId].owner.send('windowMessage', global.windows[windowId].type, error, value);

}
if(global.mainWindow && global.mainWindow.webContents && !global.mainWindow.webContents.isDestroyed()) {
global.mainWindow.webContents.send('mistUI_windowMessage', global.windows[windowId].type, global.windows[windowId].owner.getId(), error, value);
}
});
Expand Down
6 changes: 4 additions & 2 deletions modules/menuItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ var menuTempl = function(webviews) {
devtToolsSubMenu.push({
label: i18n.t('mist.applicationMenu.develop.devToolsWebview', {webview: webview.name}),
click: function() {
global.mainWindow.webContents.send('toggleWebviewDevTool', webview._id);
if(global.mainWindow && global.mainWindow.webContents && !global.mainWindow.webContents.isDestroyed())
global.mainWindow.webContents.send('toggleWebviewDevTool', webview._id);
}
});
});
Expand All @@ -212,7 +213,8 @@ var menuTempl = function(webviews) {
label: i18n.t('mist.applicationMenu.develop.runTests'),
enabled: (global.mode === 'mist'),
click: function(){
global.mainWindow.webContents.send('runTests', 'webview');
if(global.mainWindow && global.mainWindow.webContents && !global.mainWindow.webContents.isDestroyed())
global.mainWindow.webContents.send('runTests', 'webview');
}
}
];
Expand Down
2 changes: 1 addition & 1 deletion modules/popupWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module.exports = {

modalWindow.webContents.on('dom-ready', function() {
// send data, if available
if(data)
if(data && modalWindow && modalWindow.webContents && !modalWindow.webContents.isDestroyed())
modalWindow.webContents.send('data', data);
});
modalWindow.webContents.on('did-finish-load', function() {
Expand Down
6 changes: 3 additions & 3 deletions modules/syncMinimongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ module.exports = function(db, webContents){
// send
db.find().observeChanges({
'added': function(id, fields){
// if(webContents)
// if(webContents && !webContents.isDestroyed())
// webContents.send('minimongo-add', {id: id, fields: fields});
// else
if(!webContents)
ipc.send('minimongo-add', {id: id, fields: fields});
},
'changed': function(id, fields){
// if(webContents)
// if(webContents && !webContents.isDestroyed())
// webContents.send('minimongo-changed', {id: id, fields: fields});
// else
if(!webContents)
ipc.send('minimongo-changed', {id: id, fields: fields});
},
removed: function(id) {
// if(webContents)
// if(webContents && !webContents.isDestroyed())
// webContents.send('minimongo-removed', id);
// else
if(!webContents)
Expand Down
29 changes: 0 additions & 29 deletions modules/web3Admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,35 +244,6 @@ module.exports = {
]
});

// PERSONAL
web3._extend({
property: 'personal',
methods:
[
new web3._extend.Method({
name: 'newAccount',
call: 'personal_newAccount',
params: 1,
inputFormatter: [web3._extend.formatters.formatInputString],
outputFormatter: web3._extend.formatters.formatOutputString
}),
new web3._extend.Method({
name: 'unlockAccount',
call: 'personal_unlockAccount',
params: 3,
inputFormatter: [web3._extend.formatters.formatInputString,web3._extend.formatters.formatInputString,web3._extend.formatters.formatInputInt],
outputFormatter: web3._extend.formatters.formatOutputBool
})
],
properties:
[
new web3._extend.Property({
name: 'listAccounts',
getter: 'personal_listAccounts',
outputFormatter: function(obj) { return obj; }
})
]
});

// TX POOL
web3._extend({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Mist",
"version": "0.4.0",
"version": "0.4.1",
"license": "GPL-3.0",
"repository": {
"type": "git",
Expand Down

0 comments on commit ebc6097

Please sign in to comment.