This commit is contained in:
MakerYang
2024-08-06 18:30:21 +08:00
parent f363be1fc8
commit a902dd3de7
1870 changed files with 496402 additions and 6524 deletions

View File

@@ -0,0 +1,45 @@
import os from "os";
import Path from "path";
import File from "fs";
import {ipcRenderer} from "electron";
import Shell from "./shell";
import * as Config from "../../../package.json";
(window as any).base = {
os: os,
path: Path,
process: process,
platform: os.platform(), //darwin、linux、win32
config: Config,
file: File,
ipc: ipcRenderer,
lang: {
t: false,
locale: false
},
window: {
max: false
},
tools: {
shell: Shell,
crypto: require("crypto"),
navigator: navigator
},
app_path: (process: any)=> {
return Path.join(__dirname, (process.env["VITE_DEV_SERVER_HOST"] !== "127.0.0.1" ? "./../../../../" : "../../"));
},
app_data_path: (process: any)=> {
const path_temp= (os.platform() === "win32" ? process.env["APPDATA"] + "" : process.env["HOME"] + "");
return Path.join(path_temp, "./");
},
app_home_path: (process: any)=> {
const path_temp= (os.platform() === "win32" ? (process.env["HOMEDRIVE"] + "" + process.env["HOMEPATH"]) : process.env["HOME"] + "");
return Path.join(path_temp, "./");
},
app_temp_path: (process: any)=> {
return Path.join(os.tmpdir(), "./");
},
environment: (process: any) => {
return process.env["VITE_DEV_SERVER_HOST"] !== "127.0.0.1" ? "produce" : "develop"
},
}

View File

@@ -0,0 +1,61 @@
const Shell = {
command: (command: any, success: any, onerror: any, stderr: any, stdout: any, close: any) => {
const child_process = require("child_process");
const spawn: any = child_process.spawn(command.path, command.args, command.options ? command.options : {});
if(typeof success == "function"){
success(spawn);
}
spawn.on("error", (err: any) => {
if(typeof onerror == "function"){
onerror(err);
}
});
spawn.stderr.on("data", (data: any) => {
if(typeof stderr == "function"){
stderr(data);
}
});
spawn.stdout.on("data", (data: any) => {
if(typeof stdout == "function"){
stdout(data);
}
});
spawn.on("close", (code: any) => {
if(typeof close == "function"){
close(code);
}
});
},
commands: (commands: any, callback: any)=>{
return new Promise((resolve: any, reject: any)=> {
let command_index = 0;
const NextCommand = () => {
if (command_index >= commands.length) {
return resolve();
}
const item = commands[command_index];
Shell.command(item, (spawn: any)=>{
callback({type: "spawn", data: spawn, index: command_index});
}, (error: any)=>{
callback({type: "error", data: error.toString(), index: command_index});
reject(false);
}, (stderr: any)=>{
callback({type: "stderr", data: stderr.toString(), index: command_index});
reject(false);
}, (stdout: any)=>{
callback({type: "stdout", data: stdout.toString(), index: command_index});
}, (code: any)=>{
callback({type: "code", data: code, index: command_index});
if(code !== 0){
reject(false);
}else{
command_index++;
NextCommand();
}
});
}
});
}
}
export default Shell;

View File

@@ -0,0 +1,31 @@
import {defineConfig} from "vite";
import {join} from "path";
import {builtinModules} from "module";
import Package from "../../../package.json";
export default defineConfig({
root: __dirname,
plugins: [],
build: {
outDir: "../../../release/dist/preload",
emptyOutDir: true,
minify: "terser",
sourcemap: false,
rollupOptions: {
input: {
index: join(__dirname, "index.ts")
},
output: {
format: "cjs",
entryFileNames: "[name].cjs",
manualChunks: {},
},
external: [
"electron",
...builtinModules,
...builtinModules.map(e => `node:${e}`),
...Object.keys(Package.dependencies || {}),
],
},
}
})