Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use deviceName for qrlogin #482

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -206,6 +206,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
)
set_source_files_properties(
wiliwili/source/utils/config_helper.cpp
wiliwili/source/utils/version_helper.cpp
wiliwili/source/activity/setting_activity.cpp
wiliwili/source/activity/dlna_activity.cpp
PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
2 changes: 2 additions & 0 deletions wiliwili/include/utils/config_helper.hpp
Original file line number Diff line number Diff line change
@@ -117,6 +117,8 @@ class APPVersion : public brls::Singleton<APPVersion> {

std::string getPlatform();

std::string getDeviceName();

static std::string getPackageName();

bool needUpdate(std::string latestVersion);
2 changes: 1 addition & 1 deletion wiliwili/source/fragment/mine_qr_login.cpp
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ void MineQrLogin::checkLogin() {
brls::Logger::debug("check login");
ASYNC_RETAIN
bilibili::BilibiliClient::get_login_info_v2(
this->oauthKey, "wiliwili - " + APPVersion::instance().getPlatform(), ProgramConfig::instance().getDeviceID(),
this->oauthKey, APPVersion::instance().getDeviceName(), ProgramConfig::instance().getDeviceID(),
[ASYNC_TOKEN](bilibili::LoginInfo info) {
this->loginCb.fire(info);
brls::Logger::debug("return code:{}", (int)info);
2 changes: 1 addition & 1 deletion wiliwili/source/utils/activity_helper.cpp
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ void Intent::openAV(const std::string& avid, uint64_t cid, int progress) {
return;
tmp = (tmp | MAX) ^ XOR;
std::string x = "0000000000";
int i = 0;
size_t i = 0;
while (i < x.length()) {
x[i++] = table[tmp % BASE];
tmp /= BASE;
42 changes: 39 additions & 3 deletions wiliwili/source/utils/version_helper.cpp
Original file line number Diff line number Diff line change
@@ -10,12 +10,17 @@
#include <borealis/core/application.hpp>
#include <borealis/core/thread.hpp>
#include <borealis/views/dialog.hpp>
#include <borealis/platforms/desktop/steam_deck.hpp>

#include "utils/config_helper.hpp"
#include "utils/dialog_helper.hpp"
#include "api/bilibili/util/http.hpp"
#include "fragment/latest_update.hpp"
#ifdef __SWITCH__
#include <switch.h>
#elif defined(__APPLE__)
#include <SystemConfiguration/SystemConfiguration.h>
#elif defined(__linux__)
#include <borealis/platforms/desktop/steam_deck.hpp>
#endif

using namespace brls::literals;

@@ -69,6 +74,37 @@ std::string APPVersion::getPlatform() {
#endif
}

std::string APPVersion::getDeviceName() {
#ifdef __SWITCH__
SetSysDeviceNickName nick;
if (R_SUCCEEDED(setsysGetDeviceNickname(&nick))) {
return nick.nickname;
}
#elif defined(_WIN32)
DWORD bufsize = MAX_PATH;
std::vector<WCHAR> buf(bufsize);
if (GetComputerNameW(buf.data(), &bufsize)) {
std::string name(bufsize * 3, '\0');
WideCharToMultiByte(CP_UTF8, 0, buf.data(), bufsize, name.data(), name.size(), nullptr, nullptr);
return name.data();
}
#elif defined(__APPLE__)
CFStringRef nameRef = SCDynamicStoreCopyComputerName(nullptr, nullptr);
if (nameRef) {
std::string name(CFStringGetLength(nameRef) * 3, '\0');
CFStringGetCString(nameRef, name.data(), name.size(), kCFStringEncodingUTF8);
CFRelease(nameRef);
return name.data();
}
#elif defined(__linux__)
std::vector<char> buf(128);
if (gethostname(buf.data(), buf.size()) == 0) {
return buf.data();
}
#endif
return fmt::format("wiliwili - {}", getPlatform());
}

std::string APPVersion::getPackageName() { return std::string{STR(BUILD_PACKAGE_NAME)}; }

bool APPVersion::needUpdate(std::string latestVersion) {
@@ -115,7 +151,7 @@ void APPVersion::checkUpdate(int delay, bool showUpToDateDialog) {
return;
}
const nlohmann::json res = nlohmann::json::parse(r.text);
auto info = res.get<ReleaseNote>();
auto info = res.get<ReleaseNote>();
if (info.tag_name.empty()) {
brls::Logger::error("Cannot parse update info, tag_name is empty");
return;