I'm seeing a strange behavior with my simple NativeScript / Typescript app. In the app.ts i launch the application like so:
app.start({ moduleName: "pages/home/home-page" });
but debug break points in home-page.ts in the loaded and navigatingTo event handlers don't stop execution. however when in the app i click on the Home page link the events are fired and the break points are stopped. So it looks like the app.start call does not fire page lifecycle events at all.
Seems like a strange behavior. Any ides?
It appears that the application is being executed too fast and the debugger doesn't have time to attach. To fix this problem in the launch.json (debugger configuration in VSC) set
"stopOnEntry": true
This will stop the application on the first line and allow time for the debugger to attach.
Related
I have an Electron app, running on Windows, it has a few controls on the main window and a cancel button. I notice when it is running I see two threads, I assume the main and renderer threads. When the cancel button is clicked the renderer sends an IPC message to the main thread and the main thread calls app.quit. Under these conditions the two threads end. If I right click on the icon in the Windows taskbar for the app and select "Close" the threads only end when the app is run under the VSCode debugger, when the app is run without the debugger and the same is done the two threads remain.
How can I debug this? Any suggestions as to why it is happening.
Under the debugger I see the close being caught in the main thread and app.quit is called.
UPDATE: Since the app used Electron 1.7.9 I have updated it to use 2.0.8 just in case this was an issue that had been addressed. However, with 2.0.8 the issue remains.
Sid
Thanks to some input from the Electron Slack community I have resolved this issue. My mistake was in the way I was calling the app.quit() method.
My code was handling the MainWindow on "close" event and executing the app.quit() method in that event handler.
The correct way to close the app is to handle the app "window-all-closed" event and execute the app.quit() method there.
Here is a gist of a skeleton main.js for an Electron app that was sent to me to help me resolve the issue.
https://gist.github.com/sidprice/612cb49cec923eeb94cfcddf1736c181
Sid
I have a button which posts back through Ajax. I tried to find out what code executes when the button is clicked. I used Visual Event (screen capture below) to see how the event was bound but the info didn't help me enough. Then I set an event listener breakpoint on mouse clicks in Chrome. The breakpoint hit code in the main jQuery file which was also not helpful. So I blackboxed the file. Now when I click the button, no breakpoints are hit.
What's a systematic way to find the user code which gets executed? I also searched for 'live' and 'click' as text across the whole app. It was time consuming and didn't find where the click event for the button got attached. It's painful to do such a search. I would like to know the productive technique using Chrome's debugger or another tool. (Another browser's tips are OK)
Have you tried the Chrome profiler?
Launch the Chrome DevTools (F12)
Go to the Profiles panel
Ensure that Collect JavaScript CPU Profile is selected
Click Start
Perform your operation
Click Stop.
Then you should see a list of functions that were called.
There are several possible ways to do so. One is described by the user thesentiment. Another way is to use the DevTools' debugger.
Open the Chrome DevTools (F12)
Switch to the Sources panel
Click the Pause button () or hit F8
Perform your operation
=> The script execution will stop at the first line of the event handler function within jQuery. You can then step through to your actual event handling function.
Note that in Firebug this works much easier, because its Events side panel already displays the wrapped listeners, i.e. the functions that are called by a jQuery event listener:
I am trying to prevent the user from closing the window when they click on the close button. I would like to have the application dock to the system tray.
My first step is to recognize when the user attempts to close the window and prevent the default behavior on that event. I would expect this code to work, but it does not.
var appWindow = Titanium.UI.getCurrentWindow();
appWindow.addEventListener('app.exit', function(event){
event.preventDefault();
})
I tried using the exit event and the event constants themselves to no avail.
This wont work because all your doing when you call preventDefault is stopping the default behavior in the WebKit browser page, not the native application wrapper itself.
The close command is a native function call to the underlying wrapper, it just passes an event to the listener, it does not pass control.
Also, this sounds somewhat dangerous, not allowing a user to close an application seems problematic. Maybe instead you should register a background service to run instead?
one trick might be to open an 'invisible' window for the app, so even if the user closes the 'application' window, the app should still be running.
I am facing some issues in WP7 tombstoning. My issue is application hangs when i try for a sudden tombstone and come back. ie, After loading the page i press device menu button and with in seconds i pressed back button( Pressed Back button before the actual page disappeared) In that time the page loads but the application hangs / its back key press is not working. and if we try for a slow thombstone it is working perfectly. And the pretty interesting thing is that, while tombstoning the loaded and unloaded events of APP working perfectly. Please any one help me to solve this issue.
It sounds like your App has been deactivated, but not tombstoned. This results in neither the App or Page contrusctor being called, causing your app to act in unexpected ways. I highly recommend reading the Windows Phone Silverlight Application Life Cycle document. The relevant extract for said article:
This case can occur if the user
presses the Start and Back buttons on
the phone in quick succession. In this
case, the application received a
Deactivate event and the system was
starting to save the state of the
application to perform an application
tombstone. Before this operation is
completed, the app Activated event is
received. The system knows that the
application was not removed from
memory, so the flow of execution is
different. Specifically:
• The app constructor is not called.
• The page constructor is not called.
The only way for the application to determine
if this condition has occurred is to
set a flag to indicate if the page
constructor has been called. If you
notice in the above section, this flag
was set in the page constructor, and
cleared in the OnNavigateFrom event.
In this case, we will receive the
OnNavigatedTo event, but we will see
that the page constructor was not
called. This tells us that our
application was not tombstoned.
I'm seeing some unexpected things happening in the emulator.
When debugging and starting the app for the first time, the Application_Launching fires just fine. When clicking the start button, the Application_Deactivated event fires fine. When click the back button, the Application_Activated event fires fine.
If I click the start button then go to my apps and launch my app, no events are fired. I would assume either the Application_Launching or Application_Activated would fire when the app is launched every time, just a different event depending on how the app got there.
Is this an issue with the emulator or do I have the wrong assumptions here?
Well, the events get fired right. What you missed is that debugger get dettached when you are launching "new instance" of your app. ;)