电子修改选项,无需重新创建窗口

时间:2017-12-28 23:49:48

标签: javascript node.js electron electron-window

我的申请存在问题。我创建了一个漂亮的登录窗口,这是一个带有选项 {transparent:true,frame:false}的窗口。

用户登录后。我想“重定向”到仪表板,我需要将选项“透明”设置为假,因为仪表板的背景是白色的,我只能将打印的字体放在完全透明的窗户。

是否有任何解决方法可以让Electronwindow在没有重新创建的情况下恢复透明。

app.js:

const electron = require('electron');
const { BrowserWindow } = electron;
const { app } = electron;
const window = require('electron-window');

const { MainProcess } = require("./modules/ipcHelper.js");

const io = require('socket.io-client');
const port = 8888;
let socket;

require('electron-reload')(__dirname)

let mainWindow;

app.on('ready', () => {
    mainWindow = window.createWindow({
        width: 835,
        height: 750,
        frame: false,
        transparent: true,
    });

  let testwindow = new BrowserWindow({
        width: 835,
        height: 750,
        frame: false,
        transparent: true,
    });

    mainWindow.showUrl(`./app/index.html`, () => {

    });

    let mainProcess = MainProcess(mainWindow);

    mainProcess.onReady(() => {
        mainProcess.on('auth', (arg, callback) => {
            socket = io('http://' + arg.servername + ':' + port);

            socket.on("connect", () => {
                socket.emit('auth', { username: arg.username, password: arg.password }, (response) => {
                    if (response.success === true){
                        callback({ success: true });
                    //Here i want to set transparenty back to false
                    }
                    else
                        callback({ success: false, code: response.code });
                });
            });

            socket.on("connect_error",() => {
                callback({ success: false, code: 3 });
            });


        });
    });
})

1 个答案:

答案 0 :(得分:1)

BrowserWindow有一堆方法可以用来动态更改属性。我认为您正在寻找的是win.setOpacity()

https://github.com/electron/electron/blob/master/docs/api/browser-window.md#winsetopacityopacity-windows-macos

如果您在渲染器过程中执行此操作,则必须使用remote

访问它

https://github.com/electron/electron/blob/master/docs/api/remote.md