diff --git a/build/extraResources/chromeExtension/read.txt b/build/extraResources/chromeExtension/read.txt
new file mode 100644
index 0000000..57b4b84
--- /dev/null
+++ b/build/extraResources/chromeExtension/read.txt
@@ -0,0 +1 @@
+chrome应用商店ctx文件,解压后,放置在此目录中,打包时会将资源加入安装包内。
\ No newline at end of file
diff --git a/electron/config.js b/electron/config.js
index e079ec7..a251916 100644
--- a/electron/config.js
+++ b/electron/config.js
@@ -83,8 +83,6 @@ const config = {
}
exports.get = function (flag = '', env = 'prod') {
- console.log('[config] [get] flag:', flag);
-
if (flag === 'egg') {
const eggConfig = storage.getEggConfig();
if (env === 'prod' && eggConfig.port) {
diff --git a/electron/ipc/example.js b/electron/ipc/example.js
index f0e7212..fcf4faa 100644
--- a/electron/ipc/example.js
+++ b/electron/ipc/example.js
@@ -290,7 +290,6 @@ exports.getTheme = function (event, channel, arg) {
} else if (nativeTheme.shouldUseInvertedColorScheme) {
theme = 'dark';
}
- console.log('[electron] [ipc] [example] [getTheme] theme:', theme);
return theme;
}
@@ -300,7 +299,7 @@ exports.getTheme = function (event, channel, arg) {
*/
exports.setTheme = function (event, channel, arg) {
- console.log('[electron] [ipc] [example] [setTheme] theme:', arg);
+ // TODO 好像没有什么明显效果
nativeTheme.themeSource = arg;
return arg;
diff --git a/electron/lib/api.js b/electron/lib/api.js
index 4a829db..28595b8 100644
--- a/electron/lib/api.js
+++ b/electron/lib/api.js
@@ -10,8 +10,11 @@ const eLogger = require('./eLogger').get();
const apis = {};
+/**
+ * 安装模块
+ */
exports.setup = async function () {
- eLogger.info('[api] [setup] start');
+ console.log('[electron-lib-api] [setup]');
setApi();
// use api server
diff --git a/electron/lib/autoUpdater.js b/electron/lib/autoUpdater.js
index c95e481..848300b 100644
--- a/electron/lib/autoUpdater.js
+++ b/electron/lib/autoUpdater.js
@@ -7,7 +7,11 @@ const {app} = require('electron');
const eLogger = require('./eLogger').get();
const helper = require('./helper');
+/**
+ * 安装模块
+ */
exports.setup = function () {
+ console.log('[electron-lib-autoUpater] [setup]');
const version = app.getVersion();
eLogger.info('[autoUpdater] [setup] current version: ', version);
const platformObj = helper.getPlatform();
diff --git a/electron/lib/awaken.js b/electron/lib/awaken.js
index 3360f5e..52b16ee 100644
--- a/electron/lib/awaken.js
+++ b/electron/lib/awaken.js
@@ -8,6 +8,7 @@ const eLogger = require('./eLogger').get();
* 唤起Electron应用
*/
exports.setup = function () {
+ console.log('[electron-lib-awaken] [setup]');
const protocolInfo = config.get('awakeProtocol');
const PROTOCOL = protocolInfo.protocol;
diff --git a/electron/lib/chromeExtension.js b/electron/lib/chromeExtension.js
new file mode 100644
index 0000000..b4b0e45
--- /dev/null
+++ b/electron/lib/chromeExtension.js
@@ -0,0 +1,83 @@
+'use strict';
+
+const { app, session } = require('electron');
+const _ = require('lodash');
+const fs = require('fs');
+const path = require('path')
+const eLogger = require('./eLogger').get();
+
+/**
+ * 安装模块
+ */
+exports.setup = async function () {
+ console.log('[electron-lib-chromeExtension] [setup]');
+ const extensionIds = this.getAllIds();
+
+ for (let i = 0; i < extensionIds.length; i++) {
+ await this.load(extensionIds[i]);
+ }
+}
+
+/**
+ * 获取扩展id列表(crx解压后的目录名,即是该扩展的id)
+ */
+exports.getAllIds = function () {
+ const extendsionDir = this.getDirectory();
+ const ids = getDirs(extendsionDir);
+
+ return ids;
+}
+
+/**
+ * 扩展所在目录
+ */
+exports.getDirectory = function () {
+ let extensionDirPath = '';
+ let variablePath = 'build'; // 打包前路径
+ if (app.isPackaged) {
+ variablePath = '..'; // 打包后路径
+ }
+ extensionDirPath = path.join(app.getAppPath(), variablePath, "extraResources", "chromeExtension");
+
+ return extensionDirPath;
+}
+
+/**
+ * 加载扩展
+ */
+exports.load = async function (extensionId = '') {
+ if (_.isEmpty(extensionId)) {
+ return false
+ }
+
+ try {
+ const extensionPath = path.join(this.getDirectory(), extensionId);
+ console.log('[chromeExtension] [load] extensionPath:', extensionPath);
+ await session.defaultSession.loadExtension(extensionPath, { allowFileAccess: true });
+ } catch (e) {
+ eLogger.error('[chromeExtension] [load] load extension error extensionId:%s, errorInfo:%s', extensionId, e.toString());
+ return false
+ }
+
+ return true
+}
+
+/*
+ * 获取目录下所有文件夹
+ */
+function getDirs(dir) {
+ if (!dir) {
+ return [];
+ }
+
+ const components = [];
+ const files = fs.readdirSync(dir);
+ files.forEach(function(item, index) {
+ const stat = fs.lstatSync(dir + '/' + item);
+ if (stat.isDirectory() === true) {
+ components.push(item);
+ }
+ });
+
+ return components;
+};
\ No newline at end of file
diff --git a/electron/lib/crashReport.js b/electron/lib/crashReport.js
index bc4c777..a286857 100644
--- a/electron/lib/crashReport.js
+++ b/electron/lib/crashReport.js
@@ -3,7 +3,11 @@
const { crashReporter } = require('electron');
const config = require('../config');
+/**
+ * 安装模块
+ */
exports.setup = function () {
+ console.log('[electron-lib-crashReport] [setup]');
const options = config.get('crashReport');
- crashReporter.start(options);
+ crashReporter.start(options);
}
\ No newline at end of file
diff --git a/electron/lib/eLogger.js b/electron/lib/eLogger.js
index ba1ae7c..431619c 100644
--- a/electron/lib/eLogger.js
+++ b/electron/lib/eLogger.js
@@ -24,7 +24,11 @@ class Log {
}
}
+/**
+ * 安装模块
+ */
exports.setup = function () {
+ console.log('[electron-lib-eLogger] [setup]');
return new Log();
}
diff --git a/electron/lib/ipcMain.js b/electron/lib/ipcMain.js
index 836dfbe..7ee60b7 100644
--- a/electron/lib/ipcMain.js
+++ b/electron/lib/ipcMain.js
@@ -41,6 +41,7 @@ const getApiName = (jsname, method) => {
* 加载所有的主程序
*/
exports.setup = () => {
+ console.log('[electron-lib-ipc] [setup]');
const ipcDir = path.normalize(__dirname + '/../ipc');
fs.readdirSync(ipcDir).forEach(function (filename) {
if (path.extname(filename) === '.js' && filename !== 'index.js') {
diff --git a/electron/lib/security.js b/electron/lib/security.js
index ee720ac..fb118ec 100644
--- a/electron/lib/security.js
+++ b/electron/lib/security.js
@@ -4,10 +4,10 @@ const helper = require('./helper');
const eLogger = require('./eLogger').get();
/**
- * security check
+ * 安装模块
*/
exports.setup = function () {
- eLogger.info('[security] [setup] process.argv:', process.argv);
+ console.log('[electron-lib-security] [setup]');
const runWithDebug = process.argv.find(function(e){
let isHasDebug = e.includes("--inspect") || e.includes("--inspect-brk") || e.includes("--remote-debugging-port");
return isHasDebug;
diff --git a/electron/lib/shortcut.js b/electron/lib/shortcut.js
index ebba328..b263e2c 100644
--- a/electron/lib/shortcut.js
+++ b/electron/lib/shortcut.js
@@ -3,8 +3,12 @@
const { globalShortcut } = require('electron');
const storage = require('./storage');
+/**
+ * 安装模块
+ */
exports.setup = function () {
// default
+ console.log('[electron-lib-shortcut] [setup]');
storage.iniPreferences();
}
diff --git a/electron/lib/storage.js b/electron/lib/storage.js
index 5e5b459..8756399 100644
--- a/electron/lib/storage.js
+++ b/electron/lib/storage.js
@@ -12,7 +12,11 @@ const pkg = require('../../package.json');
const storageDb = 'db.json';
const _ = require('lodash');
+/**
+ * 安装模块
+ */
exports.setup = function () {
+ console.log('[electron-lib-storage] [setup]');
const storageDir = this.getStorageDir();
if (!fs.existsSync(storageDir)) {
utils.mkdir(storageDir);
diff --git a/electron/lib/tray.js b/electron/lib/tray.js
index 7a4b23a..e4882ff 100644
--- a/electron/lib/tray.js
+++ b/electron/lib/tray.js
@@ -5,7 +5,11 @@ const path = require('path');
const helper = require('./helper');
const config = require('../config');
+/**
+ * 安装模块
+ */
exports.setup = function () {
+ console.log('[electron-lib-tray] [setup]');
const cfg = config.get('tray');
// 托盘图标
diff --git a/electron/preferences.js b/electron/preferences.js
index ec82960..3fff6f1 100644
--- a/electron/preferences.js
+++ b/electron/preferences.js
@@ -6,8 +6,9 @@ const shortcut = require('./lib/shortcut');
const tray = require('./lib/tray');
const awaken = require('./lib/awaken');
const security = require('./lib/security');
+const chromeExtension = require('./lib/chromeExtension');
-module.exports = () => {
+module.exports = async () => {
// shortcut
shortcut.setup();
@@ -20,6 +21,9 @@ module.exports = () => {
// security
security.setup();
+ // chrome extension
+ await chromeExtension.setup();
+
// check update
const updateConfig = config.get('autoUpdate');
if ((is.windows() && updateConfig.windows) || (is.macOS() && updateConfig.macOS)
diff --git a/frontend/src/config/router.config.js b/frontend/src/config/router.config.js
index 5dec688..6623b9b 100644
--- a/frontend/src/config/router.config.js
+++ b/frontend/src/config/router.config.js
@@ -28,6 +28,11 @@ export const constantRouterMap = [
name: 'DemoSocketIndex',
component: () => import('@/views/demo/socket/Index')
},
+ {
+ path: '/demo/extend/index',
+ name: 'DemoExtendIndex',
+ component: () => import('@/views/demo/extend/Index')
+ },
{
path: '/demo/windowview/index',
name: 'DemoWindowViewIndex',
diff --git a/frontend/src/layouts/DemoMenu.vue b/frontend/src/layouts/DemoMenu.vue
index 1c5503f..4ef196f 100644
--- a/frontend/src/layouts/DemoMenu.vue
+++ b/frontend/src/layouts/DemoMenu.vue
@@ -36,6 +36,12 @@ export default {
pageName: 'DemoSocketIndex',
params: {}
},
+ 'menu_301' : {
+ icon: 'profile',
+ title: '扩展程序',
+ pageName: 'DemoExtendIndex',
+ params: {}
+ },
'menu_400' : {
icon: 'profile',
title: '视图',
diff --git a/frontend/src/views/demo/extend/Index.vue b/frontend/src/views/demo/extend/Index.vue
new file mode 100644
index 0000000..cf037a5
--- /dev/null
+++ b/frontend/src/views/demo/extend/Index.vue
@@ -0,0 +1,77 @@
+
+