哆啦好梦 2 年之前
父节点
当前提交
0e454ce70b

+ 16 - 0
electron/controller/effect.js

@@ -1,6 +1,8 @@
 'use strict';
 
 const { Controller } = require('ee-core');
+const { dialog } = require('electron');
+const _ = require('lodash');
 
 /**
  * 特效 - 功能demo
@@ -12,6 +14,20 @@ class EffectController extends Controller {
     super(ctx);
   }
 
+  /**
+   * 选择文件
+   */
+  selectFile () {
+    const filePaths = dialog.showOpenDialogSync({
+      properties: ['openFile']
+    });
+
+    if (_.isEmpty(filePaths)) {
+      return null
+    }
+
+    return filePaths[0];
+  }  
 }
 
 EffectController.toString = () => '[class EffectController]';

+ 16 - 38
electron/controller/framework.js

@@ -9,8 +9,7 @@ const dayjs = require('dayjs');
 const Ps = require('ee-core/ps');
 const Log = require('ee-core/log');
 const Utils = require('ee-core/utils');
-
-let myTimer = null;
+const Conf = require('ee-core/config');
 
 /**
  * electron-egg framework - 功能demo
@@ -32,7 +31,7 @@ class FrameworkController extends Controller {
    * test
    */
   async test() {
-    const result = await this.service.example.test('electron');
+    const result = await this.service.framework.test('electron');
 
     // let tmpDir = Ps.getLogDir();
     // Log.info('tmpDir:', tmpDir);
@@ -164,7 +163,7 @@ class FrameworkController extends Controller {
    * 检测http服务是否开启
    */ 
   async checkHttpServer() {
-    const httpServerConfig = this.app.config.httpServer;
+    const httpServerConfig = Conf.getValue('httpServer');
     const url = httpServerConfig.protocol + httpServerConfig.host + ':' + httpServerConfig.port;
 
     const data = {
@@ -217,8 +216,6 @@ class FrameworkController extends Controller {
   
   /**
    * 异步消息类型
-   * @param args 前端传的参数
-   * @param event - IpcMainInvokeEvent 文档:https://www.electronjs.org/zh/docs/latest/api/structures/ipc-main-invoke-event
    */ 
    async ipcInvokeMsg(args, event) {
     let timeNow = dayjs().format('YYYY-MM-DD HH:mm:ss');
@@ -229,8 +226,6 @@ class FrameworkController extends Controller {
 
   /**
    * 同步消息类型
-   * @param args 前端传的参数
-   * @param event - IpcMainEvent 文档:https://www.electronjs.org/docs/latest/api/structures/ipc-main-event
    */ 
   async ipcSendSyncMsg(args) {
     let timeNow = dayjs().format('YYYY-MM-DD HH:mm:ss');
@@ -241,29 +236,12 @@ class FrameworkController extends Controller {
 
   /**
    * 双向异步通信
-   * @param args 前端传的参数
-   * @param event - IpcMainEvent 文档:https://www.electronjs.org/docs/latest/api/structures/ipc-main-event
    */
-  ipcSendMsg(args, event) {
-    // 前端ipc频道 channel
-    const channel = 'controller.example.ipcSendMsg';
-
-    if (args.type == 'start') {
-      // 每隔1秒,向前端页面发送消息
-      // 用定时器模拟
-      myTimer = setInterval(function(e, c, msg) {
-        let timeNow = Date.now();
-        let data = msg + ':' + timeNow;
-        e.reply(`${c}`, data)
-      }, 1000, event, channel, args.content)
-
-      return '开始了'
-    } else if (args.type == 'end') {
-      clearInterval(myTimer);
-      return '停止了'    
-    } else {
-      return 'ohther'
-    }
+  async ipcSendMsg(args, event) {
+    const { type, content } = args;
+    const data = await this.service.framework.bothWayMessage(type, content, event);
+
+    return data;
   }
 
   /**
@@ -282,7 +260,7 @@ class FrameworkController extends Controller {
       await fs.unlink(file.filepath, function(){});
     }
     const fileStream = fs.createReadStream(tmpFilePath);
-    const uploadRes = await this.service.example.uploadFileToSMMS(fileStream);
+    const uploadRes = await this.service.framework.uploadFileToSMMS(fileStream);
 
     return uploadRes;
   }
@@ -296,7 +274,7 @@ class FrameworkController extends Controller {
       msg: '',
       server: ''
     }
-    const javaCfg = this.app.config.addons.javaServer || {};
+    const javaCfg = Conf.getValue('addons.javaServer') || {};
     if (!javaCfg.enable) {
       data.code = -1;
       data.msg = 'addon not enabled!';
@@ -319,7 +297,7 @@ class FrameworkController extends Controller {
       code: 0,
       msg: '',
     }
-    const javaCfg = this.app.config.addons.javaServer || {};
+    const javaCfg = Conf.getValue('addons.javaServer') || {};
     if (!javaCfg.enable) {
       data.code = -1;
       data.msg = 'addon not enabled!';
@@ -342,10 +320,10 @@ class FrameworkController extends Controller {
     let result;
     switch (action) {
       case 'create':
-        result = this.service.example.doJob(jobId, action, event);
+        result = this.service.framework.doJob(jobId, action, event);
         break;       
       case 'close':
-        this.service.example.doJob(jobId, action, event);
+        this.service.framework.doJob(jobId, action, event);
         break;
       default:  
     }
@@ -363,10 +341,10 @@ class FrameworkController extends Controller {
    */ 
   async createPool(args, event) {
     let num = args.number;
-    this.service.example.doCreatePool(num, event);
+    this.service.framework.doCreatePool(num, event);
 
     // test monitor
-    this.service.example.monitorJob();
+    this.service.framework.monitorJob();
 
     return;
   }
@@ -381,7 +359,7 @@ class FrameworkController extends Controller {
     let result;
     switch (action) {
       case 'run':
-        result = this.service.example.doJobByPool(jobId, action, event);
+        result = this.service.framework.doJobByPool(jobId, action, event);
         break;
       default:  
     }

+ 53 - 0
electron/controller/hardware.js

@@ -1,6 +1,9 @@
 'use strict';
 
 const { Controller } = require('ee-core');
+const path = require('path');
+const Ps = require('ee-core/ps');
+const { mainWindow } = require('ee-core/electron');
 
 /**
  * 硬件设备 - 功能demo
@@ -12,6 +15,56 @@ class HardwareController extends Controller {
     super(ctx);
   }
 
+  /**
+   * 获取打印机列表
+   */
+  getPrinterList () {
+
+    //主线程获取打印机列表
+    const list = mainWindow.webContents.getPrinters();
+
+    return list;
+  }  
+
+  /**
+   * 打印
+   */
+  print (args, event) {
+    const { view, deviceName } = args;
+    let content = null;
+    if (view.type == 'html') {
+      content = path.join('file://', Ps.getHomeDir(), view.content)
+    } else {
+      content = view.content;
+    }
+
+    const addonWindow = this.app.addon.window;
+    let opt = {
+      title: 'printer window',
+      x: 10,
+      y: 10,
+      width: 980, 
+      height: 650 
+    }
+    const name = 'window-printer';
+    const printWindow = addonWindow.create(name, opt);
+
+    printWindow.loadURL(content);
+    printWindow.webContents.once('did-finish-load', () => {
+      // 页面完全加载完成后,开始打印
+      printWindow.webContents.print({
+        silent: false, // 显示打印对话框
+        printBackground: true,
+        deviceName,
+      }, (success, failureReason) => {
+        const channel = 'controller.hardware.printStatus';
+        event.reply(`${channel}`, { success, failureReason });
+        printWindow.close();
+      });
+    });
+
+    return true;
+  }  
 }
 
 HardwareController.toString = () => '[class HardwareController]';

+ 44 - 75
electron/controller/os.js

@@ -4,13 +4,11 @@ const _ = require('lodash');
 const path = require('path');
 const { Controller } = require('ee-core');
 const {
-  app: electronApp,
-  dialog, shell, BrowserView, Notification, 
+  app: electronApp, dialog, shell, Notification, 
   powerMonitor, screen, nativeTheme
 } = require('electron');
-
-let browserViewObj = null;
-let notificationObj = null;
+const Conf = require('ee-core/config');
+const Ps = require('ee-core/ps');
 
 /**
  * 操作系统 - 功能demo
@@ -97,23 +95,14 @@ class OsController extends Controller {
    * 加载视图内容
    */
   loadViewContent (args) {
-    let content = null;
-    if (args.type == 'html') {
-      content = path.join('file://', electronApp.getAppPath(), args.content)
-    } else {
-      content = args.content;
+    const { type, content } = args;
+    let contentUrl = content;
+    if (type == 'html') {
+      contentUrl = path.join('file://', electronApp.getAppPath(), content);
     }
 
-    // electron实验性功能,慎用
-    browserViewObj = new BrowserView();
-    this.app.electron.mainWindow.setBrowserView(browserViewObj)
-    browserViewObj.setBounds({
-      x: 300,
-      y: 170,
-      width: 650,
-      height: 400
-    });
-    browserViewObj.webContents.loadURL(content);
+    this.service.os.createBrowserView(contentUrl);
+
     return true
   }
 
@@ -121,8 +110,9 @@ class OsController extends Controller {
    * 移除视图内容
    */
   removeViewContent () {
-    // removeBrowserView移除视图后,进程依然存在,估计是electron bug
-    this.app.electron.mainWindow.removeBrowserView(browserViewObj);
+   
+    this.service.os.removeBrowserView();
+
     return true
   }  
 
@@ -130,35 +120,35 @@ class OsController extends Controller {
    * 打开新窗口
    */
   createWindow (args) {
-    let content = null;
-    if (args.type == 'html') {
-      content = path.join('file://', electronApp.getAppPath(), args.content)
-    } else if (args.type == 'web') {
-      content = args.content;
-    } else if (args.type == 'vue') {
+    const { type, content, windowName, windowTitle } = args;
+    let contentUrl = null;
+    if (type == 'html') {
+      contentUrl = path.join('file://', electronApp.getAppPath(), content)
+    } else if (type == 'web') {
+      contentUrl = content;
+    } else if (type == 'vue') {
       let addr = 'http://localhost:8080'
-      if (this.config.env == 'prod') {
-        const mainServer = this.app.config.mainServer;
+      if (Ps.isProd()) {
+        const mainServer = Conf.getValue('mainServer');
         addr = mainServer.protocol + mainServer.host + ':' + mainServer.port;
       }
 
-      content = addr + args.content;
+      contentUrl = addr + content;
     } else {
       // some
     }
 
     const addonWindow = this.app.addon.window;
     let opt = {
-      title: args.windowName || 'new window'
+      title: windowTitle
     }
-    const name = args.windowName || 'window-1';
-    const win = addonWindow.create(name, opt);
+    const win = addonWindow.create(windowName, opt);
     const winContentsId = win.webContents.id;
 
     // load page
-    win.loadURL(content);
+    win.loadURL(contentUrl);
 
-    return winContentsId
+    return winContentsId;
   }
   
   /**
@@ -198,49 +188,28 @@ class OsController extends Controller {
   /**
    * 创建系统通知
    */
-  sendNotification (arg, event) {
-    const channel = 'controller.example.sendNotification';
+  sendNotification (args, event) {
+    const { title, subtitle, body, silent, clickEvent, closeEvent} = args;
+
     if (!Notification.isSupported()) {
       return '当前系统不支持通知';
     }
 
     let options = {};
-    if (!_.isEmpty(arg.title)) {
-      options.title = arg.title;
+    if (!_.isEmpty(title)) {
+      options.title = title;
     }
-    if (!_.isEmpty(arg.subtitle)) {
-      options.subtitle = arg.subtitle;
+    if (!_.isEmpty(subtitle)) {
+      options.subtitle = subtitle;
     }
-    if (!_.isEmpty(arg.body)) {
-      options.body = arg.body;
+    if (!_.isEmpty(body)) {
+      options.body = body;
     }
-    if (!_.isEmpty(arg.silent)) {
-      options.silent = arg.silent;
-    }
-
-    notificationObj = new Notification(options);
-
-    if (arg.clickEvent) {
-      notificationObj.on('click', (e) => {
-        let data = {
-          type: 'click',
-          msg: '您点击了通知消息'
-        }
-        event.reply(`${channel}`, data)
-      });
-    }
-
-    if (arg.closeEvent) {
-      notificationObj.on('close', (e) => {
-        let data = {
-          type: 'close',
-          msg: '您关闭了通知消息'
-        }
-        event.reply(`${channel}`, data)
-      });
+    if (!_.isEmpty(silent)) {
+      options.silent = silent;
     }
 
-    notificationObj.show();
+    this.service.os.createNotification(clickEvent, closeEvent, event);
 
     return true
   }  
@@ -248,8 +217,8 @@ class OsController extends Controller {
   /**
    * 电源监控
    */
-  initPowerMonitor (arg, event) {
-    const channel = 'controller.example.initPowerMonitor';
+  initPowerMonitor (args, event) {
+    const channel = 'controller.os.initPowerMonitor';
     powerMonitor.on('on-ac', (e) => {
       let data = {
         type: 'on-ac',
@@ -288,10 +257,10 @@ class OsController extends Controller {
   /**
    * 获取屏幕信息
    */
-  getScreen (arg) {
+  getScreen (args) {
     let data = [];
     let res = {};
-    if (arg == 0) {
+    if (args == 0) {
       let res = screen.getCursorScreenPoint();
       data = [
         {
@@ -306,10 +275,10 @@ class OsController extends Controller {
       
       return data;
     }
-    if (arg == 1) {
+    if (args == 1) {
       res = screen.getPrimaryDisplay();
     }
-    if (arg == 2) {
+    if (args == 2) {
       let resArr = screen.getAllDisplays();
       // 数组,只取一个吧
       res = resArr[0];

+ 0 - 154
electron/service/example.js

@@ -1,154 +0,0 @@
-'use strict';
-
-const { Service } = require('ee-core');
-const Log = require('ee-core/log');
-const { ChildJob, ChildPoolJob } = require('ee-core/jobs');
-
-/**
- * 示例服务(service层为单例)
- * @class
- */
-class ExampleService extends Service {
-
-  constructor(ctx) {
-    super(ctx);
-
-    // 在构造函数中初始化一些变量
-    this.myJob = new ChildJob();
-    this.myJobPool = new ChildPoolJob();
-    this.taskForJob = {};
-  }
-
-  /**
-   * test
-   */
-  async test(args) {
-    let obj = {
-      status:'ok',
-      params: args
-    }
-
-    return obj;
-  }
-
-  /**
-   * 执行任务
-   */ 
-  doJob(jobId, action, event) {
-    let res = {};
-    let oneTask;
-    const channel = 'controller.example.timerJobProgress';
-    if (action == 'create') {
-      // 执行任务及监听进度
-      const timerTask = this.myJob.exec('./jobs/example/timer', {jobId});
-      timerTask.emitter.on('job-timer-progress', (data) => {
-        Log.info('[main-process] timerTask, from TimerJob data:', data);
-        // 发送数据到渲染进程
-        event.sender.send(`${channel}`, data)
-      })
-    
-      // 执行任务及监听进度 异步
-      // myjob.execPromise('./jobs/example/timer', {jobId}).then(task => {
-      //   task.emitter.on('job-timer-progress', (data) => {
-      //     Log.info('[main-process] timerTask, from TimerJob data:', data);
-      //     // 发送数据到渲染进程
-      //     event.sender.send(`${channel}`, data)
-      //   })
-      // });
-
-      res.pid = timerTask.pid; 
-      this.taskForJob[jobId] = timerTask;
-    }
-    if (action == 'close') {
-      oneTask = this.taskForJob[jobId];
-      oneTask.kill();
-      event.sender.send(`${channel}`, {jobId, number:0, pid:0});
-    }    
-
-    return res;
-  }
-
-  /**
-   * 创建pool
-   */ 
-  doCreatePool(num, event) {
-    const channel = 'controller.example.createPoolNotice';
-    this.myJobPool.create(num).then(pids => {
-      event.reply(`${channel}`, pids);
-    });
-  }
-
-  /**
-   * 通过进程池执行任务
-   */ 
-  doJobByPool(jobId, action, event) {
-    let res = {};
-    const channel = 'controller.example.timerJobProgress';
-    if (action == 'run') {
-      // 异步-执行任务及监听进度
-      this.myJobPool.runPromise('./jobs/example/timer', {jobId}).then(task => {
-        task.emitter.on('job-timer-progress', (data) => {
-          Log.info('[main-process] [ChildPoolJob] timerTask, from TimerJob data:', data);
-  
-          // 发送数据到渲染进程
-          event.sender.send(`${channel}`, data)
-        })
-        res.pid = task.pid; 
-      });
-    }
-    return res;
-  }
-
-  /**
-   * test 
-   */ 
-  monitorJob() {
-    setInterval(() => {
-      let jobPids = this.myJob.getPids();
-      let jobPoolPids = this.myJobPool.getPids();
-      Log.info(`[main-process] [monitorJob] jobPids: ${jobPids}, jobPoolPids: ${jobPoolPids}`);
-    }, 5000)
-  }  
-
-  /**
-   * 上传到smms
-   */
-  async uploadFileToSMMS(tmpFile) {
-    const res = {
-      code: 1000,
-      message: 'unknown error',
-    };
-
-    try {
-      const headersObj = {
-        'Content-Type': 'multipart/form-data',
-        'Authorization': 'aaaaaaaaaaaaa' // 请修改这个token,用你自己的账号token
-      };
-      const url = 'https://sm.ms/api/v2/upload';
-      const response = await this.app.curl(url, {
-        method: 'POST',
-        headers: headersObj,
-        files: {
-          smfile: tmpFile,
-        },
-        dataType: 'json',
-        timeout: 15000,
-      });
-      const result = response.data;
-      if (this.app.config.env === 'local') {
-        Log.info('[ExampleService] [uploadFileToSMMS]: info result:%j', result);
-      }
-      if (result.code !== 'success') {
-        Log.error('[ExampleService] [uploadFileToSMMS]: res error result:%j', result);
-      }
-      return result;
-    } catch (e) {
-      Log.error('[ExampleService] [uploadFileToSMMS]:  ERROR ', e);
-    }
-
-    return res;
-  }    
-}
-
-ExampleService.toString = () => '[class ExampleService]';
-module.exports = ExampleService;

+ 151 - 0
electron/service/framework.js

@@ -1,6 +1,8 @@
 'use strict';
 
 const { Service } = require('ee-core');
+const Log = require('ee-core/log');
+const { ChildJob, ChildPoolJob } = require('ee-core/jobs');
 
 /**
  * framework
@@ -10,6 +12,12 @@ class FrameworkService extends Service {
 
   constructor(ctx) {
     super(ctx);
+
+    // 在构造函数中初始化一些变量
+    this.myTimer = null;
+    this.myJob = new ChildJob();
+    this.myJobPool = new ChildPoolJob();
+    this.taskForJob = {};
   }
 
   /**
@@ -24,6 +32,149 @@ class FrameworkService extends Service {
     return obj;
   }
 
+  /**
+   * ipc通信(双向)
+   */
+  bothWayMessage(type, content, event) {
+    // 前端ipc频道 channel
+    const channel = 'controller.framework.ipcSendMsg';
+
+    if (type == 'start') {
+      // 每隔1秒,向前端页面发送消息
+      // 用定时器模拟
+      this.myTimer = setInterval(function(e, c, msg) {
+        let timeNow = Date.now();
+        let data = msg + ':' + timeNow;
+        e.reply(`${c}`, data)
+      }, 1000, event, channel, content)
+
+      return '开始了'
+    } else if (type == 'end') {
+      clearInterval(this.myTimer);
+      return '停止了'    
+    } else {
+      return 'ohther'
+    }
+  }
+
+  /**
+   * 执行任务
+   */ 
+  doJob(jobId, action, event) {
+    let res = {};
+    let oneTask;
+    const channel = 'controller.framework.timerJobProgress';
+    if (action == 'create') {
+      // 执行任务及监听进度
+      const timerTask = this.myJob.exec('./jobs/example/timer', {jobId});
+      timerTask.emitter.on('job-timer-progress', (data) => {
+        Log.info('[main-process] timerTask, from TimerJob data:', data);
+        // 发送数据到渲染进程
+        event.sender.send(`${channel}`, data)
+      })
+    
+      // 执行任务及监听进度 异步
+      // myjob.execPromise('./jobs/example/timer', {jobId}).then(task => {
+      //   task.emitter.on('job-timer-progress', (data) => {
+      //     Log.info('[main-process] timerTask, from TimerJob data:', data);
+      //     // 发送数据到渲染进程
+      //     event.sender.send(`${channel}`, data)
+      //   })
+      // });
+
+      res.pid = timerTask.pid; 
+      this.taskForJob[jobId] = timerTask;
+    }
+    if (action == 'close') {
+      oneTask = this.taskForJob[jobId];
+      oneTask.kill();
+      event.sender.send(`${channel}`, {jobId, number:0, pid:0});
+    }    
+
+    return res;
+  }
+
+  /**
+   * 创建pool
+   */ 
+  doCreatePool(num, event) {
+    const channel = 'controller.framework.createPoolNotice';
+    this.myJobPool.create(num).then(pids => {
+      event.reply(`${channel}`, pids);
+    });
+  }
+
+  /**
+   * 通过进程池执行任务
+   */ 
+  doJobByPool(jobId, action, event) {
+    let res = {};
+    const channel = 'controller.framework.timerJobProgress';
+    if (action == 'run') {
+      // 异步-执行任务及监听进度
+      this.myJobPool.runPromise('./jobs/example/timer', {jobId}).then(task => {
+        task.emitter.on('job-timer-progress', (data) => {
+          Log.info('[main-process] [ChildPoolJob] timerTask, from TimerJob data:', data);
+  
+          // 发送数据到渲染进程
+          event.sender.send(`${channel}`, data)
+        })
+        res.pid = task.pid; 
+      });
+    }
+    return res;
+  }
+
+  /**
+   * test 
+   */ 
+  monitorJob() {
+    setInterval(() => {
+      let jobPids = this.myJob.getPids();
+      let jobPoolPids = this.myJobPool.getPids();
+      Log.info(`[main-process] [monitorJob] jobPids: ${jobPids}, jobPoolPids: ${jobPoolPids}`);
+    }, 5000)
+  }  
+
+  /**
+   * 上传到smms
+   */
+  async uploadFileToSMMS(tmpFile) {
+    const res = {
+      code: 1000,
+      message: 'unknown error',
+    };
+
+    try {
+      const headersObj = {
+        'Content-Type': 'multipart/form-data',
+        'Authorization': 'aaaaaaaaaaaaa' // 请修改这个token,用你自己的账号token
+      };
+      const url = 'https://sm.ms/api/v2/upload';
+      const response = await this.app.curl(url, {
+        method: 'POST',
+        headers: headersObj,
+        files: {
+          smfile: tmpFile,
+        },
+        dataType: 'json',
+        timeout: 15000,
+      });
+      const result = response.data;
+      if (this.app.config.env === 'local') {
+        Log.info('[FrameworkService] [uploadFileToSMMS]: info result:%j', result);
+      }
+      if (result.code !== 'success') {
+        Log.error('[FrameworkService] [uploadFileToSMMS]: res error result:%j', result);
+      }
+      return result;
+    } catch (e) {
+      Log.error('[FrameworkService] [uploadFileToSMMS]:  ERROR ', e);
+    }
+
+    return res;
+  }
+
 }
 
 FrameworkService.toString = () => '[class FrameworkService]';

+ 55 - 7
electron/service/os.js

@@ -1,6 +1,8 @@
 'use strict';
 
 const { Service } = require('ee-core');
+const { BrowserView, Notification } = require('electron');
+const { mainWindow } = require('ee-core/electron');
 
 /**
  * os(service层为单例)
@@ -10,20 +12,66 @@ class OsService extends Service {
 
   constructor(ctx) {
     super(ctx);
+    this.myBrowserView = null;
+    this.myNotification = null;
   }
 
   /**
-   * test
+   * createBrowserView
    */
-  async test(args) {
-    let obj = {
-      status:'ok',
-      params: args
-    }
+  createBrowserView(contentUrl) {
 
-    return obj;
+    // electron 实验性功能,慎用
+    this.myBrowserView = new BrowserView();
+    mainWindow.setBrowserView(this.myBrowserView);
+    myBrowserView.setBounds({
+      x: 300,
+      y: 170,
+      width: 650,
+      height: 400
+    });
+    this.myBrowserView.webContents.loadURL(contentUrl);
   }
 
+  /**
+   * removeBrowserView
+   */
+  removeBrowserView() {
+
+    // removeBrowserView移除视图后,进程依然存在,估计是electron bug
+    mainWindow.removeBrowserView(this.myBrowserView);
+  }
+
+  /**
+   * createNotification
+   */
+  createNotification(clickEvent, closeEvent, event) {
+    const channel = 'controller.os.sendNotification';
+    this.myNotification = new Notification(options);
+
+    if (clickEvent) {
+      this.myNotification.on('click', (e) => {
+        let data = {
+          type: 'click',
+          msg: '您点击了通知消息'
+        }
+        event.reply(`${channel}`, data)
+      });
+    }
+
+    if (closeEvent) {
+      this.myNotification.on('close', (e) => {
+        let data = {
+          type: 'close',
+          msg: '您关闭了通知消息'
+        }
+        event.reply(`${channel}`, data)
+      });
+    }
+
+    this.myNotification.show();
+  } 
+
 }
 
 OsService.toString = () => '[class OsService]';

+ 1 - 6
electron/service/storage.js

@@ -15,12 +15,7 @@ class StorageService extends Service {
     super(ctx);
 
     // jsondb数据库
-    this.systemDB = Storage.connection('system');
-
-    let jsondbOptions = {
-      driver: 'jsondb'
-    }
-    this.demoDB = Storage.connection('demo', jsondbOptions);  
+    this.demoDB = Storage.connection('demo');  
     this.demoDBKey = {
       test_data: 'test_data'
     };

+ 1 - 2
frontend/src/views/os/notification/Index.vue

@@ -58,12 +58,11 @@ export default {
   },
   methods: {
     init () {
-      const self = this;
       // 避免重复监听,或者将 on 功能写到一个统一的地方,只加载一次
       this.$ipc.removeAllListeners(ipcApiRoute.sendNotification);
       this.$ipc.on(ipcApiRoute.sendNotification, (event, result) => {
         if (Object.prototype.toString.call(result) == '[object Object]') {
-          self.$message.info(result.msg);
+          this.$message.info(result.msg);
         }  
       })
     },

+ 9 - 3
frontend/src/views/os/window/Index.vue

@@ -41,15 +41,21 @@ export default {
       views: [
         {
           type: 'web',
-          content: 'https://www.bilibili.com/'
+          content: 'https://www.bilibili.com/',
+          windowName: 'window-web',
+          windowTitle: 'bilibili'
         },
         {
           type: 'html',
-          content: '/public/html/view_example.html'
+          content: '/public/html/view_example.html',
+          windowName: 'window-html',
+          windowTitle: 'html window'
         },
         {
           type: 'vue',
-          content: '/#/special/subwindow'
+          content: '/#/special/subwindow',
+          windowName: 'window-vue',
+          windowTitle: 'vue window'
         },    
       ],
     };