内置npm,替代本地npm

♻️ 优化分离插件窗口交互
This commit is contained in:
muwoo 2023-10-26 11:04:16 +08:00
parent 289165de82
commit a3a7dfde98
12 changed files with 2286 additions and 343 deletions

View File

@ -5,7 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
<title></title>
</head>
<body>
<noscript>

View File

@ -86,6 +86,47 @@ Object.assign(window, {
plugInfo.value.subInput = null;
},
});
window.enterFullScreenTrigger = () => {
document.querySelector('.detach').classList.remove('darwin');
};
window.leaveFullScreenTrigger = () => {
const titleDom = document.querySelector('.detach');
if (!titleDom.classList.contains('darwin')) {
titleDom.classList.add('darwin');
}
};
window.maximizeTrigger = () => {
const btnMaximize = document.querySelector('.maximize')
if (!btnMaximize || btnMaximize.classList.contains('unmaximize')) return;
btnMaximize.classList.add('unmaximize');
};
window.unmaximizeTrigger = () => {
const btnMaximize = document.querySelector('.maximize');
if (!btnMaximize) return;
btnMaximize.classList.remove('unmaximize');
};
if (process.platform === 'darwin') {
window.onkeydown = (e) => {
if (e.code === 'Escape') {
ipcRenderer.send('detach:service', { type: 'endFullScreen' });
return;
}
if (e.metaKey && (e.code === 'KeyW' || e.code === 'KeyQ')) {
window.handle.close()
}
}
} else {
window.onkeydown = (e) => {
if (e.ctrlKey && e.code === 'KeyW') {
window.handle.close()
return
}
}
}
</script>
<style>

View File

@ -1,6 +1,6 @@
{
"name": "rubick",
"version": "4.0.10",
"version": "4.1.0-beta.1",
"author": "muwoo <2424880409@qq.com>",
"private": true,
"scripts": {
@ -33,6 +33,7 @@
"lodash.throttle": "^4.1.1",
"memorystream": "^0.3.1",
"node-key-sender": "^1.0.11",
"npm": "6.14.7",
"pinyin-match": "^1.2.4",
"pouchdb": "^7.2.2",
"pouchdb-load": "^1.4.6",

View File

@ -1 +1 @@
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="favicon.ico"><title>detach</title><link href="css/app.65d55ce4.css" rel="preload" as="style"><link href="js/app.bc494a66.js" rel="preload" as="script"><link href="js/chunk-vendors.b36194a6.js" rel="preload" as="script"><link href="css/app.65d55ce4.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but detach doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="js/chunk-vendors.b36194a6.js"></script><script src="js/app.bc494a66.js"></script></body></html>
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="favicon.ico"><title></title><link href="css/app.65d55ce4.css" rel="preload" as="style"><link href="js/app.f4fdc34a.js" rel="preload" as="script"><link href="js/chunk-vendors.b36194a6.js" rel="preload" as="script"><link href="css/app.65d55ce4.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but detach doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="js/chunk-vendors.b36194a6.js"></script><script src="js/app.f4fdc34a.js"></script></body></html>

View File

@ -1 +0,0 @@
(function(e){function t(t){for(var c,o,l=t[0],a=t[1],i=t[2],d=0,p=[];d<l.length;d++)o=l[d],Object.prototype.hasOwnProperty.call(r,o)&&r[o]&&p.push(r[o][0]),r[o]=0;for(c in a)Object.prototype.hasOwnProperty.call(a,c)&&(e[c]=a[c]);s&&s(t);while(p.length)p.shift()();return u.push.apply(u,i||[]),n()}function n(){for(var e,t=0;t<u.length;t++){for(var n=u[t],c=!0,l=1;l<n.length;l++){var a=n[l];0!==r[a]&&(c=!1)}c&&(u.splice(t--,1),e=o(o.s=n[0]))}return e}var c={},r={app:0},u=[];function o(t){if(c[t])return c[t].exports;var n=c[t]={i:t,l:!1,exports:{}};return e[t].call(n.exports,n,n.exports,o),n.l=!0,n.exports}o.m=e,o.c=c,o.d=function(e,t,n){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},o.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var c in e)o.d(n,c,function(t){return e[t]}.bind(null,c));return n},o.n=function(e){var t=e&&e.__esModule?function(){return e["default"]}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="";var l=window["webpackJsonp"]=window["webpackJsonp"]||[],a=l.push.bind(l);l.push=t,l=l.slice();for(var i=0;i<l.length;i++)t(l[i]);var s=a;u.push([0,"chunk-vendors"]),n()})({0:function(e,t,n){e.exports=n("cd49")},4011:function(e,t,n){},c549:function(e,t,n){},cd49:function(e,t,n){"use strict";n.r(t);var c=n("79c4"),r=n("c965"),u=n.n(r);const o={class:"info"},l=["src"],a=["value","placeholder"],i={key:1},s={class:"handle-container"},d={key:0,class:"window-handle"};var p={__name:"App",setup(e){const{ipcRenderer:t}=window.require("electron"),n=window.require("process"),r=Object(c["g"])(!1),p=localStorage.getItem("rubick-system-detach")||"{}",b=Object(c["g"])({});window.initDetach=e=>{b.value=e,r.value=e.subInput&&(!!e.subInput.value||!!e.subInput.placeholder),localStorage.setItem("rubick-system-detach",JSON.stringify(e))};try{window.initDetach(JSON.parse(p))}catch(g){}const v=u()(e=>{t.send("msg-trigger",{type:"detachInputChange",data:{text:e.target.value}})},500),f=()=>{t.send("msg-trigger",{type:"openPluginDevTools"})},O=()=>{t.send("detach:service",{type:"minimize"})},h=()=>{t.send("detach:service",{type:"maximize"})},j=()=>{t.send("detach:service",{type:"close"})};return Object.assign(window,{setSubInputValue:({value:e})=>{b.value.subInput.value=e},setSubInput:e=>{b.value.subInput.placeholder=e},removeSubInput:()=>{b.value.subInput=null}}),(e,t)=>{var u,p;return Object(c["f"])(),Object(c["c"])("div",{class:Object(c["e"])([Object(c["i"])(n).platform,"detach"])},[Object(c["d"])("div",o,[Object(c["d"])("img",{src:b.value.logo},null,8,l),r.value?(Object(c["f"])(),Object(c["c"])("input",{key:0,autofocus:"",onInput:t[0]||(t[0]=(...e)=>Object(c["i"])(v)&&Object(c["i"])(v)(...e)),value:null===(u=b.value.subInput)||void 0===u?void 0:u.value,placeholder:null===(p=b.value.subInput)||void 0===p?void 0:p.placeholder},null,40,a)):(Object(c["f"])(),Object(c["c"])("span",i,Object(c["h"])(b.value.pluginName),1))]),Object(c["d"])("div",s,[Object(c["d"])("div",{class:"handle"},[Object(c["d"])("div",{class:"devtool",onClick:f,title:"开发者工具"})]),"darwin"!==Object(c["i"])(n).platform?(Object(c["f"])(),Object(c["c"])("div",d,[Object(c["d"])("div",{class:"minimize",onClick:O}),Object(c["d"])("div",{class:"maximize",onClick:h}),Object(c["d"])("div",{class:"close",onClick:j})])):Object(c["b"])("",!0)])],2)}}};n("f8d8");const b=p;var v=b;n("4011");Object(c["a"])(v).mount("#app")},f8d8:function(e,t,n){"use strict";n("c549")}});

View File

@ -4,7 +4,6 @@ import getMacApps from './get-mac-app';
import fs from 'fs';
import path from 'path';
import translate from './translate';
import os from 'os';
const icondir = path.join(os.tmpdir(), 'ProcessIcon');

View File

@ -7,10 +7,11 @@ import path from 'path';
import got from 'got';
import fixPath from 'fix-path';
import spawn from 'cross-spawn';
import { ipcRenderer } from 'electron';
import axios from 'axios';
import npm from 'npm';
fixPath();
/**
@ -41,7 +42,7 @@ class AdapterHandler {
}
this.baseDir = options.baseDir;
let register = options.registry || 'https://registry.npm.taobao.org';
let register = options.registry || 'https://registry.npmmirror.com/';
try {
const dbdata = ipcRenderer.sendSync('msg-trigger', {
@ -157,44 +158,67 @@ class AdapterHandler {
*/
private async execCommand(cmd: string, modules: string[]): Promise<string> {
return new Promise((resolve: any, reject: any) => {
let args: string[] = [cmd].concat(
const module =
cmd !== 'uninstall' && cmd !== 'link'
? modules.map((m) => `${m}@latest`)
: modules
);
: modules;
const config: any = {
prefix: this.baseDir,
save: true,
cache: path.join(this.baseDir, 'cache'),
};
if (cmd !== 'link') {
args = args
.concat('--color=always')
.concat('--save')
.concat(`--registry=${this.registry}`);
config.registry = this.registry;
}
npm.load(config, function (err) {
npm.commands[cmd](module, function (er, data) {
if (!err) {
console.log(data);
resolve({ code: -1, data });
} else {
reject({ code: -1, data: err });
}
});
const npm = spawn('npm', args, {
cwd: this.baseDir,
npm.on('log', function (message) {
// log installation progress
console.log(message);
});
});
console.log(args);
// if (cmd !== 'link') {
// args = args
// .concat('--color=always')
// .concat('--save')
// .concat(`--registry=${this.registry}`);
// }
let output = '';
npm.stdout
.on('data', (data: string) => {
output += data; // 获取输出日志
})
.pipe(process.stdout);
npm.stderr
.on('data', (data: string) => {
output += data; // 获取报错日志
})
.pipe(process.stderr);
npm.on('close', (code: number) => {
if (!code) {
resolve({ code: 0, data: output }); // 如果没有报错就输出正常日志
} else {
reject({ code: code, data: output }); // 如果报错就输出报错日志
}
});
// const npm = spawn('npm', args, {
// cwd: this.baseDir,
// });
//
// console.log(args);
//
// let output = '';
// npm.stdout
// .on('data', (data: string) => {
// output += data; // 获取输出日志
// })
// .pipe(process.stdout);
//
// npm.stderr
// .on('data', (data: string) => {
// output += data; // 获取报错日志
// })
// .pipe(process.stderr);
//
// npm.on('close', (code: number) => {
// if (!code) {
// resolve({ code: 0, data: output }); // 如果没有报错就输出正常日志
// } else {
// reject({ code: code, data: output }); // 如果报错就输出报错日志
// }
// });
});
}
}

View File

@ -1,7 +1,9 @@
import { BrowserWindow, ipcMain, nativeTheme } from 'electron';
import { BrowserWindow, ipcMain, nativeTheme, screen } from 'electron';
import localConfig from '../common/initLocalConfig';
import commonConst from '@/common/utils/commonConst';
import path from 'path';
import { WINDOW_MIN_HEIGHT } from '@/common/constans/common';
import mainInstance from '@/main';
export default () => {
let win: any;
@ -38,6 +40,7 @@ export default () => {
webviewTag: true,
devTools: true,
nodeIntegration: true,
navigateOnDragDrop: true,
spellcheck: false,
},
});
@ -55,6 +58,7 @@ export default () => {
});
createWin.on('focus', () => {
win = createWin;
view && win.webContents?.focus();
});
createWin.once('ready-to-show', async () => {
@ -71,6 +75,73 @@ export default () => {
);
createWin.show();
});
// 最大化设置
createWin.on('maximize', () => {
createWin.webContents.executeJavaScript('window.maximizeTrigger()');
const view = createWin.getBrowserView();
if (!view) return;
const display = screen.getDisplayMatching(createWin.getBounds());
view.setBounds({
x: 0,
y: WINDOW_MIN_HEIGHT,
width: display.workArea.width,
height: display.workArea.height - WINDOW_MIN_HEIGHT,
});
});
// 最小化
createWin.on('unmaximize', () => {
createWin.webContents.executeJavaScript('window.unmaximizeTrigger()');
const view = createWin.getBrowserView();
if (!view) return;
const bounds = createWin.getBounds();
const display = screen.getDisplayMatching(bounds);
const width =
(display.scaleFactor * bounds.width) % 1 == 0
? bounds.width
: bounds.width - 2;
const height =
(display.scaleFactor * bounds.height) % 1 == 0
? bounds.height
: bounds.height - 2;
view.setBounds({
x: 0,
y: WINDOW_MIN_HEIGHT,
width,
height: height - WINDOW_MIN_HEIGHT,
});
});
createWin.on('page-title-updated', (e) => {
e.preventDefault();
});
createWin.webContents.once('render-process-gone', () => {
createWin.close();
});
if (commonConst.macOS()) {
createWin.on('enter-full-screen', () => {
createWin.webContents.executeJavaScript(
'window.enterFullScreenTrigger()'
);
});
createWin.on('leave-full-screen', () => {
createWin.webContents.executeJavaScript(
'window.leaveFullScreenTrigger()'
);
});
}
view.webContents.on('before-input-event', (event, input) => {
if (input.type !== 'keyDown') return;
if (!(input.meta || input.control || input.shift || input.alt)) {
if (input.key === 'Escape') {
operation.endFullScreen();
}
return;
}
});
const executeHooks = (hook, data) => {
if (!view) return;
const evalJs = `console.log(window.rubick);if(window.rubick && window.rubick.hooks && typeof window.rubick.hooks.on${hook} === 'function' ) {
@ -97,6 +168,9 @@ export default () => {
close: () => {
win.close();
},
endFullScreen: () => {
win.isFullScreen() && win.setFullScreen(false);
},
};
return {

View File

@ -78,13 +78,13 @@ getPluginInfo({
watch([options, pluginHistory, currentPlugin], () => {
currentSelect.value = 0;
if (currentPlugin.value.name) return;
// if (currentPlugin.value.name) return;
nextTick(() => {
ipcRenderer.sendSync('msg-trigger', {
type: 'setExpendHeight',
data: getWindowHeight(
options.value,
pluginLoading.value ? [] : pluginHistory.value
(pluginLoading.value || currentPlugin.value.name) ? [] : pluginHistory.value
),
});
});

View File

@ -42,7 +42,6 @@
<template #suffix>
<div class="suffix-tool">
<MoreOutlined
v-show="!pluginLoading"
@click="showSeparate()"
class="icon-more"
/>

View File

@ -24,6 +24,7 @@ module.exports = {
externals: [
'pouchdb',
'extract-file-icon',
'npm',
'electron-screenshots',
'@electron/remote',
],

2409
yarn.lock

File diff suppressed because it is too large Load Diff