From 700cbbb86dc3eb0be9d1e74100865b0889aad7a9 Mon Sep 17 00:00:00 2001 From: HolographicHat Date: Wed, 13 Apr 2022 20:54:00 +0800 Subject: [PATCH] update --- export.js | 18 ++++++++++++------ native.d.ts | 1 + native/src/main.cc | 8 ++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/export.js b/export.js index e6f809f..3166928 100644 --- a/export.js +++ b/export.js @@ -3,7 +3,7 @@ const axios = require("axios") const readline = require("readline") const { randomUUID } = require("crypto") const { loadCache, log } = require("./utils") -const { openUrl } = require("./native") +const { openUrl, checkSnapFastcall, copyToClipboard } = require("./native") const exportToSeelie = proto => { const out = { achievements: {} } @@ -38,11 +38,17 @@ const exportToSnapGenshin = async proto => { timestamp: finishTimestamp }) }) - const json = JSON.stringify(out) - const path = `${process.env.TMP}/YaeAchievement-export-${randomUUID()}` - fs.writeFileSync(path, json) - openUrl(`snapgenshin://achievement/import/file?path=\"${path}\"`) - log("在 SnapGenshin 进行下一步操作") + if (checkSnapFastcall()) { + const json = JSON.stringify(out) + const path = `${process.env.TMP}/YaeAchievement-export-${randomUUID()}` + fs.writeFileSync(path, json) + openUrl(`snapgenshin://achievement/import/file?path=\"${path}\"`) + log("在 SnapGenshin 进行下一步操作") + } else { + const json = JSON.stringify(out, null, 2) + copyToClipboard(json) + log("导出内容已复制到剪贴板") + } } const exportToCocogoat = async proto => { diff --git a/native.d.ts b/native.d.ts index 9f1722f..51fa9ee 100644 --- a/native.d.ts +++ b/native.d.ts @@ -2,6 +2,7 @@ export function selectGameExecutable(): string export function checkGameIsRunning(processName: string): boolean export function whoUseThePort(port: number): object export function copyToClipboard(value: string): any +export function checkSnapFastcall(): boolean export function enablePrivilege(): any export function getDeviceInfo(): any export function getDeviceID(): string diff --git a/native/src/main.cc b/native/src/main.cc index 5cd6c2c..7ba065a 100644 --- a/native/src/main.cc +++ b/native/src/main.cc @@ -176,6 +176,13 @@ namespace native { 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) { exports.Set("pause", Function::New(env, pause)); exports.Set("openUrl", Function::New(env, openUrl)); @@ -184,6 +191,7 @@ namespace native { exports.Set("whoUseThePort", Function::New(env, whoUseThePort)); exports.Set("copyToClipboard", Function::New(env, copyToClipboard)); exports.Set("enablePrivilege", Function::New(env, enablePrivilege)); + exports.Set("checkSnapFastcall", Function::New(env, checkSnapFastcall)); exports.Set("checkGameIsRunning", Function::New(env, checkGameIsRunning)); exports.Set("selectGameExecutable", Function::New(env, selectGameExecutable)); return exports;