Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow window resizing down to 800x600 #502

Merged
merged 1 commit into from
Mar 16, 2021

Conversation

ctzsnooze
Copy link
Member

This PR is a quick and dirty one that allows re-sizing of Blackbox windows down to 800x600, so that I can easily view multiple log windows at once. Currently they cannot be made any smaller than 134x900.

I'm sure this is not the most elegant solution, but it works. I targeted all the instances of 1340x900 I could find :-)

The chrome.background.js file may not be required, I don't know what it does.

The behaviour isn't ideal on my Mac. The initial window on launching BBE opens fairly large, but all new windows (after clicking the 'new window' button are 800x600, centred. They don't need to be that small on opening, could open the same size as the initial window, that would be fine.

I don't mind if windows open at 1340x900, I just wanted to be able to drag them to a smaller size; 800x600 allows quite a few windows open at once on a good screen, making it easy to compare multiple files at once.

Thanks!

PS: the window size changes may have been initiated in #450

chromeBackground.js Outdated Show resolved Hide resolved
js/main.js Outdated
const INNER_BOUNDS_WIDTH = 1340;
const INNER_BOUNDS_HEIGHT = 900;
const INNER_BOUNDS_WIDTH = 800;
const INNER_BOUNDS_HEIGHT = 600;
Copy link
Member

@McGiverGim McGiverGim Mar 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add more parameters here.

They are used here:

gui.Window.open(INITIAL_APP_PAGE,
{
'min_width' : INNER_BOUNDS_WIDTH,
'min_height' : INNER_BOUNDS_HEIGHT,
},

And the parameters accepted are here: https://docs.nwjs.io/en/latest/References/Manifest%20Format/#window-subfields

The most important is id, if we pass it, it will remember the latest position/size in theory, and it will use it for the new window.

We have one "id": "main" for the main window, but this, that are for additional windows, maybe we must have one id for them.

Something like :

const ID_SECONDARY_WINDOW = 'ID_SECONDARY_WINDOW';
...
 gui.Window.open(INITIAL_APP_PAGE, 
 {  
     'id' : ID_SECONDARY_WINDOW,
     'min_width'  : INNER_BOUNDS_WIDTH, 
     'min_height' : INNER_BOUNDS_HEIGHT, 
 }, 

I think a better solution will be to add a number to the id, like:

  • 'ID_ SECONDARY_WINDOW_1'
  • 'ID_ SECONDARY_WINDOW_2'
  • 'ID_ SECONDARY_WINDOW_3'
  • ...

In this way it will remember various secondary windows positions and size, and they will be always the same if we open more than 1. But maybe we can let this for a future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the Chrome window, if we use the same ID for all maybe it simply focuses the window created: https://developer.chrome.com/docs/extensions/reference/app_window/#type-CreateWindowOptions

So maybe we need to go to the _1, _2, _3 version. If you can test it we can know more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback ... I have no clue about JS or windows but will try :-)

Copy link
Member Author

@ctzsnooze ctzsnooze Mar 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a width and height that operates on opening a secondary window.
This is working really well.
After starting the app, the initial window opens at the same location and size as on the last run of the app. It can be resized down to 800x560. This is good.
With the secondary window code, when a secondary window is opened, it opens at the position of the most recent (previous) secondary window at 1000x760px. It also can be resized as small as 800x560. If it is closed, a new secondary window opens at the location of the previous secondary window. This too is good.
The only problem is that we can only create one single secondary window.
So I commented that out.
With it commented out, all secondary windows open centred at 1000x760, which is quite OK I think.
So either we put code with IDs 1_, 2_, 3_ for secondary windows, or keep it simple and have each open in the centre.
I think its OK opening secondary windows in centre, as now, and the code is simpler :-) So I'm happy with it working as it is now. If you're OK I can remove the secondary window code, which is commented out.

@ctzsnooze ctzsnooze force-pushed the smaller_window branch 2 times, most recently from b88e463 to 472af72 Compare March 15, 2021 22:58
@ctzsnooze
Copy link
Member Author

ctzsnooze commented Mar 15, 2021

I think the code now solves the issues that concerned me.
The behaviour seems good.
All windows can be resized very small, but not too small.
New secondary windows open in the centre of the screen at a reasonable size.

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
4.7% 4.7% Duplication

Copy link
Member

@McGiverGim McGiverGim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to have an ID with _1, _2, etc. but your code is not worse than previous one, so to me is ok.

@ctzsnooze
Copy link
Member Author

I would be happy with ID _1, _2 also... if you could demonstrate exactly the code required to do it, I will test it out.

@McGiverGim
Copy link
Member

The best solution will be to remember "the latest" width an height of a window. Catching the "onclose" event and write it to the storage of the app. But to simplify the _1, _2, _3 solution I think will be enough.

If you want to try it, to implement, simply declare a "windowCounter" variable, with value 0, at the top of the file:

const WINDOW_ID = 'SECONDARY';
let windowCounter = 0;

Then, increment it at each call:

            gui.Window.open(INITIAL_APP_PAGE,
            {
                'id' : `${WINDOW_ID}_${windowCounter++}`,
                'width'  : NEW_WINDOW_WIDTH,
                'height' : NEW_WINDOW_HEIGHT,
                'min_width'  : INNER_BOUNDS_WIDTH,
                'min_height' : INNER_BOUNDS_HEIGHT,
            },

I think this will work.

@mikeller mikeller added this to the 3.6.0 milestone Mar 16, 2021
@mikeller mikeller merged commit 1535f3f into betaflight:master Mar 16, 2021
@ctzsnooze ctzsnooze deleted the smaller_window branch September 3, 2021 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants