arboleya / electrify

Package your Meteor apps with Electron, and butter
MIT License
247 stars 52 forks source link

Empty screen #6

Closed rafaelcorreiapoli closed 9 years ago

rafaelcorreiapoli commented 9 years ago

Hi, when I compile the app (go to app's folder, >meteor shell, >electrify), it runs normally on the first time (app/.electrify/.dist/Electrified-linux-x64/Electrified) but when I close it and run again, I get a white empty screen... the window's title also changes to "Electron" instead of "electrify"... if I do >meteor shell >electrify again, the proccess repeats and I can see the app again (only for the first time running)

miri-am commented 9 years ago

same for me but always. A simpler app worked fine, however, my larger project just shows an empty screen.

arboleya commented 9 years ago

Thanks for reporting, I'm gonna check into it.

arboleya commented 9 years ago

@miri-am Which OS are you running on?

miri-am commented 9 years ago

I was using: Meteor 1.2-rc.10
OS X 10.9.5

AlexFrazer commented 9 years ago

Me too. OS X 10.10.5 Here's what happens when I use ./Electron in the folder.

[51679:0904/164025:WARNING:dns_config_service_posix.cc(150)] dns_config has unhandled options!
app ready
{ _events:
   { blur: [Function],
     focus: [Function],
     'devtools-opened': [Function] },
  _eventsCount: 3 }
{ boot: [Function], shutdown: [Function] }
elecrify:  starting mongo
elecrify:  [mongo::log] 2015-09-04T16:40:26.267-0400 [initandlisten] MongoDB starting : pid=51682 port=11235 dbpath=/Users/afrazer/Code/health-pillbot/app/.electrify/.dist/Electrified-darwin-x64/Electrified.app/Contents/Resources/app/db 64-bit host=Alexanders-MacBook-Pro.local
2015-09-04T16:40:26.267-0400 [initandlisten] db version v2.6.7
2015-09-04T16:40:26.267-0400 [initandlisten] git version: nogitversion

elecrify:  [mongo::log] 2015-09-04T16:40:26.267-0400 [initandlisten] OpenSSL version: OpenSSL 1.0.2 22 Jan 2015
2015-09-04T16:40:26.267-0400 [initandlisten] build info: Darwin meteor.local 11.4.0 Darwin Kernel Version 11.4.0: Mon Apr  9 19:32:15 PDT 2012; root:xnu-1699.26.8~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
2015-09-04T16:40:26.267-0400 [initandlisten] allocator: tcmalloc
2015-09-04T16:40:26.268-0400 [initandlisten] options: { net: { bindIp: "127.0.0.1", port: 11235 }, storage: { dbPath: "/Users/afrazer/Code/health-pillbot/app/.electrify/.dist/Electrified-darwin-x64/Electrified.app/Contents/Resources/app/db", smallFiles: true } }
2015-09-04T16:40:26.268-0400 [initandlisten] journal dir=/Users/afrazer/Code/health-pillbot/app/.electrify/.dist/Electrified-darwin-x64/Electrified.app/Contents/Resources/app/db/journal

elecrify:  [mongo::log] 2015-09-04T16:40:26.269-0400 [initandlisten] recover : no journal files present, no recovery needed

elecrify:  [mongo::log] 2015-09-04T16:40:26.278-0400 [initandlisten] allocating new ns file /Users/afrazer/Code/health-pillbot/app/.electrify/.dist/Electrified-darwin-x64/Electrified.app/Contents/Resources/app/db/local.ns, filling with zeroes...

elecrify:  [mongo::log] 2015-09-04T16:40:26.309-0400 [FileAllocator] allocating new datafile /Users/afrazer/Code/health-pillbot/app/.electrify/.dist/Electrified-darwin-x64/Electrified.app/Contents/Resources/app/db/local.0, filling with zeroes...
2015-09-04T16:40:26.309-0400 [FileAllocator] creating directory /Users/afrazer/Code/health-pillbot/app/.electrify/.dist/Electrified-darwin-x64/Electrified.app/Contents/Resources/app/db/_tmp

elecrify:  [mongo::log] 2015-09-04T16:40:26.329-0400 [FileAllocator] done allocating datafile /Users/afrazer/Code/health-pillbot/app/.electrify/.dist/Electrified-darwin-x64/Electrified.app/Contents/Resources/app/db/local.0, size: 16MB,  took 0.019 secs

elecrify:  [mongo::log] 2015-09-04T16:40:26.344-0400 [initandlisten] build index on: local.startup_log properties: { v: 1, key: { _id: 1 }, name: "_id_", ns: "local.startup_log" }

elecrify:  [mongo::log] 2015-09-04T16:40:26.345-0400 [initandlisten]     added index to empty collection

elecrify:  [mongo::log] 2015-09-04T16:40:26.345-0400 [initandlisten] waiting for connections on port 11235

elecrify:  mongo started
elecrify:  starting meteor { MONGO_URL: 'mongodb://localhost:11235/meteor',
  PORT: 11236,
  ROOT_URL: 'http://localhost' }
arboleya commented 9 years ago

@AlexFrazer Yes, the meteor's startup process gets frozen, however no errors are raised. I'm gonna look into it this weekend.

arboleya commented 9 years ago

Are you guys still having this problem? I cannot reproduce it anymore on my side, in any OS.

However I suspect I found something that might be causing blank screen, I'll release a patch so we can see how it goes.

arboleya commented 9 years ago

Please update to last version:

meteor remove arboleya:electrify && meteor add arboleya:electrify

@shactdeveloper @AlexFrazer Can you guys please tell me if it's working fine now?

@miri-am Can you tell me if your larger project works fine now? I cannot see any relation between the project size and this blank-screen thing.

AlexFrazer commented 9 years ago

Still getting the same result, both using the meteor package and NPM. I am at release 1.1.2 on both.

I'll look into it a bit, this library seems the most reliable of all the ones out there. If I find the problem, I'll put in a PR

arboleya commented 9 years ago

@AlexFrazer This is very weird, besides I can't reproduce it anymore. What is your version of Meteor?

In case you want to dig deeper, I suggest you to:

  1. Compile the app
  2. Add and move a console.log line from up to bottom, at the file:
.electrify/.dist/Electrified-darwin-x64/Electrified.app/Contents/Resources/app/app/programs/server/boot.js
  1. After each line move, open your app via Electron:
.electrify/.dist/Electrified-darwin-x64/Electrified.app/Contents/MacOS/Electron

This way, when the console.log stops appearing in the terminal, you'll get the exact point of the Meteor's boot process has stopped.

This can give us some idea.

arboleya commented 9 years ago

@AlexFrazer One question, you did the upgrade on a existent project, or a new one?

Like meteor create --example leaderboard or something.

AlexFrazer commented 9 years ago

TL;DR: The source of the problem.

It's when you use Meteor.settings in your program. The reason I suspected it is because when packages or code uses Meteor.settings and you replace it with a plain object, it works fine. (full code from original before)

// let remoteSettings = Meteor.settings.public.remote;
// changed it to this:
let remoteSettings = { url: 'http://localhost:4000', _id: '1234' };

Ideally the solution would be a --settings flag on the npm package and meteor package.

For a minimal reproducible example, try creating leaderboard, giving it some settings, and then referencing those settings.


Okay, went through some debugging. Basically, I found that it never completely finished the _.each in the fiber function (line 116). The total number of iterations it should have to load every package is 89. It halts at 75 for my package: insightfil:galil. When I meteor.remove this package, it will complain on the 82nd iteration, with my file called lib/connection.es6.

let remoteSettings = Meteor.settings.public.remote;

Remote = DDP.connect(remoteSettings.url);

Accounts.connection = Remote;
Meteor.connection = Remote;

Meteor.users = new Mongo.Collection('users', Remote);
Orders = new Mongo.Collection('orders', Remote);
// .. a few more of these

FlowRouter.subscriptions = function () {
  this.register('workstation', Remote.subscribe('workstation', remoteSettings._id));
  this.register('machine', Meteor.subscribe('machine'));
}

if (Meteor.isClient) {
  Accounts.onLogin(function () {
    Meteor._localStorage.setItem('_token', Accounts._storedLoginToken());
  });

  Meteor.connection.onReconnect = function () {
    Meteor.loginWithToken(Meteor._localStorage.getItem('_token'));
    Remote.subscribe('workstation', remoteSettings.robot);
  }
}

So I tried commenting out the whole file. This working completely fine, and the application loaded (with expected errors), but it did pass the _.each phase

arboleya commented 9 years ago

@AlexFrazer I don't think the net package have nothing to do with it, unless the error came from an net exception that however get lost and not shown. Like, for instance, trying opening a socket connection with a port that's already in use (with was exactly my last patch).

Anyway, I could not test the insightfil:galil because without one of these controllers it raises an error Host or port not specified and the process always exits with this error.

But lets move on in two steps:

1 - electrify version

One thing came to mind: Your Electron app may be not running the electrify package at version 1.1.2, even if you updated the Meteor package and you global/local NPM module to 1.1.2. Weird? Yes, I'll have to resolve this design.

But lets move on and re-check its version and force-update things if necessary. The 1.1.2 patch is required for this.

Please:

  1. Check the electrify version inside the .electrify/package.json file
  2. If it's older, update it to 1.1.2
  3. Remove the rm -rf .electrify/node_modules folder
  4. Run cd .electrify && npm install
  5. Try packaging and running your app again

If it does not work, move to part #2.

2 - isolating electrify

Looking forward, one way of isolating the problem is by removing the electrify package from the equation.

Your Meteor app should work 100% without it, so let's double check it:

Please remove the .electrify/node_modules folder and package the app again, then open two terminal tabs and run the lines (bellow).

After mongodb and meteor is up, try accessing the app at http://localhost:3000.

With a little bit of luck, we're gonna trace the evil code spot.

Terminal 1

# enter app foder inside the packaged electron
cd .electrify/.dist/Electrified-darwin-x64/Electrified.app/Contents/Resources/app

# start mongodb as Electrify does (port number may vary)
mkdir -p db && ./bin/mongod --dbpath ./db --port 3001 --bind_ip 127.0.0.1 --smallfiles

Terminal 2

# enter app foder inside the packaged electron
cd .electrify/.dist/Electrified-darwin-x64/Electrified.app/Contents/Resources/app

# start meteor
MONGO_URL=mongodb://localhost:3001/meteor PORT=3000 ROOT_URL=http://localhost ELECTRON_PRODUCTION=true ./bin/node ./app/main.js
arboleya commented 9 years ago

@AlexFrazer Just saw you've edited your last post with more info about settings, I'm gonna look into it.

In your case, as I see it, you don't need the server running locally right? You're looking for just the client code connecting to a remote server, right?

Those remote settings could be used at build time also, to build the client side only, so you wouldn't have to alter your connection settings manually. Makes sense?

arboleya commented 9 years ago

@AlexFrazer However, I've release 1.1.3 with a little fix regarding updates.

AlexFrazer commented 9 years ago

I do use a server locally, as well as a remote server (it's a pretty odd system, involves some TCP sockets to control a robot and a remote database for orders). Yeah I edited it a lot of times as I was going haha, I can get it compiled and running on both windows 8.1 and OS X now. Would be nice to have flags to add to the meteor build process, especially --settings for deployments to different machines. I am going to check tomorrow morning if adding the environment variable of METEOR_SETTINGS will work to the same effect

arboleya commented 9 years ago

@AlexFrazer Can't believe man! haha

Now everything makes sense.

  1. Electrify wasn't handling the settings
    • So the default was always Meteor.settings = {}
  2. Your app was always crashing when trying to read Meteor.settings.public.remote
    • Since property public was null - Cannot read property 'public' of undefined

This error should have been raised and instead it went silently (gotta check that!), which made it much hard to find this bug. Appreciate all the help man. Great job!

Did some last minute improvements today, and --settings is now properly handled. Pls update again.

Let me know if it worked.

:beers:

miri-am commented 9 years ago

@arboleya. Thanks for solving this! Works for me now :)

rafaelcorreiapoli commented 9 years ago

I'm still getting the problem of empty screen whenever I run the app for the second time =( using electrify 1.2.1

arboleya commented 9 years ago

@shactdeveloper You're on linux right? Ubuntu? I'll do some further research through it.

arboleya commented 9 years ago

@shactdeveloper I cannot reproduce this blank screen anymore, no matter what. Perhaps it was already fixed?

I need more information to keep digging it, if you could put a repo with instructions for me to reproduce the error, it could be a start.

I've already tested it with a simple leaderboard example:

meteor create --example leaderboard
cd leaderboard && meteor add arboleya:electrify && meteor

Then I've packaged the App

cd leaderboard
meteor shell
electrify

And was able to open/close it indefinitely..

arboleya commented 9 years ago

Hello @shactdeveloper @AlexFrazer @miri-am

I've just released a complete revamp version of the project, now it has tests and I'm confident it's way more stable than before.

Can you please update and report back if you still are facing the problem you've mentioned?

Some notes on upgrading: https://github.com/arboleya/electrify#upgrading

Thanks in advance.

AlexFrazer commented 9 years ago

Perfect timing; I am currently building it for windows, mac, and ubuntu, I'll let you know

arboleya commented 9 years ago

Great.

arboleya commented 9 years ago

@AlexFrazer Forgot to mention, there are some little breaking changes about packaging the app with the last release.

Check it out https://github.com/arboleya/electrify/#packaging

arboleya commented 9 years ago

@AlexFrazer There was a little problem on Windows that prevented the app from running after being packaged, fixed in last release.

arboleya commented 9 years ago

Hello everybody, any news about this issue?

I guess it's working, can someone confirm if the bug was fixed?

lacymorrow commented 9 years ago

I didn't have the initial issue, but tested just now with my app and it seems to be working, was able to load multiple times with no blank screen.

Nice update @arboleya !

arboleya commented 9 years ago

This issue is inactive for more than 1 month now and I believe it is resolved, so I'm closing.

In case anyone faces this again, please open a new issue.