Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Electron: How to minimize a window from a rendered process

Scenario

I have a window and it has an add task button that is opening a window. Everytime user clicks on it, it opens a window. I have a button on add task window that minimize it. How to implement this minimize button?

Code

I am able to close maximize window by using the code below:

var winclose = function () {
    window.close();
}

var winmaximize = function () {
    window.moveTo(0, 0);
    window.resizeTo(screen.width, screen.height);
}

However, I am not able to find any function that can minimize a window from rendered process.

Please help, many thanks;

Note:

Browsers do not provide a function to devs to minimize them. but here is a different scenario. Here I am using chromium provided by Electronjs. So, there must be a way to do so as we are developing a desktop application

Dummy Download link: download from OneDrive

like image 951
Vikas Bansal Avatar asked Jun 08 '16 07:06

Vikas Bansal


People also ask

How do you close the Electron window?

addEventListener("click", function (e) { var window = remote. getCurrentWindow(); window. close(); });

How do you drag a frameless window in an Electron?

By default, the frameless window is non-draggable. Applications need to specify the -webkit-app-region: drag CSS property to tell Electron which regions are draggable. To make the whole window draggable, this CSS property is set to the style of the body tag in HTML.

How do you make an Electron fullscreen?

To make an Electron app run in full-screen mode when it's started, pass the following configuration option when creating the BrowserWindow instance: mainWindow = new BrowserWindow({fullscreen: true});


1 Answers

You can call minimize() on the respective BrowserWindow instance. The question is how to best get access to this instance and this, in turn, depends on how you open the windows and where your minimize button is. From your example, I take it that the minimize button is actually in the window you want to close, in that case you can just minimize the focused window, because to when a user clicks the button inside it, the window should currently have the focus:

const { remote } = require('electron')
remote.BrowserWindow.getFocusedWindow().minimize();

Alternatively you can use BrowserWindow.fromId() to get access to the window in question if, for example, you want to minimize the task window from the other window.

like image 146
inukshuk Avatar answered Oct 27 '22 01:10

inukshuk