直接启动原神

close #80
This commit is contained in:
目棃
2024-09-30 19:21:50 +08:00
parent 911aeed9ea
commit df3158f428
13 changed files with 541 additions and 4049 deletions

View File

@@ -2,60 +2,59 @@
<v-list class="config-list">
<v-list-subheader :inset="true" class="config-header" title="路径" />
<v-divider :inset="true" class="border-opacity-75" />
<v-list-item title="用户数据目录" :subtitle="appStore.userDir">
<v-list-item title="用户数据目录" :subtitle="appStore.userDir.value">
<template #prepend>
<div class="config-icon">
<v-icon>mdi-folder-key</v-icon>
</div>
</template>
<template #append>
<v-icon @click="confirmCUD()" style="cursor: pointer" title="修改用户数据目录"
>mdi-pencil
</v-icon>
&emsp;
<v-icon @click="openPath('user')" style="cursor: pointer" title="打开用户数据目录"
>mdi-folder-open
</v-icon>
&emsp;
<v-icon @click="copyPath('user')" style="cursor: pointer" title="复制用户数据目录路径"
>mdi-content-copy
</v-icon>
<div class="config-opers">
<v-icon @click="confirmCUD()" title="修改用户数据目录"> mdi-pencil </v-icon>
<v-icon @click="openPath('user')" title="打开用户数据目录"> mdi-folder-open </v-icon>
<v-icon @click="copyPath('user')" title="复制用户数据目录路径"> mdi-content-copy </v-icon>
</div>
</template>
</v-list-item>
<v-list-item title="应用数据库路径" :subtitle="appStore.dbPath">
<v-list-item title="应用数据库路径" :subtitle="appStore.dbPath.value">
<template #prepend>
<div class="config-icon">
<v-icon>mdi-folder-account</v-icon>
</div>
</template>
<template #append>
<v-icon @click="openPath('db')" style="cursor: pointer" title="打开数据库目录"
>mdi-folder-open
</v-icon>
&emsp;
<v-icon @click="copyPath('db')" style="cursor: pointer" title="复制数据库目录路径"
>mdi-content-copy
</v-icon>
<div class="config-opers">
<v-icon @click="openPath('db')" title="打开数据库目录"> mdi-folder-open </v-icon>
<v-icon @click="copyPath('db')" title="复制数据库目录路径"> mdi-content-copy </v-icon>
</div>
</template>
</v-list-item>
<v-list-item title="日志目录" :subtitle="appStore.logDir">
<v-list-item title="启动器安装目录" :subtitle="appStore.gameDir.value">
<template #prepend>
<div class="config-icon">
<v-icon>mdi-gamepad</v-icon>
</div>
</template>
<template #append>
<div class="config-opers">
<v-icon @click="confirmCGD()" title="修改启动器安装目录"> mdi-pencil </v-icon>
<v-icon @click="openPath('game')" title="打开游戏安装目录"> mdi-folder-open </v-icon>
<v-icon @click="copyPath('game')" title="复制游戏安装目录"> mdi-content-copy </v-icon>
</div>
</template>
</v-list-item>
<v-list-item title="日志目录" :subtitle="appStore.logDir.value">
<template #prepend>
<div class="config-icon">
<v-icon>mdi-folder-multiple</v-icon>
</div>
</template>
<template #append>
<v-icon @click="confirmCLD()" style="cursor: pointer" title="清理日志文件"
>mdi-delete
</v-icon>
&emsp;
<v-icon @click="openPath('log')" style="cursor: pointer" title="打开日志目录"
>mdi-folder-open
</v-icon>
&emsp;
<v-icon @click="copyPath('log')" style="cursor: pointer" title="复制日志目录路径"
>mdi-content-copy
</v-icon>
<div class="config-opers">
<v-icon @click="confirmCLD()" title="清理日志文件"> mdi-delete </v-icon>
<v-icon @click="openPath('log')" title="打开日志目录"> mdi-folder-open </v-icon>
<v-icon @click="copyPath('log')" title="复制日志目录路径"> mdi-content-copy </v-icon>
</div>
</template>
</v-list-item>
</v-list>
@@ -63,7 +62,9 @@
<script lang="ts" setup>
import { path } from "@tauri-apps/api";
import { open } from "@tauri-apps/plugin-dialog";
import { readDir, remove } from "@tauri-apps/plugin-fs";
import { exists, readDir, remove } from "@tauri-apps/plugin-fs";
import { platform } from "@tauri-apps/plugin-os";
import { storeToRefs } from "pinia";
import { onMounted } from "vue";
import TGSqlite from "../../plugins/Sqlite/index.js";
@@ -73,37 +74,31 @@ import TGShell from "../../utils/TGShell.js";
import showConfirm from "../func/confirm.js";
import showSnackbar from "../func/snackbar.js";
const appStore = useAppStore();
const appStore = storeToRefs(useAppStore());
onMounted(async () => {
const logDir = await path.appLogDir();
const dbPath = `${await path.appConfigDir()}${path.sep()}TeyvatGuide.db`;
let message = "";
if (appStore.dbPath !== dbPath) {
appStore.dbPath = dbPath;
if (appStore.dbPath.value !== dbPath) {
appStore.dbPath.value = dbPath;
await TGSqlite.saveAppData("dbPath", dbPath);
message += "数据库路径 ";
}
if (appStore.logDir !== logDir) {
appStore.logDir = logDir;
if (appStore.logDir.value !== logDir) {
appStore.logDir.value = logDir;
message += "日志路径 ";
}
if (message !== "") {
showSnackbar({
text: `${message}已更新!`,
color: "success",
});
showSnackbar({ text: `${message}已更新!`, color: "success" });
}
});
async function confirmCUD(): Promise<void> {
const oriDir = appStore.userDir;
const oriDir = appStore.userDir.value;
const check = await showConfirm({ title: "确认修改用户数据路径吗?" });
if (!check) {
showSnackbar({
color: "cancel",
text: "已取消修改",
});
showSnackbar({ color: "cancel", text: "已取消修改" });
return;
}
const dir: string | null = await open({
@@ -112,42 +107,80 @@ async function confirmCUD(): Promise<void> {
multiple: false,
});
if (dir === null) {
showSnackbar({
color: "error",
text: "路径不能为空!",
});
showSnackbar({ color: "error", text: "路径不能为空!" });
return;
}
if (dir === oriDir) {
showSnackbar({
color: "warn",
text: "路径未修改!",
});
showSnackbar({ color: "warn", text: "路径未修改!" });
return;
}
appStore.userDir = dir;
appStore.userDir.value = dir;
await TGSqlite.saveAppData("userDir", dir);
await backUpUserData(dir);
showSnackbar({
text: "已重新备份数据!",
color: "success",
});
const confirm = await showConfirm({
title: "是否删除原用户数据目录?",
text: "删除后不可恢复!",
});
showSnackbar({ text: "已重新备份数据!", color: "success" });
const confirm = await showConfirm({ title: "是否删除原用户数据目录?", text: "删除后不可恢复!" });
if (confirm) {
await remove(oriDir, { recursive: true });
showSnackbar({
text: "已删除原用户数据目录!",
color: "success",
});
showSnackbar({ text: "已删除原用户数据目录!", color: "success" });
}
setTimeout(() => {
window.location.reload();
}, 4000);
}
async function confirmCGD(): Promise<void> {
if (platform() !== "windows") {
showSnackbar({ text: "不支持的平台!", color: "warning" });
return;
}
const oriEmpty = appStore.gameDir.value === "未设置";
const editConfirm = await showConfirm({
title: oriEmpty ? "确认设置目录?" : "确认修改目录?",
text: oriEmpty ? "请选择启动器所在目录" : `当前:${appStore.gameDir.value}`,
});
if (!editConfirm) {
showSnackbar({ text: oriEmpty ? "取消设置启动器目录" : "取消修改启动器目录", color: "cancel" });
return;
}
const dir: string | null = await open({
directory: true,
defaultPath: oriEmpty ? undefined : appStore.gameDir.value,
multiple: false,
});
if (dir === null) {
showSnackbar({ text: "路径不能为空!", color: "error" });
return;
}
if (!oriEmpty && appStore.gameDir.value === dir) {
showSnackbar({ text: "路径未修改!", color: "warn" });
return;
}
/// 校验 launcher.exe 跟 games 目录判断是否为合法的启动器路径
if (!(await exists(`${dir}${path.sep()}launcher.exe`))) {
showSnackbar({ text: "未检测到 launcher.exe", color: "error" });
return;
}
if (
!(await exists(
`${dir}${path.sep()}games${path.sep()}Genshin Impact Game${path.sep()}YuanShen.exe`,
))
) {
const confirm = await showConfirm({
title: "确认设置为启动器目录?",
text: "未检测到原神本体应用",
});
if (!confirm) {
showSnackbar({
text: oriEmpty ? "取消设置启动器目录" : "取消修改启动器目录",
color: "cancel",
});
return;
}
}
appStore.gameDir.value = dir;
showSnackbar({ text: oriEmpty ? "成功设置启动器目录" : "成功修改启动器目录" });
}
// 判断是否超过一周
function isOverWeek(date: string): boolean {
const nowTs = Date.now();
@@ -162,13 +195,10 @@ async function confirmCLD(): Promise<void> {
text: "将保留一周内的日志文件",
});
if (!check) {
showSnackbar({
color: "cancel",
text: "已取消清理",
});
showSnackbar({ color: "cancel", text: "已取消清理" });
return;
}
const logDir = appStore.logDir;
const logDir = appStore.logDir.value;
const files = await readDir(logDir);
const delFiles = files.filter((file) => {
// yyyy-mm-dd.log
@@ -179,54 +209,61 @@ async function confirmCLD(): Promise<void> {
return isOverWeek(date);
});
if (delFiles.length < 1) {
showSnackbar({
color: "warn",
text: "无需清理!",
});
showSnackbar({ color: "warn", text: "无需清理!" });
return;
}
for (const file of delFiles) {
const filePath = `${logDir}/${file.name}`;
await remove(filePath);
}
showSnackbar({
text: `已清理 ${delFiles.length} 个日志文件!`,
});
showSnackbar({ text: `已清理 ${delFiles.length} 个日志文件!` });
}
function copyPath(type: "db" | "user" | "log"): void {
function copyPath(type: "db" | "user" | "log" | "game"): void {
let targetPath: string, targetName: string;
switch (type) {
case "db":
targetPath = appStore.dbPath;
targetPath = appStore.dbPath.value;
targetName = "数据库";
break;
case "user":
targetPath = appStore.userDir;
targetPath = appStore.userDir.value;
targetName = "用户数据";
break;
case "log":
targetPath = appStore.logDir;
targetPath = appStore.logDir.value;
targetName = "日志";
break;
case "game":
if (appStore.gameDir.value === "未设置") {
showSnackbar({ text: "未设置游戏目录!", color: "warn" });
return;
}
targetPath = appStore.gameDir.value;
targetName = "游戏安装目录";
}
navigator.clipboard.writeText(targetPath);
showSnackbar({
text: `${targetName}路径已复制!`,
});
showSnackbar({ text: `${targetName}路径已复制!` });
}
async function openPath(type: "db" | "user" | "log"): Promise<void> {
async function openPath(type: "db" | "user" | "log" | "game"): Promise<void> {
let targetPath: string;
switch (type) {
case "db":
targetPath = await path.appConfigDir();
break;
case "user":
targetPath = appStore.userDir;
targetPath = appStore.userDir.value;
break;
case "log":
targetPath = appStore.logDir;
targetPath = appStore.logDir.value;
break;
case "game":
if (appStore.gameDir.value === "未设置") {
showSnackbar({ text: "未设置游戏目录!", color: "warn" });
return;
}
targetPath = appStore.gameDir.value;
break;
}
await TGShell.openPath(targetPath);
@@ -253,4 +290,11 @@ async function openPath(type: "db" | "user" | "log"): Promise<void> {
background: var(--box-bg-2);
color: var(--box-text-2);
}
.config-opers {
display: flex;
align-items: flex-end;
justify-content: center;
column-gap: 10px;
}
</style>

View File

@@ -0,0 +1,145 @@
<template>
<div class="tgb-box">
<div class="tgb-top">
<div class="tgb-title">原神启动</div>
<div class="tgb-btns">
<v-btn size="small" icon="mdi-refresh" @click="refreshAccount" variant="outlined" />
<v-btn
size="small"
:disabled="!canPlay"
icon="mdi-rocket"
variant="outlined"
@click="tryPlayGame()"
/>
</div>
</div>
<v-list-item v-if="account">
<v-list-item-title class="tgb-name"
>{{ account.nickname }}({{ account.regionName }})</v-list-item-title
>
<v-list-item-subtitle>{{ account.gameUid }} Lv.{{ account.level }}</v-list-item-subtitle>
</v-list-item>
</div>
</template>
<script lang="ts" setup>
import { path } from "@tauri-apps/api";
import { exists } from "@tauri-apps/plugin-fs";
import { Command } from "@tauri-apps/plugin-shell";
import { storeToRefs } from "pinia";
import { onMounted, ref, computed } from "vue";
import TSUserAccount from "../../plugins/Sqlite/modules/userAccount.js";
import { useAppStore } from "../../store/modules/app.js";
import { useUserStore } from "../../store/modules/user.js";
import TGLogger from "../../utils/TGLogger.js";
import TGRequest from "../../web/request/TGRequest.js";
import showSnackbar from "../func/snackbar.js";
const userStore = storeToRefs(useUserStore());
const appStore = storeToRefs(useAppStore());
const account = ref<TGApp.Sqlite.Account.Game>();
const canPlay = computed<boolean>(() => {
if (!account.value) return false;
return account.value.isOfficial === 1;
});
onMounted(async () => {
if (!userStore.uid.value) return;
await refreshAccount();
});
async function refreshAccount(): Promise<void> {
const accountFind = await TSUserAccount.game.getCurAccount(userStore.uid.value!);
if (!accountFind) account.value = undefined;
else account.value = accountFind;
showSnackbar({ text: "成功刷新当前登录用户!" });
}
async function tryPlayGame(): Promise<void> {
await refreshAccount();
if (!userStore.uid.value || !userStore.cookie.value) {
showSnackbar({ text: "请先登录!", color: "warn" });
return;
}
if (account.value === undefined) {
showSnackbar({ text: "未检测到当前登录用户!", color: "warn" });
return;
}
if (account.value.isOfficial === 0) {
showSnackbar({ text: "仅支持官服用户启动!", color: "warn" });
return;
}
if (appStore.gameDir.value === "未设置") {
showSnackbar({ text: "未设置游戏安装目录!", color: "warn" });
return;
}
const gamePath = `${appStore.gameDir.value}${path.sep()}games${path.sep()}Genshin Impact Game${path.sep()}YuanShen.exe`;
if (!(await exists(gamePath))) {
showSnackbar({ text: "未检测到原神本体应用!", color: "warn" });
return;
}
const resp = await TGRequest.User.getAuthTicket(account.value, userStore.cookie.value);
if (typeof resp !== "string") {
showSnackbar({ text: `[${resp.retcode}] ${resp.message}`, color: "error" });
await TGLogger.Error(
`[config][gameBadge] 尝试获取authTicket失败当前用户${account.value.uid}-${account.value.gameUid}`,
);
await TGLogger.Error(`[config][gameBadge] resp: ${JSON.stringify(resp)}`);
return;
}
showSnackbar({ text: `成功获取ticket:${resp},正在启动应用...` });
const cmd = Command.create("exec-sh", [`&"${gamePath}" login_auth_ticket=${resp}`], {
cwd: appStore.gameDir.value,
encoding: "utf-8",
});
console.log(cmd);
const result = await cmd.execute();
if (result.stderr) {
await TGLogger.Error(`[config][gameBadge] 启动游戏本体失败!`);
console.error(result.stderr);
showSnackbar({ text: `[config][gameBadge] ${result.stderr}`, color: "error" });
}
}
</script>
<style lang="css" scoped>
.tgb-box {
position: relative;
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: center;
padding: 10px;
border-radius: 10px;
background-image: linear-gradient(to right, #f78ca0 0%, #f9748f 19%, #fd868c 60%, #fe9a8b 100%);
color: var(--tgc-white-1);
row-gap: 10px;
}
.tgb-top {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
}
.tgb-title {
display: flex;
align-items: center;
justify-content: center;
color: var(--tgc-yellow-1);
font-family: var(--font-title);
font-size: 18px;
}
.tgb-btns {
display: flex;
align-items: center;
justify-content: center;
column-gap: 10px;
}
.tgb-name {
font-family: var(--font-title);
}
</style>

View File

@@ -103,6 +103,7 @@
<div class="config-right">
<TcAppBadge />
<TcUserBadge @loadOuter="loadHandle" />
<TcGameBadge />
</div>
</template>
@@ -115,6 +116,7 @@ import { onMounted, ref } from "vue";
import TcAppBadge from "../../components/config/tc-appBadge.vue";
import TcDataDir from "../../components/config/tc-dataDir.vue";
import TcGameBadge from "../../components/config/tc-gameBadge.vue";
import TcInfo from "../../components/config/tc-info.vue";
import TcUserBadge from "../../components/config/tc-userBadge.vue";
import showConfirm from "../../components/func/confirm.js";

View File

@@ -17,17 +17,26 @@ async function getVideoView(
aid?: string,
bvid?: string,
): Promise<TGApp.Plugins.Bili.Video.ViewData> {
let url = "https://api.bilibili.com/x/web-interface/view?";
const url = "https://api.bilibili.com/x/web-interface/wbi/view";
const params: Record<string, string | number | boolean> = {
need_view: 1,
isGaiaAoided: true,
};
if (aid) {
url += `aid=${aid}`;
params.aid = aid;
} else if (bvid) {
url += `bvid=${bvid}`;
params.bvid = bvid;
} else {
throw new Error("参数错误");
}
const resp = await TGHttp<TGApp.Plugins.Bili.Video.ViewResponse>(url, {
method: "GET",
query: params,
}).catch((err) => {
console.error(err);
return err;
});
console.warn(resp.data);
return resp.data;
}

View File

@@ -29,17 +29,19 @@ export const useAppStore = defineStore(
collapse: true,
});
// 开发者模式
const devMode = ref(false);
const devMode = ref<boolean>(false);
// 应用主题
const theme = ref("default");
const theme = ref<string>("default");
// 是否登录
const isLogin = ref(false);
const isLogin = ref<boolean>(false);
// 用户数据目录
const userDir = ref(userDataDir);
const userDir = ref<string>(userDataDir);
// 数据库路径
const dbPath = ref(dbDataPath);
const dbPath = ref<string>(dbDataPath);
// 日志目录
const logDir = ref(logDataDir);
const logDir = ref<string>(logDataDir);
// 游戏安装目录
const gameDir = ref<string>("未设置");
// 设备信息
const deviceInfo = ref<TGApp.App.Device.DeviceInfo>(getInitDeviceInfo());
// 服务器
@@ -47,7 +49,7 @@ export const useAppStore = defineStore(
// 语言
const lang = ref<AnnoLang>("zh-cn");
// 最近的咨讯类型
const recentNewsType = ref("notice");
const recentNewsType = ref<string>("notice");
// 是否开启分辨率回正
const needResize = ref<string>("true");
@@ -61,6 +63,7 @@ export const useAppStore = defineStore(
lang.value = "zh-cn";
recentNewsType.value = "notice";
needResize.value = "true";
gameDir.value = "未设置";
initDevice();
}
@@ -87,6 +90,7 @@ export const useAppStore = defineStore(
lang,
recentNewsType,
needResize,
gameDir,
init,
changeTheme,
};
@@ -96,7 +100,7 @@ export const useAppStore = defineStore(
{
key: "appPath",
storage: window.localStorage,
pick: ["userDir", "dbPath", "logDir"],
pick: ["userDir", "dbPath", "logDir", "gameDir"],
},
{
key: "app",

View File

@@ -223,4 +223,18 @@ declare namespace TGApp.BBS.Response {
list: TGApp.BBS.Account.GameAccount[];
};
}
/**
* @description 获取登录 ticket
* @interface getAuthTicketByGameBiz
* @since Beta v0.6.0
* @extends BaseWithData
* @property {string} data.ticket
* @returns getAuthTicketByGameBiz
*/
interface getAuthTicketByGameBiz extends BaseWithData {
data: {
ticket: string;
};
}
}

View File

@@ -1,13 +1,14 @@
/**
* @file web/request/TGRequest.ts
* @description 应用用到的请求函数
* @since Beta v0.5.3
* @since Beta v0.6.0
*/
import { genAuthkey, genAuthkey2 } from "./genAuthkey.js";
import { getAbyss } from "./getAbyss.js";
import { getActionTicketBySToken } from "./getActionTicket.js";
import { getAnnoContent, getAnnoList } from "./getAnno.js";
import getAuthTicket from "./getAuthTicket.js";
import { getAvatarList, getAvatarDetail } from "./getAvatarDetail.js";
import getCode from "./getCode.js";
import { getCookieTokenByGameToken, getCookieTokenBySToken } from "./getCookieToken.js";
@@ -35,6 +36,7 @@ const TGRequest = {
User: {
getAuthkey: genAuthkey,
getAuthkey2: genAuthkey2,
getAuthTicket,
getCollect: getUserCollect,
getGachaLog,
getRecord: getGameRecord,

View File

@@ -0,0 +1,41 @@
/**
* @files web/request/getAuthTicket.ts
* @description 获取登录 ticket
* @since Beta v0.6.0
*/
import TGHttp from "../../utils/TGHttp.js";
/**
* @description 获取登录ticket
* @since Beta v0.6.0
* @param {TGApp.Sqlite.Account.Game} account - 账户
* @param {TGApp.App.Account.Cookie} cookie - cookie
* @returns {Promise<TGApp.BBS.Response.Base|string>}
*/
async function getAuthTicket(
account: TGApp.Sqlite.Account.Game,
cookie: TGApp.App.Account.Cookie,
): Promise<TGApp.BBS.Response.Base | string> {
const url =
"https://passport-api.mihoyo.com/account/ma-cn-verifier/app/createAuthTicketByGameBiz";
const params = {
game_biz: account.gameBiz,
stoken: cookie.stoken,
uid: account.gameUid,
mid: cookie.mid,
};
const header = {
"x-rpc-client_type": "3",
"x-rpc-app_id": "ddxf5dufpuyo",
};
const resp = await TGHttp<TGApp.BBS.Response.getAuthTicketByGameBiz>(url, {
method: "POST",
headers: header,
query: params,
});
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
return resp.data.ticket;
}
export default getAuthTicket;