Files
electron-egg/electron/service/os.js
gaoshuaixing 176526dbe0 销毁视图
2023-06-19 14:24:49 +08:00

77 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict';
const { Service } = require('ee-core');
const { BrowserView, Notification } = require('electron');
const CoreWindow = require('ee-core/electron/window');
/**
* osservice层为单例
* @class
*/
class OsService extends Service {
constructor(ctx) {
super(ctx);
this.myBrowserView = null;
this.myNotification = null;
}
/**
* createBrowserView
*/
createBrowserView(contentUrl) {
// electron 实验性功能,慎用
const win = CoreWindow.getMainWindow();
this.myBrowserView = new BrowserView();
win.setBrowserView(this.myBrowserView);
this.myBrowserView.setBounds({
x: 300,
y: 170,
width: 650,
height: 400
});
this.myBrowserView.webContents.loadURL(contentUrl);
}
/**
* removeBrowserView
*/
removeBrowserView() {
this.myBrowserView.webContents.destroy();
}
/**
* createNotification
*/
createNotification(options, event) {
const channel = 'controller.os.sendNotification';
this.myNotification = new Notification(options);
if (options.clickEvent) {
this.myNotification.on('click', (e) => {
let data = {
type: 'click',
msg: '您点击了通知消息'
}
event.reply(`${channel}`, data)
});
}
if (options.closeEvent) {
this.myNotification.on('close', (e) => {
let data = {
type: 'close',
msg: '您关闭了通知消息'
}
event.reply(`${channel}`, data)
});
}
this.myNotification.show();
}
}
OsService.toString = () => '[class OsService]';
module.exports = OsService;