How to prevent more than once instance of chrome app being open at a time? - google-chrome-app

I just discovered I can launch more than one instance of my first chrome app at a time. And they stack directly on top of one another, which does not make it immediately detectable. Is there some kind of flag or lock file I can look for on startup?

If you give your app window an ID the system will only ever create one of it. The next time the window is 'created' the system will focus the existing window. Check out the CreateWindowOptions.id field for more info.

Related

How can I close a property window in an application developed with RCP?

I'm having a bit of a trouble modifying an application that I have inherited from another party. The application is a Front End made with Eclipse RCP, and I have to modify one of its property windows so when I click a Save button it will not just save the data to my database, but also close that property window.
I can't find a way to reference the window itself so I can invoke a method like "window.close();", would anyone have a hint by any chance?
Thank you.

How to find out which function is cased hang on main thread

Is there any way to easy to debug out what cause my hang on main thread?
when I debug without enable the breakpoint, there's a moment that the tableView will hang for a while, but how to found what cause that?
EDIT
I have upload the thread status when the app is hang, and I click the Pause button. show bellow:
EDIT I have upload the Profile of Instruments, which selected duration is which the screen is hang.
Edit
I have create a root problem question about this.Image download and save to file, Image read from file will cause lock?
You can use Instruments for that. Choose Product / Profile. Choose Time Profiler. Start profiling by pressing Record (the red circle). When the table view hangs, you'll most likely see a change in the graph. Select the region on the graph corresponding to the time when the table view hanged, and see what's being done on the main thread. You can find more info on Instruments on the web.
Another option is to start normal debugging, and then press "Pause" right when the tableView hangs. And then look at the stack trace for the main thread.

How do I verify that a window is the topmost window using UIAutomation?

I've searched for solutions in many forums but they all tell me that usign the WindowPattern and checkign the topmost value should return true if the window is on top. However, this isn't the case for me. I am testing an application that is housed within a tab in outlok. A user can then click within the application and open a new window. I'd like to verify this window is in the foreground. Also.. this is a WPF application so I cant grab separate handles for new windows that open.
thanks
This might be a terminology problem: 'Topmost' has a special meaning in Win32 (See description of WS_EX_TOPMOST here), which basically means "floats above other ordinary windows" - it's typically used for things like tooltips, menu popups, notification balloons and the like, which float above all other windows on the screen. It's rarely by actual application windows.
An application can be the currently foreground window, above other windows, but not have this property.
An alternate approach to see if the window is in the foreground is to see if it is or contains the contains the current focus or active window.

Restarting an app in Eclipse

Is there any way to restart a program in Eclipse? (preferably 1-click)
I really wish the console view had something like a restart button that would kill the app and restart it with the latest changes.
This always takes me at least three clicks. I click the down arrow next to the green circle with white triangle (play button) to open the dropdown menu, then I click to choose the Java main that I want to run, and then to stop I click the red square terminate button in the console view. Is there any easier way to do this that requires fewer clicks?
In Eclipse 4.1
open:
windows->Preferences->keys
in the filter text type: terminate and relaunch
In the binding add your binding (i use shift-F5)
For "when" select "In Windows"
This will do it in single shorcut for you.
Or install relaunch plugin:
https://bitbucket.org/mantis78/relaunch-plugin/wiki/Home
which will enable you to restart anywhere
If you use "build automatically", there is a good chance that your changes are applied on the running program, on the fly. As such, most changes will be effective directly without a need to restart.
If there is a structural difference and Eclipse can't inject the new code (for example if you change anonymous classes, or inheritance patterns), then you will be prompted with a dialog inviting you to restart the application in one click:
Exceptions are when you change the value of a static variable (or of the initialization of a class that won't be executed again until you restart the application). In this case indeed, you will need to restart explicitly with another method.
the console view has a terminate button (a red square) which stops the execution. then another click on the Run button (the green circle with triangle) begins execution again.
thats what i do - 2 clicks :)
If you're using Eclipse with Spring you could download the "Spring Tools X" plugin.
This will automatically add a start and relaunch button to the top bar menu.
It should be available on any perspective.
I haven't found an elegant solution for this problem, but if your program is short running and you can live with a few instances here and there, you can just use the run command. Its default shortcut is Ctrl+F11. Every time you press this, your application will restart. BUT! If you press this while your application is still running, another instance will be run because the "old" instance won't be automatically terminated.
There are ways to really terminate your application using shortcut keys, but that requires setting breakpoints and then using the "terminate" command, and that isn't very elegant.
When developing my own network application, I have added a code to check if the older instance is running, and if so, then send an agreed command over network socket for graceful shutdown. While this approach may not be the best as universal solution, it allows clean shutdown of the previous instance, rather than just killing it.
Easy way without plugin, every Eclipse !
Click the project from of this icon at this time hold the shift Button, Project will restart (Terminate and relaunch) with server port also.

What determines the monitor my app runs on?

I am using Windows, and I have two monitors.
Some applications will always start on my primary monitor, no matter where they were when I closed them.
Others will always start on the secondary monitor, no matter where they were when I closed them.
Is there a registry setting buried somewhere, which I can manipulate to control which monitor applications launch into by default?
#rp: I have Ultramon, and I agree that it is indispensable, to the point that Microsoft should buy it and incorporate it into their OS. But as you said, it doesn't let you control the default monitor a program launches into.
Here's what I've found. If you want an app to open on your secondary monitor by default do the following:
1. Open the application.
2. Re-size the window so that it is not maximized or minimized.
3. Move the window to the monitor you want it to open on by default.
4. Close the application. Do not re-size prior to closing.
5. Open the application.
It should open on the monitor you just moved it to and closed it on.
6. Maximize the window.
The application will now open on this monitor by default. If you want to change it to another monitor, just follow steps 1-6 again.
Correctly written Windows apps that want to save their location from run to run will save the results of GetWindowPlacement() before shutting down, then use SetWindowPlacement() on startup to restore their position.
Frequently, apps will store the results of GetWindowPlacement() in the registry as a REG_BINARY for easy use.
The WINDOWPLACEMENTroute has many advantages over other methods:
Handles the case where the screen resolution changed since the last run: SetWindowPlacement() will automatically ensure that the window is not entirely offscreen
Saves the state (minimized/maximized) but also saves the restored (normal) size and position
Handles desktop metrics correctly, compensating for the taskbar position, etc. (i.e. uses "workspace coordinates" instead of "screen coordinates" -- techniques that rely on saving screen coordinates may suffer from the "walking windows" problem where a window will always appear a little lower each time if the user has a toolbar at the top of the screen).
Finally, programs that handle window restoration properly will take into account the nCmdShow parameter passed in from the shell. This parameter is set in the shortcut that launches the application (Normal, Minimized, Maximize):
if(nCmdShow != SW_SHOWNORMAL)
placement.showCmd = nCmdShow; //allow shortcut to override
For non-Win32 applications, it's important to be sure that the method you're using to save/restore window position eventually uses the same underlying call, otherwise (like Java Swing's setBounds()/getBounds() problem) you'll end up writing a lot of extra code to re-implement functionality that's already there in the WINDOWPLACEMENT functions.
It's not exactly the answer to this question but I dealt with this problem with the Shift + Win + [left,right] arrow keys shortcut. You can move the currently active window to another monitor with it.
Get UltraMon. Quickly.
http://realtimesoft.com/ultramon/
It doesn't let you specify what monitor an app starts on, but it lets you move an app to the another monitor, and keep its aspect ratio intact, with one mouse click. It is a very handy utility.
Most programs will start where you last left them. So if you have two monitors at work, but only one at home, it's possible to start you laptop at home and not see the apps running on the other monitor (which now isn't there). UltrMon also lets you move those orphan apps back to the main screen quickly and easily.
I'm fairly sure the primary monitor is the default. If the app was coded decently, when it's closed, it'll remember where it was last at and will reopen there, but -- as you've noticed -- it isn't a default behavior.
EDIT: The way I usually do it is to have the location stored in the app's settings. On load, if there is no value for them, it defaults to the center of the screen. On closing of the form, it records its position. That way, whenever it opens, it's where it was last. I don't know of a simple way to tell it to launch onto the second monitor the first time automatically, however.
-- Kevin Fairchild
Important note: If you remember the position of your application and shutdown and then start up again at that position, keep in mind that the user's monitor configuration may have changed while your application was closed.
Laptop users, for example, frequently change their display configuration. When docked there may be a 2nd monitor that disappears when undocked. If the user closes an application that was running on the 2nd monitor and the re-opens the application when the monitor is disconnected, restoring the window to the previous coordinates will leave it completely off-screen.
To figure out how big the display really is, check out GetSystemMetrics.
So I had this issue with Adobe Reader 9.0. Somehow the program forgot to open on my right monitor and was consistently opening on my left monitor. Most programs allow you to drag it over, maximize the screen, and then close it out and it will remember. Well, with Adobe, I had to drag it over and then close it before maximizing it, in order for Windows to remember which screen to open it in next time. Once you set it to the correct monitor, then you can maximize it. I think this is stupid, since almost all windows programs remember it automatically without try to rig a way for XP to remember.
So I agree there are some apps that you can configured to open on one screen by maximizing or right clicking and moving/sizing screen, then close and reopen. However, there are others that will only open on the main screen.
What I've done to resolve: set the monitor you prefer stubborn apps to open on, as monitor 1 and the your other monitor as 2, then change your monitor 2 to be the primary - so your desktop settings and start bar remain. Hope this helps.
Do not hold me to this but I am pretty sure it depends on the application it self. I know many always open on the main monitor, some will reopen to the same monitor they were previously run in, and some you can set. I know for example I have shortcuts to open command windows to particular directories, and each has an option in their properties to the location to open the window in. While Outlook just remembers and opens in the last screen it was open in. Then other apps open in what ever window the current focus is in.
So I am not sure there is a way to tell every program where to open. Hope that helps some.
I've noticed that if I put a shortcut on my desktop on one screen the launched application may appear on that screen (if that app doesn't reposition itself).
This also applies to running things from Windows Explorer - if Explorer is on one screen the launched application will pick that monitor to use.
Again - I think this is when the launching application specifies the default (windows managed) position. Most applications seem to override this default behavior in some way.
A simple window created like so will do this:
hWnd = CreateWindow(windowClass, windowTitle, WS_VISIBLE | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, SW_SHOW, CW_USEDEFAULT, 0, NULL, NULL, hInst, NULL);
Right click the shortcut and select properties.
Make sure you are on the "Shortcut" Tab.
Select the RUN drop down box and change it to Maximized.
This may assist in launching the program in full screen on the primary monitor.