Hold splashscreen with launch-screen - javascript

I've tried everything and I can't get https://atmospherejs.com/meteor/launch-screen to work.
I'd like to hold the Android's splashscreen with var handle = LaunchScreen.hold(); but it doesn't seem to affect my app at all.
I tried to put it in different folders of my application (root, client root...), to wrap it with Meteor.startup, to use multiple handles, to put it in my iron-router... No chance yet.
Then I started to play with mobile-config since I suspected the config.xml to be the source of my problem. I tried to change "AutoHideSplashScreen" to true (meh, you never know...), to change the delay... It doesn't work either.
Finally, I took a shot at deleting completely the "launch-screen" package, but even when it doesn't appear with "meteor list", it's still there when I inspect my Android application. Maybe it needed to be overriden...
Anyway, I really need your help, thanks a lot !
EDIT : samples of my code
in /both/routes.js
Router.configure({
layoutTemplate : 'mainLayout',
loadingTemplate: 'launchScreen',
// Transitions
// TODO : Use CSS or transition.js ? Slide or fade ?
onBeforeAction : function(){
$('.container').css({opacity: 0});
this.next();
},
onAfterAction : function(){
$('.container').transition({ opacity: 1 });
}
});
// Routes
Router.map(function() {
this.route('home', {path: '/'});
this.route('news', {path: '/news'});
});
And if I try to put :
var handle = LaunchScreen.hold();
Anywhere in a file located in /client/*, it doesn't do anything.
Nothing special at the moment in my mobile-config, I deleted everything I tried...
// Allow XMLHttpRequest
App.accessRule("*");

You have to put var handle = LaunchScreen.hold(); at the very "beginning" of your client code so it is loaded before everything else.
To do this you can put it in a file located in the yourApp/client/lib/ folder (loaded before every other folders) and name the file with an underscore as files are loaded in alphabetical order.

Ok, it seems like I figured out a hack arround this for now.
I added App.setPreference("SplashScreenDelay", 90000); in my mobile-config.js, since I noticed that even if the splashscreen is on hold, if the delay is out, its fades anyway.
It's hacky but I'll deal with it for now. :/

Related

NightwatchJS method .resizeWindow not working

A while back, I had an issue using the .maximizeWindow() from NightwatchJS. I was able to resolve this issue by using the following:
"chromeOptions" : {
"args" : ["start-maximized"]
},
However, this was more a work around than a fix. Currently, I need to resize the window, not just maximize it, and want to use the .resizeWindow() method. I also need this to work in browsers other than Chrome, so the above fix is inadequate. Below is my current setup in a test I am writing. This code worked fine in the past and just recently I noticed that the window was no longer resizing correctly. Any thoughts on why it might be failing? Note: this is written in Coffeescript, not JS.
module.exports = {
"Geoprocessing Commands and Assert Tests": (browser) ->
browser
.launchAs "anonymous"
.assert.title "<app name>"
.iFrameReady()
.frame 0, () ->
browser
.resizeWindow 1800, 1000
.pageDisplayed()
.pause 1000
...
.frameParent()
browser.end()
}

Using sortable.js and turbolinks in Rails 5

I have a Rails 5.1 app in which I am using the sortable.js library from https://www.kryogenix.org/code/browser/sorttable/ in order to do some simple client-side sorting of tables.
I am running into an issue where, when the page first loads, the table sorting does not work. (It just doesn't respond at all.) If you then manually reload the page (cmd-R or equivalent), then it does work.
After some searching, I believe that the problem is being caused by turbolinks. Posts like this one, and others suggest how to modify the JS code to solve it: Rails javascript only works after reload
To quote from the answer on that page you have to tell turbolinks to load by doing this:
document.addEventListener("turbolinks:load", function() {
my_func();
})
I, however, am not a JS expert, and so am a bit loathe to monkey around in the sortable.js code too much. I'm looking for help as to the least invasive way to solve the problem.
Posting a working solution, for the sake of future Google-ers.
I had to do two things to get this to work:
1: Comment out to lines at the top of the init function which prevent it from running more than once. So the top of my init function in sorttable.js looks like this:
sorttable = {
init: function() {
// Had to comment these top to out to get things to work with turbolinks
// quit if this function has already been called
//if (arguments.callee.done) return;
// flag this function so we don't do the same thing twice
//arguments.callee.done = true
Add this code somewhere else in the file. (I personally added it after the line that says "window.onload = sorttable.init;"
document.addEventListener("turbolinks:load", function() {
sorttable.init();
})

Metoer.js: iron-router Router.route() not working

I'm using Meteor.js and iron-router for the first time, and so far everything is going well, except for iron-router. I call this code at the beginning of my js file.
Router.route('/find_tutors', function () {
this.render('content_find_tutors');
});
Really simple, nothing interesting whatsoever going on here, the problem is it just doesn't work. I get this error if I navigate to the URL http://foobar.bar/find_tutors
Exception in defer callback: Error: Oh no! No route found for path: "/find_tutors"
at Utils.extend.onRouteNotFound (http://localhost:3000/packages/iron_router.js?da7f2ac81c3fd9daebf49ce9a6980a54caa1dc17:1714:13)
at IronRouter.dispatch (http://localhost:3000/packages/iron_router.js?da7f2ac81c3fd9daebf49ce9a6980a54caa1dc17:1201:19)
at http://localhost:3000/packages/iron_router.js?da7f2ac81c3fd9daebf49ce9a6980a54caa1dc17:1666:12
at Tracker.Computation._compute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:288:36)
at new Tracker.Computation (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:206:10)
at Object.Tracker.autorun (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:476:11)
at Utils.extend.start (http://localhost:3000/packages/iron_router.js?da7f2ac81c3fd9daebf49ce9a6980a54caa1dc17:1663:10)
at http://localhost:3000/packages/iron_router.js?da7f2ac81c3fd9daebf49ce9a6980a54caa1dc17:1458:16
at _.extend.withValue (http://localhost:3000/packages/meteor.js?012a26290d9cb731a3b52b396e571c8159d11236:891:17)
at http://localhost:3000/packages/meteor.js?012a26290d9cb731a3b52b396e571c8159d11236:430:45
I feel like something obvious is off but honestly this code is just so simple I don't see why I can't get it to work. Am I wrong in saying that it should just render that template if it reaches that route? Though I suppose it doesn't even matter whats in the route() function block, because iron router never even gets there.
Here is the smallest set of code I can give to recreate the error (though the error happens regardless of the size of the code.)
//test.js
Router.route('/find_tutors', function () {
this.render('page');
});
if (Meteor.isClient) {
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}
<!--- test.html --->
<head>
<title>Test</title>
</head>
<body>
</body>
<template name="page">
<h1>Welp.</h1>
</template>
This example is hosted at cvoege.meteor.com
Am I an idiot or is there something deep going on?
iron:router changed some of its api in 1.0.0 version (still in 1.0.0-pre4 at this moment).
And it seems that you are using iron:router in the 1.0.0 way but not the current (0.9.4) one.
You can update your iron:router to 1.0.0-pre4 by
meteor update iron:router#1.0.0-pre4
Update
It seems that I misuse the update function. Please remove and then re-install it instead.
meteor remove iron:router
meteor add iron:router#1.0.0-pre4

Game with AngularJS/Phaser.io and destroy method

I am making a game with a friend and we have some problems with AngularJS and Phaser.
So, we have a page named game, it has a template, a controller and a factory.
There is a page who "redirect" us to the game page (just with a link).
In the template :
<div id="game"></div>
Back
In the factory :
// function prealod and create ....
init: function(data) {
game = new Phaser.Game(width, height, Phaser.AUTO, 'game', { preload: preload, create: create });
},
destroy: function() {
game.destroy();
}
In the controller :
gameFact.init();
$scope.$on('$destroy', function() {
gameFact.destroy();
});
Of course, there are more code.
The problem is simple :
If i come to the game page, Phaser load very well the game (we just display a map with sprites).
After that, i click on the back button and reclick on the link to return to the game page.
If i do that 7 times, there is an error in the console :
Uncaught SyntaxError: Failed to construct 'AudioContext': number of hardware contexts reached maximum (6).
And after few seconds, i have this error :
Uncaught TypeError: Cannot read property 'gain' of undefined
I already search on the web, and the solution are :
Use an iFrame (I really don't think that iFrame is a good solution)
Use the destory method (it doesn't work)
Do you know how to solve this problem ?
If you have any ideas, don't hesitate. Even if you use another game framework (maybe it works the same way).
I had a similar issue, it seems that destroy() doesn't work correctly (issue discussed here) with the current version:
Could you please test out the dev branch, which has lots of fixes for this in.
I resolved the issue by using the dev branch (available here)
You need to use an Angular directive and using the navigation event to do that, check my example: http://market.ionic.io/plugins/ionphaser
Regards, Nicholls
There's a new WebComponent to integrate Phaser with any other Framework https://github.com/proyecto26/ion-phaser

Backbone/jQuery mobile duplicate view

I've got some problems with my Backbone, RequireJS & jQuery mobile application.
When I use a form view 2 times the form submit event is fired twice.
Each new view is added to the body and the previous view will be removed. For that I use this code in my app.js file:
$(document).on("mobileinit", function () {
$.mobile.linkBindingEnabled = false;
$.mobile.hashListeningEnabled = false;
$(document).on('pagehide', 'div[data-role="page"]', function (event, ui) {
$(event.currentTarget).remove();
});
})
Router.js
define([
'jquery',
'backbone',
'views/projects/ProjectsView',
'views/projects/AddProjectView'
], function($, Backbone, ProjectsView, AddProjectView) {
return Backbone.Router.extend({
routes: {
'addProject': 'addProject',
'editProject/:projectId': 'editProject',
'*actions': 'showProjects' // Default
},
addProject: function() {
new AddProjectView().render();
},
editProject: function(projectId) {
require([
"views/projects/EditProjectView",
"collections/ProjectsCollection",
"models/ProjectModel"
], function (EditProjectView, ProjectsCollection, ProjectModel) {
var projectsCollection = new ProjectsCollection();
projectsCollection.fetch();
var project = projectsCollection.get(projectId);
if (project) {
var view = new EditProjectView({model: project, projectsCollection: projectsCollection});
view.render();
}
});
},
showProjects: function() {
new ProjectsView().navigate();
}
});
});
I've uploaded my code to a directory on my website: http://rickdoorakkers.nl/np2
If you go through the following steps, you'll see the problem:
Add a project
Add a second project with a different name
Open a project by clicking on it and change the values and save it
As you can see the event of adding a project is launched and there's a project added instead of changed.
This same problem also occurs when you try to change 2 projects after each other. The first project is edited then.
Is there somebody who can tell me what I'm doing wrong?
Thanks!
Rido, your code is really hard to read for me because of the way it's mixing together a few things and not following any of the usual conventions for Backbone.
For your specific problem, I have a feeling the problem is that you binding both the Edit view and the New view to body (el: body), both respond to the event submit, and you are never clearly cleaning up the views, so I think that whenever you add a project and then edit it, the add view is still in memory, still bound to the submit event and still answering the call = new project with the new name, instead of editing.
It's 'easy' to fix in a dirty way, by adding a call to stopListening after adding, but the real problem is that you are binding to body, and mixing togethers the Backbone Router and manual hash control + other weird patterns, such as fetching the collection every 5 lines (you could just create one at the start of the App and always use it! here it's localstorage so it doesn't matter but if you ever move to a remote storage, you'll regret it... fetch() reset the collection and do a full reload!). May I suggest you maybe try to rewrite this without caring about jQuery mobile and just try to make it work with Backbone.Router + a single collection + not binding to body but instead, create the views on the fly and append them to body / remove when you are done? You'll see the bugs will be less weird and easier to track.

Categories

Resources