mirror of
https://github.com/rubickCenter/rubick
synced 2025-12-16 23:54:19 +08:00
✨ 内置npm,替代本地npm
♻️ 优化分离插件窗口交互
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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 }); // 如果报错就输出报错日志
|
||||
// }
|
||||
// });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
<template #suffix>
|
||||
<div class="suffix-tool">
|
||||
<MoreOutlined
|
||||
v-show="!pluginLoading"
|
||||
@click="showSeparate()"
|
||||
class="icon-more"
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user