Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

javascript - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...