This commit is contained in:
HolographicHat
2022-04-13 20:54:00 +08:00
parent 6a23153f70
commit 700cbbb86d
3 changed files with 21 additions and 6 deletions

View File

@@ -3,7 +3,7 @@ const axios = require("axios")
const readline = require("readline") const readline = require("readline")
const { randomUUID } = require("crypto") const { randomUUID } = require("crypto")
const { loadCache, log } = require("./utils") const { loadCache, log } = require("./utils")
const { openUrl } = require("./native") const { openUrl, checkSnapFastcall, copyToClipboard } = require("./native")
const exportToSeelie = proto => { const exportToSeelie = proto => {
const out = { achievements: {} } const out = { achievements: {} }
@@ -38,11 +38,17 @@ const exportToSnapGenshin = async proto => {
timestamp: finishTimestamp timestamp: finishTimestamp
}) })
}) })
const json = JSON.stringify(out) if (checkSnapFastcall()) {
const path = `${process.env.TMP}/YaeAchievement-export-${randomUUID()}` const json = JSON.stringify(out)
fs.writeFileSync(path, json) const path = `${process.env.TMP}/YaeAchievement-export-${randomUUID()}`
openUrl(`snapgenshin://achievement/import/file?path=\"${path}\"`) fs.writeFileSync(path, json)
log("在 SnapGenshin 进行下一步操作") openUrl(`snapgenshin://achievement/import/file?path=\"${path}\"`)
log("在 SnapGenshin 进行下一步操作")
} else {
const json = JSON.stringify(out, null, 2)
copyToClipboard(json)
log("导出内容已复制到剪贴板")
}
} }
const exportToCocogoat = async proto => { const exportToCocogoat = async proto => {

1
native.d.ts vendored
View File

@@ -2,6 +2,7 @@ export function selectGameExecutable(): string
export function checkGameIsRunning(processName: string): boolean export function checkGameIsRunning(processName: string): boolean
export function whoUseThePort(port: number): object export function whoUseThePort(port: number): object
export function copyToClipboard(value: string): any export function copyToClipboard(value: string): any
export function checkSnapFastcall(): boolean
export function enablePrivilege(): any export function enablePrivilege(): any
export function getDeviceInfo(): any export function getDeviceInfo(): any
export function getDeviceID(): string export function getDeviceID(): string

View File

@@ -176,6 +176,13 @@ namespace native {
return Napi::Number::New(env, (INT_PTR)retcode); // NOLINT(cppcoreguidelines-narrowing-conversions) return Napi::Number::New(env, (INT_PTR)retcode); // NOLINT(cppcoreguidelines-narrowing-conversions)
} }
Value checkSnapFastcall(const CallbackInfo &info) {
Env env = info.Env();
wstring queryResult;
RegUtils::GetString(HKEY_CLASSES_ROOT, L"snapgenshin", L"", queryResult);
return Napi::Boolean::New(env, wcscmp(queryResult.c_str(), L"URL:snapgenshin") == 0);
}
Object init(Env env, Object exports) { Object init(Env env, Object exports) {
exports.Set("pause", Function::New(env, pause)); exports.Set("pause", Function::New(env, pause));
exports.Set("openUrl", Function::New(env, openUrl)); exports.Set("openUrl", Function::New(env, openUrl));
@@ -184,6 +191,7 @@ namespace native {
exports.Set("whoUseThePort", Function::New(env, whoUseThePort)); exports.Set("whoUseThePort", Function::New(env, whoUseThePort));
exports.Set("copyToClipboard", Function::New(env, copyToClipboard)); exports.Set("copyToClipboard", Function::New(env, copyToClipboard));
exports.Set("enablePrivilege", Function::New(env, enablePrivilege)); exports.Set("enablePrivilege", Function::New(env, enablePrivilege));
exports.Set("checkSnapFastcall", Function::New(env, checkSnapFastcall));
exports.Set("checkGameIsRunning", Function::New(env, checkGameIsRunning)); exports.Set("checkGameIsRunning", Function::New(env, checkGameIsRunning));
exports.Set("selectGameExecutable", Function::New(env, selectGameExecutable)); exports.Set("selectGameExecutable", Function::New(env, selectGameExecutable));
return exports; return exports;