diff --git a/electron/controller/hardware.js b/electron/controller/hardware.js deleted file mode 100644 index 547042c..0000000 --- a/electron/controller/hardware.js +++ /dev/null @@ -1,66 +0,0 @@ -'use strict'; - -const path = require('path'); -const { getBaseDir } = require('ee-core/ps'); -const { getMainWindow } = require('ee-core/electron/window'); - -/** - * 硬件设备 - 功能demo - * @class - */ -class HardwareController { - - /** - * 获取打印机列表 - */ - async getPrinterList () { - - //主线程获取打印机列表 - const win = getMainWindow(); - const list = await win.webContents.getPrintersAsync(); - - return list; - } - - /** - * 打印 - */ - print (args, event) { - const { view, deviceName } = args; - let content = null; - if (view.type == 'html') { - content = path.join('file://', getBaseDir(), view.content) - } else { - content = view.content; - } - - let opt = { - title: 'printer window', - x: 10, - y: 10, - width: 980, - height: 650 - } - const name = 'window-printer'; - const printWindow = Addon.get('window').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]'; -module.exports = HardwareController; \ No newline at end of file diff --git a/electron/controller/os.js b/electron/controller/os.js index d4b9f2c..495ab16 100644 --- a/electron/controller/os.js +++ b/electron/controller/os.js @@ -1,14 +1,11 @@ 'use strict'; const _ = require('lodash'); +const fs = require('fs'); const path = require('path'); const { app: electronApp, dialog, shell, Notification, - powerMonitor, screen, nativeTheme } = require('electron'); -// const { isProd, getBaseDir } = require('ee-core/ps'); -// const { getConfig } = require('ee-core/config'); -// const { isFileProtocol } = require('ee-core/utils/is'); const { windowService } = require('../service/os/window'); /** @@ -18,45 +15,45 @@ const { windowService } = require('../service/os/window'); class OsController { /** - * 所有方法接收两个参数 - * @param args 前端传的参数 - * @param event - ipc通信时才有值。详情见:控制器文档 + * All methods receive two parameters + * @param args Parameters transmitted by the frontend + * @param event - Values are only available during IPC communication. For details, please refer to the controller documentation */ /** - * 消息提示对话框 + * Message prompt dialog box */ messageShow() { dialog.showMessageBoxSync({ type: 'info', // "none", "info", "error", "question" 或者 "warning" - title: '自定义标题-message', - message: '自定义消息内容', - detail: '其它的额外信息' + title: 'Custom Title', + message: 'Customize message content', + detail: 'Other additional information' }) - return '打开了消息框'; + return 'Opened the message box'; } /** - * 消息提示与确认对话框 + * Message prompt and confirmation dialog box */ messageShowConfirm() { const res = dialog.showMessageBoxSync({ type: 'info', - title: '自定义标题-message', - message: '自定义消息内容', - detail: '其它的额外信息', - cancelId: 1, // 用于取消对话框的按钮的索引 - defaultId: 0, // 设置默认选中的按钮 - buttons: ['确认', '取消'], // 按钮及索引 + title: 'Custom Title', + message: 'Customize message content', + detail: 'Other additional information', + cancelId: 1, // Index of buttons used to cancel dialog boxes + defaultId: 0, // Set default selected button + buttons: ['confirm', 'cancel'], }) - let data = (res === 0) ? '点击确认按钮' : '点击取消按钮'; + let data = (res === 0) ? 'click the confirm button' : 'click the cancel button'; return data; } /** - * 选择目录 + * Select Directory */ selectFolder() { const filePaths = dialog.showOpenDialogSync({ @@ -71,7 +68,7 @@ class OsController { } /** - * 打开目录 + * open directory */ openDirectory(args) { const { id } = args; @@ -90,7 +87,7 @@ class OsController { } /** - * 选择图片 + * Select Picture */ selectPic() { const filePaths = dialog.showOpenDialogSync({ @@ -103,35 +100,19 @@ class OsController { if (_.isEmpty(filePaths)) { return null } - - return filePaths[0]; + + try { + const data = fs.readFileSync(filePaths[0]); + const pic = 'data:image/jpeg;base64,' + data.toString('base64'); + return pic; + } catch (err) { + console.error(err); + return null; + } } /** - * 加载视图内容 - */ - loadViewContent(args) { - const { type, content } = args; - let contentUrl = content; - if (type == 'html') { - contentUrl = path.join('file://', electronApp.getAppPath(), content); - } - - Services.get('os').createBrowserView(contentUrl); - - return true - } - - /** - * 移除视图内容 - */ - removeViewContent() { - Services.get('os').removeBrowserView(); - return true - } - - /** - * 打开新窗口 + * Open a new window */ createWindow(args) { const wcid = windowService.createWindow(args); @@ -163,7 +144,7 @@ class OsController { } /** - * 创建系统通知 + * Create system notifications */ sendNotification(args, event) { const { title, subtitle, body, silent} = args; @@ -185,140 +166,10 @@ class OsController { if (!_.isEmpty(silent)) { options.silent = silent; } - - Services.get('os').createNotification(options, event); + windowService.createNotification(options, event); return true - } - - /** - * 电源监控 - */ - initPowerMonitor(args, event) { - const channel = 'controller.os.initPowerMonitor'; - powerMonitor.on('on-ac', (e) => { - let data = { - type: 'on-ac', - msg: '接入了电源' - } - event.reply(`${channel}`, data) - }); - - powerMonitor.on('on-battery', (e) => { - let data = { - type: 'on-battery', - msg: '使用电池中' - } - event.reply(`${channel}`, data) - }); - - powerMonitor.on('lock-screen', (e) => { - let data = { - type: 'lock-screen', - msg: '锁屏了' - } - event.reply(`${channel}`, data) - }); - - powerMonitor.on('unlock-screen', (e) => { - let data = { - type: 'unlock-screen', - msg: '解锁了' - } - event.reply(`${channel}`, data) - }); - - return true - } - - /** - * 获取屏幕信息 - */ - getScreen(args) { - let data = []; - let res = {}; - if (args == 0) { - let res = screen.getCursorScreenPoint(); - data = [ - { - title: '横坐标', - desc: res.x - }, - { - title: '纵坐标', - desc: res.y - }, - ] - - return data; - } - if (args == 1) { - res = screen.getPrimaryDisplay(); - } - if (args == 2) { - let resArr = screen.getAllDisplays(); - // 数组,只取一个吧 - res = resArr[0]; - } - // Log.info('[electron] [ipc] [example] [getScreen] res:', res); - data = [ - { - title: '分辨率', - desc: res.bounds.width + ' x ' + res.bounds.height - }, - { - title: '单色显示器', - desc: res.monochrome ? '是' : '否' - }, - { - title: '色深', - desc: res. colorDepth - }, - { - title: '色域', - desc: res.colorSpace - }, - { - title: 'scaleFactor', - desc: res.scaleFactor - }, - { - title: '加速器', - desc: res.accelerometerSupport - }, - { - title: '触控', - desc: res.touchSupport == 'unknown' ? '不支持' : '支持' - }, - ] - - return data; - } - - /** - * 获取系统主题 - */ - getTheme() { - let theme = 'system'; - if (nativeTheme.shouldUseHighContrastColors) { - theme = 'light'; - } else if (nativeTheme.shouldUseInvertedColorScheme) { - theme = 'dark'; - } - - return theme; - } - - /** - * 设置系统主题 - */ - setTheme(args) { - - // TODO 好像没有什么明显效果 - nativeTheme.themeSource = args; - - return args; - } + } } OsController.toString = () => '[class OsController]'; diff --git a/electron/service/os/os.js b/electron/service/os/os.js deleted file mode 100644 index f848d17..0000000 --- a/electron/service/os/os.js +++ /dev/null @@ -1,88 +0,0 @@ -'use strict'; - -const { BrowserView, Notification } = require('electron'); -const { getMainWindow } = require('ee-core/electron/window'); - -/** - * os - * @class - */ -class OsService { - - constructor() { - this.myBrowserView = null; - this.myNotification = null; - } - - /** - * createBrowserView - */ - createBrowserView(contentUrl) { - - // electron 实验性功能,慎用 - const win = 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() { - // one - this.myBrowserView.webContents.loadURL('about:blank') - - // two - electron 11 remove destroy() - // this.myBrowserView.webContents.destroy(); - - // three - // this.myBrowserView.webContents.forcefullyCrashRenderer() - - // fore - // this.myBrowserView.webContents.close - } - - /** - * 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, - osService: new OsService() -}; \ No newline at end of file diff --git a/electron/service/os/window.js b/electron/service/os/window.js index 62be593..f648d94 100644 --- a/electron/service/os/window.js +++ b/electron/service/os/window.js @@ -2,7 +2,7 @@ const path = require('path'); const { app: electronApp } = require('electron'); -const { BrowserWindow, BrowserView, Notification } = require('electron'); +const { BrowserWindow, Notification } = require('electron'); const { getMainWindow } = require('ee-core/electron/window'); const { isProd, getBaseDir } = require('ee-core/ps'); @@ -13,7 +13,6 @@ const { isProd, getBaseDir } = require('ee-core/ps'); class WindowService { constructor() { - this.myBrowserView = null; this.myNotification = null; this.windows = {} } @@ -66,7 +65,7 @@ class WindowService { } /** - * 获取窗口contents id + * Get window contents id */ getWCid(args) { const { windowName } = args; @@ -94,6 +93,36 @@ class WindowService { } } + /** + * 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(); + } + } WindowService.toString = () => '[class WindowService]'; diff --git a/frontend/src/api/index.js b/frontend/src/api/index.js index 65b6250..880ddd7 100644 --- a/frontend/src/api/index.js +++ b/frontend/src/api/index.js @@ -52,13 +52,6 @@ const ipcApiRoute = { window2ToWindow1: 'controller.os.window2ToWindow1', }, - // hardware - hardware: { - getPrinterList: 'controller.hardware.getPrinterList', - print: 'controller.hardware.print', - printStatus: 'controller.hardware.printStatus', - }, - // effect effect: { selectFile: 'controller.effect.selectFile', diff --git a/frontend/src/layouts/AppSider.vue b/frontend/src/layouts/AppSider.vue index 7ddf788..b000f5d 100644 --- a/frontend/src/layouts/AppSider.vue +++ b/frontend/src/layouts/AppSider.vue @@ -53,18 +53,12 @@ export default { params: {}, }, 'menu_3' : { - icon: 'icon-xiangji', - title: '硬件', - pageName: 'Hardware', - params: {}, - }, - 'menu_4' : { icon: 'icon-liuxing', title: '特效', pageName: 'Effect', params: {}, }, - 'menu_5' : { + 'menu_4' : { icon: 'icon-gouwu', title: 'cross', pageName: 'Cross', diff --git a/frontend/src/layouts/Menu.vue b/frontend/src/layouts/Menu.vue index 462aab5..40e64d8 100644 --- a/frontend/src/layouts/Menu.vue +++ b/frontend/src/layouts/Menu.vue @@ -28,20 +28,6 @@ import subMenu from '@/router/subMenu'; export default { - // setup() { - // const state = reactive({ - // selectedKeys: ['menu_100'], - // }); - - // const handleClick = e => { - // state.selectedKeys = [e.key]; - // }; - - // return { - // state, - // handleClick, - // }; - // }, props: { id: { type: String, diff --git a/frontend/src/router/routerMap.js b/frontend/src/router/routerMap.js index e2e4893..18588b5 100644 --- a/frontend/src/router/routerMap.js +++ b/frontend/src/router/routerMap.js @@ -94,28 +94,9 @@ const constantRouterMap = [ path: '/os/theme/index', name: 'OsThemeIndex', component: () => import('@/views/os/theme/Index.vue') - }, - { - path: '/os/system/index', - name: 'OsSystemIndex', - component: () => import('@/views/os/system/Index.vue') - }, + }, ] }, - { - path: '/hardware', - name: 'Hardware', - component: () => import('@/layouts/Menu.vue'), - props: { id: 'hardware' }, - redirect: { name: 'HardwarePrinterIndex' }, - children: [ - { - path: '/hardware/printer/index', - name: 'HardwarePrinterIndex', - component: () => import('@/views/hardware/printer/Index.vue') - }, - ] - }, { path: '/effect', name: 'Effect', diff --git a/frontend/src/router/subMenu.js b/frontend/src/router/subMenu.js index 7ae7272..b7007e2 100644 --- a/frontend/src/router/subMenu.js +++ b/frontend/src/router/subMenu.js @@ -38,90 +38,58 @@ export default { params: {} }, }, - os: { - 'menu_100' : { - icon: 'profile', - title: '文件', - pageName: 'OsFileIndex', - params: {} - }, - 'menu_101' : { - icon: 'profile', - title: '视图', - pageName: 'OsWindowViewIndex', - params: {} - }, - 'menu_102' : { - icon: 'profile', - title: '窗口', - pageName: 'OsWindowIndex', - params: {} - }, - 'menu_103' : { - icon: 'profile', - title: '桌面通知', - pageName: 'OsNotificationIndex', - params: {} - }, - 'menu_104' : { - icon: 'profile', - title: '电源监控', - pageName: 'OsPowerMonitorIndex', - params: {} - }, - 'menu_105' : { - icon: 'profile', - title: '屏幕信息', - pageName: 'OsScreenIndex', - params: {} - }, - 'menu_106' : { - icon: 'profile', - title: '系统主题', - pageName: 'OsThemeIndex', - params: {} - }, - 'menu_110' : { - icon: 'profile', - title: '图片', - pageName: 'OsFilePic', - params: {} - }, - }, - hardware: { - 'menu_100' : { - icon: 'profile', - title: '打印机', - pageName: 'HardwarePrinterIndex', - params: {} - } + os: { + 'menu_100' : { + icon: 'profile', + title: '文件', + pageName: 'OsFileIndex', + params: {} }, - effect: { - 'menu_100' : { - icon: 'profile', - title: '登录', - pageName: 'EffectLoginIndex', - params: {} - } + 'menu_102' : { + icon: 'profile', + title: '窗口', + pageName: 'OsWindowIndex', + params: {} }, - cross: { - 'menu_100' : { - icon: 'profile', - title: 'go服务', - pageName: 'CrossGoIndex', - params: {} - }, - 'menu_110' : { - icon: 'profile', - title: 'java服务', - pageName: 'CrossJavaIndex', - params: {} - }, - 'menu_120' : { - icon: 'profile', - title: 'python服务', - pageName: 'CrossPythonIndex', - params: {} - }, + 'menu_103' : { + icon: 'profile', + title: '桌面通知', + pageName: 'OsNotificationIndex', + params: {} }, + 'menu_110' : { + icon: 'profile', + title: '图片', + pageName: 'OsFilePic', + params: {} + }, + }, + effect: { + 'menu_100' : { + icon: 'profile', + title: '登录', + pageName: 'EffectLoginIndex', + params: {} + } + }, + cross: { + 'menu_100' : { + icon: 'profile', + title: 'go服务', + pageName: 'CrossGoIndex', + params: {} + }, + 'menu_110' : { + icon: 'profile', + title: 'java服务', + pageName: 'CrossJavaIndex', + params: {} + }, + 'menu_120' : { + icon: 'profile', + title: 'python服务', + pageName: 'CrossPythonIndex', + params: {} + }, + }, } diff --git a/frontend/src/views/effect/login/Index.vue b/frontend/src/views/effect/login/Index.vue index 287046c..d956bfc 100644 --- a/frontend/src/views/effect/login/Index.vue +++ b/frontend/src/views/effect/login/Index.vue @@ -12,24 +12,17 @@ - diff --git a/frontend/src/views/os/file/Index.vue b/frontend/src/views/os/file/Index.vue index 280ddf7..7dcee03 100644 --- a/frontend/src/views/os/file/Index.vue +++ b/frontend/src/views/os/file/Index.vue @@ -1,5 +1,5 @@ - diff --git a/frontend/src/views/os/screen/Index.vue b/frontend/src/views/os/screen/Index.vue deleted file mode 100644 index 5f2fe4c..0000000 --- a/frontend/src/views/os/screen/Index.vue +++ /dev/null @@ -1,61 +0,0 @@ - - - diff --git a/frontend/src/views/os/subwindow/Ipc.vue b/frontend/src/views/os/subwindow/Ipc.vue index f47d0e2..db40c3c 100644 --- a/frontend/src/views/os/subwindow/Ipc.vue +++ b/frontend/src/views/os/subwindow/Ipc.vue @@ -1,5 +1,5 @@