electron兼容
This commit is contained in:
parent
4002db4c22
commit
9c001c5403
3
electron/.gitignore
vendored
Normal file
3
electron/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
openRenamerBackend
|
1
electron/.npmrc
Normal file
1
electron/.npmrc
Normal file
@ -0,0 +1 @@
|
|||||||
|
electron_mirror=https://npmmirror.com/mirrors/electron/
|
8
electron/index.html
Normal file
8
electron/index.html
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>test</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
你好
|
||||||
|
</body>
|
||||||
|
</html>
|
98
electron/main.js
Normal file
98
electron/main.js
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
// main.js
|
||||||
|
// 控制应用生命周期和创建原生浏览器窗口的模组
|
||||||
|
const {app, BrowserWindow, Menu} = require('electron')
|
||||||
|
const path = require('path')
|
||||||
|
const {spawn} = require('child_process');
|
||||||
|
const net = require('net');
|
||||||
|
|
||||||
|
async function createWindow() {
|
||||||
|
// 隐藏菜单栏
|
||||||
|
Menu.setApplicationMenu(null)
|
||||||
|
// 创建浏览器窗口
|
||||||
|
const win = new BrowserWindow({
|
||||||
|
//width: 800, //窗口宽度,单位像素. 默认是 800
|
||||||
|
//height: 600, //窗口高度,单位像素. 默认是 600
|
||||||
|
icon: './logo.ico', // 设置窗口左上角的图标
|
||||||
|
show: false, //窗口创建的时候是否显示. 默认为 true
|
||||||
|
webPreferences: {
|
||||||
|
nodeIntegration: true, // 是否完整支持node。默认为 true
|
||||||
|
preload: path.join(__dirname, 'preload.js') //界面的其它脚本运行之前预先加载一个指定脚本。
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// 下面这两行代码配合上面 new BrowserWindow 里面的 show: false,可以实现打开时窗口最大化
|
||||||
|
win.maximize()
|
||||||
|
win.show()
|
||||||
|
console.log(__dirname);
|
||||||
|
let port = await startBackend()
|
||||||
|
// 并且为你的应用加载index.html
|
||||||
|
// win.loadFile('./dist/index.html')
|
||||||
|
win.loadURL(`file://${__dirname}/dist/index.html?port=` + port);
|
||||||
|
win.webContents.openDevTools()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Electron会在初始化完成并且准备好创建浏览器窗口时调用这个方法
|
||||||
|
// 部分 API 在 ready 事件触发后才能使用。
|
||||||
|
app.whenReady().then(createWindow)
|
||||||
|
// 当所有窗口都被关闭后退出
|
||||||
|
app.on('window-all-closed', () => {
|
||||||
|
// 在 macOS 上,除非用户用 Cmd + Q 确定地退出,
|
||||||
|
// 否则绝大部分应用及其菜单栏会保持激活。
|
||||||
|
if (process.platform !== 'darwin') {
|
||||||
|
app.quit()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
app.on('activate', () => {
|
||||||
|
// 在macOS上,当单击dock图标并且没有其他窗口打开时,
|
||||||
|
// 通常在应用程序中重新创建一个窗口。
|
||||||
|
if (BrowserWindow.getAllWindows().length === 0) {
|
||||||
|
createWindow()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动后台服务
|
||||||
|
* @returns {Promise<number>}
|
||||||
|
*/
|
||||||
|
async function startBackend() {
|
||||||
|
let port = 51000;
|
||||||
|
while (true) {
|
||||||
|
let ok = await checkPort(port);
|
||||||
|
if (ok) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
port = port + 1;
|
||||||
|
}
|
||||||
|
const childProcess = spawn('node', ['openRenamerBackend/dist/index.js'], {env: {"PORT": port}});
|
||||||
|
|
||||||
|
childProcess.stdout.on('data', (data) => {
|
||||||
|
console.log(`stdout: ${data}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
childProcess.stderr.on('data', (data) => {
|
||||||
|
console.error(`stderr: ${data}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
childProcess.on('close', (code) => {
|
||||||
|
console.log(`child process exited with code ${code}`);
|
||||||
|
});
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断端口是否可用
|
||||||
|
* @param port
|
||||||
|
* @returns {Promise<unknown>}
|
||||||
|
*/
|
||||||
|
function checkPort(port) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let server = net.createServer().listen(port);
|
||||||
|
server.on("listening", function () {
|
||||||
|
server.close();
|
||||||
|
resolve(true);
|
||||||
|
})
|
||||||
|
server.on("error", function (err) {
|
||||||
|
console.error(err);
|
||||||
|
resolve(false);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
15
electron/package.json
Normal file
15
electron/package.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "electron",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "main.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "electron .",
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"devDependencies": {
|
||||||
|
"electron": "^28.0.0"
|
||||||
|
}
|
||||||
|
}
|
12
electron/preload.js
Normal file
12
electron/preload.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// preload.js
|
||||||
|
// 所有Node.js API都可以在预加载过程中使用。
|
||||||
|
// 它拥有与Chrome扩展一样的沙盒。
|
||||||
|
window.addEventListener('DOMContentLoaded', () => {
|
||||||
|
const replaceText = (selector, text) => {
|
||||||
|
const element = document.getElementById(selector)
|
||||||
|
if (element) element.innerText = text
|
||||||
|
}
|
||||||
|
for (const dependency of ['chrome', 'node', 'electron']) {
|
||||||
|
replaceText(`${dependency}-version`, process.versions[dependency])
|
||||||
|
}
|
||||||
|
})
|
@ -9,22 +9,22 @@
|
|||||||
"author": "fxb",
|
"author": "fxb",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/fs-extra": "^5.0.4",
|
"@types/fs-extra": "5.0.4",
|
||||||
"@types/koa": "^2.0.47",
|
"@types/koa": "2.13.12",
|
||||||
"@types/node": "^11.13.4",
|
"@types/node": "11.13.4",
|
||||||
"axios": "^0.21.4",
|
"axios": "0.21.4",
|
||||||
"fs-extra": "^7.0.0",
|
"fs-extra": "7.0.0",
|
||||||
"koa": "^2.5.3",
|
"koa": "2.5.3",
|
||||||
"koa-body": "^4.0.4",
|
"koa-body": "4.0.4",
|
||||||
"koa-router": "^7.4.0",
|
"koa-router": "7.4.0",
|
||||||
"koa-static": "^5.0.0",
|
"koa-static": "5.0.0",
|
||||||
"koa2-cors": "^2.0.6",
|
"koa2-cors": "2.0.6",
|
||||||
"log4js": "^6.3.0",
|
"log4js": "6.3.0",
|
||||||
"moment": "^2.22.2",
|
"moment": "2.22.2",
|
||||||
"mysql2": "^2.2.5",
|
"mysql2": "2.2.5",
|
||||||
"sqlite": "^4.0.23",
|
"sqlite": "4.0.23",
|
||||||
"sqlite3": "^5.0.2",
|
"sqlite3": "5.0.2",
|
||||||
"uuid": "^3.3.2",
|
"uuid": "3.3.2",
|
||||||
"winston": "^3.1.0"
|
"winston": "3.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2012
openRenamerBackend/pnpm-lock.yaml
generated
2012
openRenamerBackend/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -8,21 +8,21 @@
|
|||||||
"lint": "vue-cli-service lint"
|
"lint": "vue-cli-service lint"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@element-plus/icons-vue": "^2.0.10",
|
"@element-plus/icons-vue": "2.0.10",
|
||||||
"axios": "^0.21.1",
|
"axios": "0.21.1",
|
||||||
"core-js": "^3.6.5",
|
"core-js": "3.6.5",
|
||||||
"dayjs": "^1.10.7",
|
"dayjs": "1.10.7",
|
||||||
"element-plus": "^2.2.25",
|
"element-plus": "2.2.25",
|
||||||
"vue": "^3.2.45",
|
"vue": "3.2.45",
|
||||||
"vue-router": "^4.0.0-0"
|
"vue-router": "4.2.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vue/cli-plugin-babel": "~5.0.8",
|
"@vue/cli-plugin-babel": "5.0.8",
|
||||||
"@vue/cli-plugin-router": "~5.0.8",
|
"@vue/cli-plugin-router": "5.0.8",
|
||||||
"@vue/cli-service": "~5.0.8",
|
"@vue/cli-service": "5.0.8",
|
||||||
"@vue/compiler-sfc": "^3.0.0",
|
"@vue/compiler-sfc": "3.0.0",
|
||||||
"less": "^3.0.4",
|
"less": "3.0.4",
|
||||||
"less-loader": "^5.0.0",
|
"less-loader": "5.0.0",
|
||||||
"prettier": "^2.2.1"
|
"prettier": "2.2.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4734
openRenamerFront/pnpm-lock.yaml
generated
4734
openRenamerFront/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -49,6 +49,15 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
async beforeCreate() {
|
async beforeCreate() {
|
||||||
|
console.log("beforeCreate");
|
||||||
|
let queryMap = {};
|
||||||
|
location.search.substring(1).split("&").forEach(item => {
|
||||||
|
let arr = item.split("=");
|
||||||
|
queryMap[arr[0]] = arr[1];
|
||||||
|
})
|
||||||
|
if (queryMap.port) {
|
||||||
|
window.baseUrl =
|
||||||
|
}
|
||||||
window.token = localStorage.getItem("token");
|
window.token = localStorage.getItem("token");
|
||||||
window.isWindows = await httpUtil.get("/file/isWindows");
|
window.isWindows = await httpUtil.get("/file/isWindows");
|
||||||
},
|
},
|
||||||
|
@ -2,4 +2,5 @@ module.exports = {
|
|||||||
devServer: {
|
devServer: {
|
||||||
proxy: "http://localhost:8089",
|
proxy: "http://localhost:8089",
|
||||||
},
|
},
|
||||||
|
publicPath: "./"
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user