1
0
mirror of https://gitee.com/sui-feng-cb/AzurLaneAutoScript1 synced 2026-03-16 10:27:21 +08:00

Opt: AP preserve until reset

This commit is contained in:
sui-feng-cb
2025-09-03 13:59:51 +08:00
parent c3856ae101
commit 6b0383a169
137 changed files with 9982 additions and 13706 deletions

View File

@@ -1,59 +0,0 @@
import {ALAS_CONFIG_YAML} from '@common/constant/config';
import {getAlasABSPath, checkIsFirst} from '@common/utils';
import {ThemeObj} from '@common/constant/theme';
import {Dirent} from 'fs';
const path = require('path');
const yaml = require('yaml');
const fs = require('fs');
let alasConfig: AlasConfig | null = null;
export async function getAlasConfig() {
if (alasConfig === null) {
const alasPath = getAlasABSPath();
const file = fs.readFileSync(path.join(alasPath, `./config/${ALAS_CONFIG_YAML}`), 'utf8');
const config = yaml.parse(file) as DefAlasConfig;
const WebuiPort = config.Deploy.Webui.WebuiPort.toString();
const Theme = config.Deploy.Webui.Theme;
alasConfig = {
webuiUrl: `http://127.0.0.1:${WebuiPort}`,
theme: ThemeObj[Theme] || 'light',
language: config.Deploy.Webui.Language || 'en-US',
repository: config.Deploy.Git.Repository as any,
alasPath,
};
}
return alasConfig;
}
export function checkIsNeedInstall() {
return checkIsFirst();
}
interface fileInfoItem {
name: string;
path: string;
lastModifyTime: Date;
}
export function getAlasConfigDirFiles() {
const alasPath = getAlasABSPath();
const configPath = path.join(alasPath, `./config`);
const files: Dirent[] = fs.readdirSync(configPath, {withFileTypes: true});
const filesInfoList: fileInfoItem[] = files.map((file: Dirent) => {
const name = file.name;
const filePath = path.join(configPath, name);
return {
name,
path: filePath,
lastModifyTime: getFileUpdateDate(filePath),
};
});
return {
configPath,
files: filesInfoList,
};
}
export function getFileUpdateDate(path: string) {
const stat = fs.statSync(path);
return stat.mtime;
}

View File

@@ -1,13 +0,0 @@
import {ipcRenderer} from 'electron';
import IpcRenderer = Electron.IpcRenderer;
export function ipcRendererSend(channel: string, ...args: any[]): void {
ipcRenderer.send(channel, ...args);
}
export function ipcRendererOn(
channel: string,
listener: (event: Electron.IpcRendererEvent, ...args: any[]) => void,
): IpcRenderer {
return ipcRenderer.on(channel, listener);
}

View File

@@ -1,10 +1,17 @@
/**
* @module preload
*/
import {contextBridge} from 'electron';
export {sha256sum} from './nodeCrypto';
export {versions} from './versions';
export {ipcRendererSend, ipcRendererOn} from './electronApi';
export {getAlasConfig, checkIsNeedInstall, getAlasConfigDirFiles} from './alasConfig';
export {copyFilesToDir} from '@common/utils/copyFilesToDir';
export {modifyConfigYaml} from './modifyConfigYaml';
const apiKey = 'electron';
/**
* @see https://github.com/electron/electron/issues/21437#issuecomment-573522360
*/
const api: ElectronApi = {
versions: process.versions,
};
/**
* The "Main World" is the JavaScript context that your main renderer code runs in.
* By default, the page you load in your renderer executes code in this world.
*
* @see https://www.electronjs.org/docs/api/context-bridge
*/
contextBridge.exposeInMainWorld(apiKey, api);

View File

@@ -1,8 +0,0 @@
import {join, normalize} from 'path';
import {modifyYaml} from '@common/utils';
import {ALAS_CONFIG_YAML} from '@common/constant/config';
export function modifyConfigYaml(path: string, keyObj: {[k in string]: any}) {
const configYamlPath = join(normalize(path) + `./config/${ALAS_CONFIG_YAML}`);
return modifyYaml(configYamlPath, keyObj);
}

View File

@@ -1,5 +0,0 @@
import {type BinaryLike, createHash} from 'node:crypto';
export function sha256sum(data: BinaryLike) {
return createHash('sha256').update(data).digest('hex');
}

View File

@@ -1 +0,0 @@
export {versions} from 'node:process';

View File

@@ -1,15 +0,0 @@
import {test, expect} from 'vitest';
import {modifyYaml} from '../../common/utils/modifyYaml';
import getAlasABSPath from '../../common/utils/getAlasABSPath';
const path = require('path');
const fs = require('fs');
test('test write yaml', () => {
const absPath = getAlasABSPath();
const yamlPath = path.join(absPath, './config/deploy.yaml');
modifyYaml(yamlPath, {Branch: 'dev'});
const newYamlConfig1 = require('yaml').parse(fs.readFileSync(yamlPath, 'utf8'));
expect(newYamlConfig1.Deploy.Git.Branch).toBe('dev');
modifyYaml(yamlPath, {Branch: 'master'});
const newYamlConfig2 = require('yaml').parse(fs.readFileSync(yamlPath, 'utf8'));
expect(newYamlConfig2.Deploy.Git.Branch).toBe('master');
});

View File

@@ -1,15 +0,0 @@
import {createHash} from 'crypto';
import {expect, test} from 'vitest';
import {sha256sum, versions} from '../src';
test('versions', async () => {
expect(versions).toBe(process.versions);
});
test('nodeCrypto', async () => {
// Test hashing a random string.
const testString = Math.random().toString(36).slice(2, 7);
const expectedHash = createHash('sha256').update(testString).digest('hex');
expect(sha256sum(testString)).toBe(expectedHash);
});

View File

@@ -1,18 +1,18 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "esnext",
"target": "esnext",
"sourceMap": false,
"moduleResolution": "Node",
"skipLibCheck": true,
"strict": true,
"isolatedModules": true,
"types": ["node"],
"baseUrl": ".",
"paths": {
"@common/*": ["../common/*"]
"paths": {
"/@/*": [
"./src/*"
]
}
},
"include": ["src/**/*.ts", "../../types/**/*.d.ts","../common/**/*.ts"],
"exclude": ["**/*.spec.ts", "**/*.test.ts"]
"files": [
"types/electron-api.d.ts",
"src/index.ts"
],
"include": [
"../../types/**/*.d.ts"
]
}

View File

@@ -1,8 +1,9 @@
interface ElectronApi {
readonly versions: Readonly<NodeJS.ProcessVersions>;
readonly versions: Readonly<NodeJS.ProcessVersions>
}
declare interface Window {
electron: Readonly<ElectronApi>;
electronRequire?: NodeRequire;
electron: Readonly<ElectronApi>
electronRequire?: NodeRequire
}

View File

@@ -1,10 +1,8 @@
import {chrome} from '../../.electron-vendors.cache.json';
import {preload} from 'unplugin-auto-expose';
import {join} from 'node:path';
import {injectAppVersion} from '../../version/inject-app-version-plugin.mjs';
import {chrome} from '../../electron-vendors.config.json';
import {join} from 'path';
import {builtinModules} from 'module';
const PACKAGE_ROOT = __dirname;
const PROJECT_ROOT = join(PACKAGE_ROOT, '../..');
/**
* @type {import('vite').UserConfig}
@@ -13,35 +11,41 @@ const PROJECT_ROOT = join(PACKAGE_ROOT, '../..');
const config = {
mode: process.env.MODE,
root: PACKAGE_ROOT,
envDir: PROJECT_ROOT,
envDir: process.cwd(),
resolve: {
alias: [
{
find: '@common',
replacement: join(PACKAGE_ROOT, '../common'),
},
],
alias: {
'/@/': join(PACKAGE_ROOT, 'src') + '/',
},
},
build: {
ssr: true,
sourcemap: 'inline',
target: `chrome${chrome}`,
outDir: 'dist',
assetsDir: '.',
minify: process.env.MODE !== 'development',
minify: process.env.MODE === 'development' ? false : 'terser',
terserOptions: {
ecma: 2020,
compress: {
passes: 2,
},
safari10: false,
},
lib: {
entry: 'src/index.ts',
formats: ['cjs'],
},
rollupOptions: {
external: [
'electron',
...builtinModules,
],
output: {
entryFileNames: '[name].cjs',
},
},
emptyOutDir: true,
reportCompressedSize: false,
brotliSize: false,
},
plugins: [preload.vite(), injectAppVersion()],
};
export default config;