electron_window 創建窗口


/**
 * 窗口基類,封裝通用的窗口操作
 */

const { BrowserWindow } = require('electron');

/**
 * 基本窗口樣式
 * @type {{width: number, height: number, resizable: boolean, frame: boolean, parent: object, modal: boolean}}
 */
const windowStyle = {
    title: '雲', // 窗口標題
    width: 800, // 寬
    height: 600, // 高
    resizable: true, // 窗口大小是否可變
 //   frame: false, // 是否帶邊框
    parent: null, // 父窗口
    modal: false, // 是否模態窗口
    show: false, // 是否顯示窗口
};

/**
 * 窗口類,繼承electron的BrowserWindow
 * @extends BrowserWindow
 */
class EucWindow extends BrowserWindow {
    /**
     * 窗口類,繼承electron的BrowserWindow
     * @param style 窗口樣式
     * @param url
     * @param win
     */
    constructor(style, url, win) {
        const myStyle = Object.assign({}, windowStyle, style);
        super(myStyle);

        win = this;

        // 阻止跳轉鏈接
        this.webContents.on( 'will-navigate', (event)=>{
            event.preventDefault();
        });

        win.webContents.openDevTools({detach:true});

        // 加載網頁
        this.loadURL(url);

        this.on('closed', function() {
            win = null;
        });

    }

}

module.exports = EucWindow;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM