mirror of
https://github.com/rubickCenter/rubick
synced 2025-12-18 08:44:16 +08:00
init
This commit is contained in:
9
api/index.js
Normal file
9
api/index.js
Normal file
@@ -0,0 +1,9 @@
|
||||
const notice = require('./operators/notice');
|
||||
const network = require('./operators/network');
|
||||
const common = require('./operators/common');
|
||||
|
||||
window.rubick = {
|
||||
notice,
|
||||
network,
|
||||
common,
|
||||
}
|
||||
7
api/operators/common.js
Normal file
7
api/operators/common.js
Normal file
@@ -0,0 +1,7 @@
|
||||
const { shell } = require('electron');
|
||||
|
||||
module.exports = {
|
||||
openInBrowser(url) {
|
||||
shell.openExternal(url);
|
||||
}
|
||||
}
|
||||
71
api/operators/network.js
Normal file
71
api/operators/network.js
Normal file
@@ -0,0 +1,71 @@
|
||||
const {ipcRenderer} = require("electron");
|
||||
const AnyProxy = require('anyproxy');
|
||||
|
||||
const options = {
|
||||
port: 8001,
|
||||
webInterface: {
|
||||
enable: true,
|
||||
webPort: 8002
|
||||
},
|
||||
forceProxyHttps: false,
|
||||
wsIntercept: false, // 不开启websocket代理
|
||||
silent: true
|
||||
};
|
||||
|
||||
class Network {
|
||||
constructor() {
|
||||
this.mockList = [];
|
||||
this.proxyServer = null;
|
||||
}
|
||||
initNetwork(op, {
|
||||
beforeSendRequest,
|
||||
beforeSendResponse,
|
||||
success,
|
||||
}) {
|
||||
if (op === 'start') {
|
||||
if (!this.proxyServer || !this.proxyServer.recorder) {
|
||||
const _this = this;
|
||||
options.rule = {
|
||||
*beforeSendRequest(requestDetail) {
|
||||
if (beforeSendRequest) {
|
||||
return beforeSendRequest(requestDetail);
|
||||
}
|
||||
return requestDetail
|
||||
},
|
||||
*beforeSendResponse (requestDetail, responseDetail) {
|
||||
if (beforeSendResponse) {
|
||||
return beforeSendResponse(requestDetail, responseDetail);
|
||||
}
|
||||
return responseDetail;
|
||||
}
|
||||
};
|
||||
this.proxyServer = new AnyProxy.ProxyServer(options);
|
||||
this.proxyServer.once('ready', () => {
|
||||
console.log('启动完成');
|
||||
success && success(this.proxyServer);
|
||||
});
|
||||
}
|
||||
this.proxyServer.start();
|
||||
} else {
|
||||
AnyProxy.utils.systemProxyMgr.disableGlobalProxy('http');
|
||||
AnyProxy.utils.systemProxyMgr.disableGlobalProxy('https');
|
||||
this.proxyServer.close();
|
||||
success && success();
|
||||
}
|
||||
}
|
||||
getIPAddress() {
|
||||
const interfaces = require('os').networkInterfaces();
|
||||
for (const devName in interfaces) {
|
||||
const iface = interfaces[devName];
|
||||
for (let i = 0; i < iface.length; i++) {
|
||||
const alias = iface[i];
|
||||
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
|
||||
return alias.address;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new Network();
|
||||
|
||||
11
api/operators/notice.js
Normal file
11
api/operators/notice.js
Normal file
@@ -0,0 +1,11 @@
|
||||
module.exports = {
|
||||
system({title, body}, cb) {
|
||||
const myNotification = new Notification(title, {
|
||||
body
|
||||
});
|
||||
|
||||
myNotification.onclick = () => {
|
||||
cb();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user