diff options
Diffstat (limited to '')
-rw-r--r-- | .ci/scripts/android/eabuild.sh | 21 | ||||
-rw-r--r-- | .ci/scripts/android/mainlinebuild.sh | 21 | ||||
-rw-r--r-- | .github/workflows/android-ea-play-release.yml | 66 | ||||
-rw-r--r-- | .github/workflows/android-mainline-play-release.yml | 59 | ||||
-rw-r--r-- | .github/workflows/android-merge.js | 129 | ||||
-rw-r--r-- | .github/workflows/android-publish.yml | 4 | ||||
-rw-r--r-- | src/android/app/build.gradle.kts | 31 | ||||
-rw-r--r-- | src/web_service/web_backend.cpp | 31 | ||||
-rw-r--r-- | src/yuzu/configuration/configure_hotkeys.cpp | 41 | ||||
-rw-r--r-- | src/yuzu/configuration/configure_hotkeys.h | 13 | ||||
-rw-r--r-- | src/yuzu/configuration/configure_ui.cpp | 78 | ||||
-rw-r--r-- | src/yuzu/hotkeys.cpp | 3 |
12 files changed, 351 insertions, 146 deletions
diff --git a/.ci/scripts/android/eabuild.sh b/.ci/scripts/android/eabuild.sh new file mode 100644 index 000000000..1672f2948 --- /dev/null +++ b/.ci/scripts/android/eabuild.sh @@ -0,0 +1,21 @@ +#!/bin/bash -ex + +# SPDX-FileCopyrightText: 2024 yuzu Emulator Project +# SPDX-License-Identifier: GPL-3.0-or-later + +export NDK_CCACHE="$(which ccache)" +ccache -s + +export ANDROID_KEYSTORE_FILE="${GITHUB_WORKSPACE}/ks.jks" +base64 --decode <<< "${EA_PLAY_ANDROID_KEYSTORE_B64}" > "${ANDROID_KEYSTORE_FILE}" +export ANDROID_KEY_ALIAS="${PLAY_ANDROID_KEY_ALIAS}" +export ANDROID_KEYSTORE_PASS="${PLAY_ANDROID_KEYSTORE_PASS}" +export SERVICE_ACCOUNT_KEY_PATH="${GITHUB_WORKSPACE}/sa.json" +base64 --decode <<< "${EA_SERVICE_ACCOUNT_KEY_B64}" > "${SERVICE_ACCOUNT_KEY_PATH}" +./gradlew "publishEaReleaseBundle" + +ccache -s + +if [ ! -z "${ANDROID_KEYSTORE_B64}" ]; then + rm "${ANDROID_KEYSTORE_FILE}" +fi diff --git a/.ci/scripts/android/mainlinebuild.sh b/.ci/scripts/android/mainlinebuild.sh new file mode 100644 index 000000000..f3b89ed1c --- /dev/null +++ b/.ci/scripts/android/mainlinebuild.sh @@ -0,0 +1,21 @@ +#!/bin/bash -ex + +# SPDX-FileCopyrightText: 2024 yuzu Emulator Project +# SPDX-License-Identifier: GPL-3.0-or-later + +export NDK_CCACHE="$(which ccache)" +ccache -s + +export ANDROID_KEYSTORE_FILE="${GITHUB_WORKSPACE}/ks.jks" +base64 --decode <<< "${MAINLINE_PLAY_ANDROID_KEYSTORE_B64}" > "${ANDROID_KEYSTORE_FILE}" +export ANDROID_KEY_ALIAS="${PLAY_ANDROID_KEY_ALIAS}" +export ANDROID_KEYSTORE_PASS="${PLAY_ANDROID_KEYSTORE_PASS}" +export SERVICE_ACCOUNT_KEY_PATH="${GITHUB_WORKSPACE}/sa.json" +base64 --decode <<< "${MAINLINE_SERVICE_ACCOUNT_KEY_B64}" > "${SERVICE_ACCOUNT_KEY_PATH}" +./gradlew "publishMainlineReleaseBundle" + +ccache -s + +if [ ! -z "${ANDROID_KEYSTORE_B64}" ]; then + rm "${ANDROID_KEYSTORE_FILE}" +fi diff --git a/.github/workflows/android-ea-play-release.yml b/.github/workflows/android-ea-play-release.yml new file mode 100644 index 000000000..0cf78279c --- /dev/null +++ b/.github/workflows/android-ea-play-release.yml @@ -0,0 +1,66 @@ +# SPDX-FileCopyrightText: 2024 yuzu Emulator Project +# SPDX-License-Identifier: GPL-2.0-or-later + +name: yuzu-android-ea-play-release + +on: + workflow_dispatch: + inputs: + release-track: + description: 'Play store release track (internal/alpha/beta/production)' + required: true + default: 'alpha' + +jobs: + android: + runs-on: ubuntu-latest + if: ${{ github.repository == 'yuzu-emu/yuzu' }} + steps: + - uses: actions/checkout@v3 + name: Checkout + with: + fetch-depth: 0 + submodules: true + token: ${{ secrets.ALT_GITHUB_TOKEN }} + - run: npm install execa@5 + - uses: actions/github-script@v5 + name: 'Merge and publish Android EA changes' + env: + ALT_GITHUB_TOKEN: ${{ secrets.ALT_GITHUB_TOKEN }} + BUILD_EA: true + with: + script: | + const execa = require("execa"); + const mergebot = require('./.github/workflows/android-merge.js').mergebot; + process.chdir('${{ github.workspace }}'); + mergebot(github, context, execa); + - name: Get tag name + run: echo "GIT_TAG_NAME=$(cat tag-name.txt)" >> $GITHUB_ENV + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y ccache apksigner glslang-dev glslang-tools + - name: Build + run: ./.ci/scripts/android/eabuild.sh + env: + EA_PLAY_ANDROID_KEYSTORE_B64: ${{ secrets.PLAY_ANDROID_KEYSTORE_B64 }} + PLAY_ANDROID_KEY_ALIAS: ${{ secrets.PLAY_ANDROID_KEY_ALIAS }} + PLAY_ANDROID_KEYSTORE_PASS: ${{ secrets.PLAY_ANDROID_KEYSTORE_PASS }} + EA_SERVICE_ACCOUNT_KEY_B64: ${{ secrets.EA_SERVICE_ACCOUNT_KEY_B64 }} + STORE_TRACK: ${{ github.event.inputs.release-track }} + AUTO_VERSIONED: true + BUILD_EA: true + - name: Create release + uses: softprops/action-gh-release@v1 + with: + tag_name: ${{ env.EA_TAG_NAME }} + name: ${{ env.EA_TAG_NAME }} + draft: false + prerelease: false + repository: yuzu/yuzu-android + token: ${{ secrets.ALT_GITHUB_TOKEN }} diff --git a/.github/workflows/android-mainline-play-release.yml b/.github/workflows/android-mainline-play-release.yml new file mode 100644 index 000000000..8255e0a40 --- /dev/null +++ b/.github/workflows/android-mainline-play-release.yml @@ -0,0 +1,59 @@ +# SPDX-FileCopyrightText: 2024 yuzu Emulator Project +# SPDX-License-Identifier: GPL-2.0-or-later + +name: yuzu-android-mainline-play-release + +on: + workflow_dispatch: + inputs: + release-tag: + description: 'Tag # from yuzu-android that you want to build and publish' + required: true + default: '200' + release-track: + description: 'Play store release track (internal/alpha/beta/production)' + required: true + default: 'alpha' + +jobs: + android: + runs-on: ubuntu-latest + if: ${{ github.repository == 'yuzu-emu/yuzu' }} + steps: + - uses: actions/checkout@v3 + name: Checkout + with: + fetch-depth: 0 + submodules: true + token: ${{ secrets.ALT_GITHUB_TOKEN }} + - run: npm install execa@5 + - uses: actions/github-script@v5 + name: 'Pull mainline tag' + env: + MAINLINE_TAG: ${{ github.event.inputs.release-tag }} + with: + script: | + const execa = require("execa"); + const mergebot = require('./.github/workflows/android-merge.js').getMainlineTag; + process.chdir('${{ github.workspace }}'); + mergebot(execa); + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y ccache apksigner glslang-dev glslang-tools + - name: Build + run: | + echo "GIT_TAG_NAME=android-${{ github.event.inputs.releast-tag }}" >> $GITHUB_ENV + ./.ci/scripts/android/mainlinebuild.sh + env: + MAINLINE_PLAY_ANDROID_KEYSTORE_B64: ${{ secrets.PLAY_ANDROID_KEYSTORE_B64 }} + PLAY_ANDROID_KEY_ALIAS: ${{ secrets.PLAY_ANDROID_KEY_ALIAS }} + PLAY_ANDROID_KEYSTORE_PASS: ${{ secrets.PLAY_ANDROID_KEYSTORE_PASS }} + SERVICE_ACCOUNT_KEY_B64: ${{ secrets.MAINLINE_SERVICE_ACCOUNT_KEY_B64 }} + STORE_TRACK: ${{ github.event.inputs.release-track }} + AUTO_VERSIONED: true diff --git a/.github/workflows/android-merge.js b/.github/workflows/android-merge.js index 44ab56e44..315f81ba0 100644 --- a/.github/workflows/android-merge.js +++ b/.github/workflows/android-merge.js @@ -6,9 +6,12 @@ const fs = require("fs"); // which label to check for changes -const CHANGE_LABEL = 'android-merge'; +const CHANGE_LABEL_MAINLINE = 'android-merge'; +const CHANGE_LABEL_EA = 'android-ea-merge'; // how far back in time should we consider the changes are "recent"? (default: 24 hours) const DETECTION_TIME_FRAME = (parseInt(process.env.DETECTION_TIME_FRAME)) || (24 * 3600 * 1000); +const BUILD_EA = process.env.BUILD_EA == 'true'; +const MAINLINE_TAG = process.env.MAINLINE_TAG; async function checkBaseChanges(github) { // query the commit date of the latest commit on this branch @@ -40,20 +43,7 @@ async function checkBaseChanges(github) { async function checkAndroidChanges(github) { if (checkBaseChanges(github)) return true; - const query = `query($owner:String!, $name:String!, $label:String!) { - repository(name:$name, owner:$owner) { - pullRequests(labels: [$label], states: OPEN, first: 100) { - nodes { number headRepository { pushedAt } } - } - } - }`; - const variables = { - owner: 'yuzu-emu', - name: 'yuzu', - label: CHANGE_LABEL, - }; - const result = await github.graphql(query, variables); - const pulls = result.repository.pullRequests.nodes; + const pulls = getPulls(github, false); for (let i = 0; i < pulls.length; i++) { let pull = pulls[i]; if (new Date() - new Date(pull.headRepository.pushedAt) <= DETECTION_TIME_FRAME) { @@ -83,7 +73,13 @@ async function tagAndPush(github, owner, repo, execa, commit=false) { }; const tags = await github.graphql(query, variables); const tagList = tags.repository.refs.nodes; - const lastTag = tagList[0] ? tagList[0].name : 'dummy-0'; + let lastTag = 'android-1'; + for (let i = 0; i < tagList.length; ++i) { + if (tagList[i].name.includes('android-')) { + lastTag = tagList[i].name; + break; + } + } const tagNumber = /\w+-(\d+)/.exec(lastTag)[1] | 0; const channel = repo.split('-')[1]; const newTag = `${channel}-${tagNumber + 1}`; @@ -101,6 +97,48 @@ async function tagAndPush(github, owner, repo, execa, commit=false) { console.info('Successfully pushed new changes.'); } +async function tagAndPushEA(github, owner, repo, execa) { + let altToken = process.env.ALT_GITHUB_TOKEN; + if (!altToken) { + throw `Please set ALT_GITHUB_TOKEN environment variable. This token should have write access to ${owner}/${repo}.`; + } + const query = `query ($owner:String!, $name:String!) { + repository(name:$name, owner:$owner) { + refs(refPrefix: "refs/tags/", orderBy: {field: TAG_COMMIT_DATE, direction: DESC}, first: 10) { + nodes { name } + } + } + }`; + const variables = { + owner: owner, + name: repo, + }; + const tags = await github.graphql(query, variables); + const tagList = tags.repository.refs.nodes; + let lastTag = 'ea-1'; + for (let i = 0; i < tagList.length; ++i) { + if (tagList[i].name.includes('ea-')) { + lastTag = tagList[i].name; + break; + } + } + const tagNumber = /\w+-(\d+)/.exec(lastTag)[1] | 0; + const newTag = `ea-${tagNumber + 1}`; + console.log(`New tag: ${newTag}`); + console.info('Pushing tags to GitHub ...'); + await execa("git", ["remote", "add", "android", "https://github.com/yuzu-emu/yuzu-android.git"]); + await execa("git", ["fetch", "android"]); + + await execa("git", ['tag', newTag]); + await execa("git", ['push', 'android', `${newTag}`]); + + fs.writeFile('tag-name.txt', newTag, (err) => { + if (err) throw 'Could not write tag name to file!' + }) + + console.info('Successfully pushed new changes.'); +} + async function generateReadme(pulls, context, mergeResults, execa) { let baseUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/`; let output = @@ -202,10 +240,7 @@ async function resetBranch(execa) { } } -async function mergebot(github, context, execa) { - // Reset our local copy of master to what appears on yuzu-emu/yuzu - master - await resetBranch(execa); - +async function getPulls(github) { const query = `query ($owner:String!, $name:String!, $label:String!) { repository(name:$name, owner:$owner) { pullRequests(labels: [$label], states: OPEN, first: 100) { @@ -215,13 +250,49 @@ async function mergebot(github, context, execa) { } } }`; - const variables = { + const mainlineVariables = { owner: 'yuzu-emu', name: 'yuzu', - label: CHANGE_LABEL, + label: CHANGE_LABEL_MAINLINE, }; - const result = await github.graphql(query, variables); - const pulls = result.repository.pullRequests.nodes; + const mainlineResult = await github.graphql(query, mainlineVariables); + const pulls = mainlineResult.repository.pullRequests.nodes; + if (BUILD_EA) { + const eaVariables = { + owner: 'yuzu-emu', + name: 'yuzu', + label: CHANGE_LABEL_EA, + }; + const eaResult = await github.graphql(query, eaVariables); + const eaPulls = eaResult.repository.pullRequests.nodes; + return pulls.concat(eaPulls); + } + return pulls; +} + +async function getMainlineTag(execa) { + console.log(`::group::Getting mainline tag android-${MAINLINE_TAG}`); + let hasFailed = false; + try { + await execa("git", ["remote", "add", "mainline", "https://github.com/yuzu-emu/yuzu-android.git"]); + await execa("git", ["fetch", "mainline", "--tags"]); + await execa("git", ["checkout", `tags/android-${MAINLINE_TAG}`]); + await execa("git", ["submodule", "update", "--init", "--recursive"]); + } catch (err) { + console.log('::error title=Failed pull tag'); + hasFailed = true; + } + console.log("::endgroup::"); + if (hasFailed) { + throw 'Failed pull mainline tag. Aborting!'; + } +} + +async function mergebot(github, context, execa) { + // Reset our local copy of master to what appears on yuzu-emu/yuzu - master + await resetBranch(execa); + + const pulls = await getPulls(github); let displayList = []; for (let i = 0; i < pulls.length; i++) { let pull = pulls[i]; @@ -231,11 +302,17 @@ async function mergebot(github, context, execa) { console.table(displayList); await fetchPullRequests(pulls, "https://github.com/yuzu-emu/yuzu", execa); const mergeResults = await mergePullRequests(pulls, execa); - await generateReadme(pulls, context, mergeResults, execa); - await tagAndPush(github, 'yuzu-emu', `yuzu-android`, execa, true); + + if (BUILD_EA) { + await tagAndPushEA(github, 'yuzu-emu', `yuzu-android`, execa); + } else { + await generateReadme(pulls, context, mergeResults, execa); + await tagAndPush(github, 'yuzu-emu', `yuzu-android`, execa, true); + } } module.exports.mergebot = mergebot; module.exports.checkAndroidChanges = checkAndroidChanges; module.exports.tagAndPush = tagAndPush; module.exports.checkBaseChanges = checkBaseChanges; +module.exports.getMainlineTag = getMainlineTag; diff --git a/.github/workflows/android-publish.yml b/.github/workflows/android-publish.yml index 68e21c2f2..61f739e96 100644 --- a/.github/workflows/android-publish.yml +++ b/.github/workflows/android-publish.yml @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2023 yuzu Emulator Project +# SPDX-FileCopyrightText: 2024 yuzu Emulator Project # SPDX-License-Identifier: GPL-2.0-or-later name: yuzu-android-publish @@ -16,7 +16,7 @@ on: jobs: android: runs-on: ubuntu-latest - if: ${{ github.event.inputs.android != 'false' && github.repository == 'yuzu-emu/yuzu-android' }} + if: ${{ github.event.inputs.android != 'false' && github.repository == 'yuzu-emu/yuzu' }} steps: # this checkout is required to make sure the GitHub Actions scripts are available - uses: actions/checkout@v3 diff --git a/src/android/app/build.gradle.kts b/src/android/app/build.gradle.kts index 188ef9469..d44bb4c74 100644 --- a/src/android/app/build.gradle.kts +++ b/src/android/app/build.gradle.kts @@ -3,8 +3,8 @@ import android.annotation.SuppressLint import kotlin.collections.setOf -import org.jetbrains.kotlin.konan.properties.Properties import org.jlleitschuh.gradle.ktlint.reporter.ReporterType +import com.github.triplet.gradle.androidpublisher.ReleaseStatus plugins { id("com.android.application") @@ -13,6 +13,7 @@ plugins { kotlin("plugin.serialization") version "1.9.20" id("androidx.navigation.safeargs.kotlin") id("org.jlleitschuh.gradle.ktlint") version "11.4.0" + id("com.github.triplet.play") version "3.8.6" } /** @@ -58,15 +59,7 @@ android { targetSdk = 34 versionName = getGitVersion() - // If you want to use autoVersion for the versionCode, create a property in local.properties - // named "autoVersioned" and set it to "true" - val properties = Properties() - val versionProperty = try { - properties.load(project.rootProject.file("local.properties").inputStream()) - properties.getProperty("autoVersioned") ?: "" - } catch (e: Exception) { "" } - - versionCode = if (versionProperty == "true") { + versionCode = if (System.getenv("AUTO_VERSIONED") == "true") { autoVersion } else { 1 @@ -221,6 +214,15 @@ ktlint { } } +play { + val keyPath = System.getenv("SERVICE_ACCOUNT_KEY_PATH") + if (keyPath != null) { + serviceAccountCredentials.set(File(keyPath)) + } + track.set(System.getenv("STORE_TRACK") ?: "internal") + releaseStatus.set(ReleaseStatus.COMPLETED) +} + dependencies { implementation("androidx.core:core-ktx:1.12.0") implementation("androidx.appcompat:appcompat:1.6.1") @@ -257,14 +259,13 @@ fun runGitCommand(command: List<String>): String { } fun getGitVersion(): String { + val gitVersion = runGitCommand(listOf("git", "describe", "--always", "--long")) val versionName = if (System.getenv("GITHUB_ACTIONS") != null) { - val gitTag = System.getenv("GIT_TAG_NAME") ?: "" - gitTag + System.getenv("GIT_TAG_NAME") ?: gitVersion } else { - runGitCommand(listOf("git", "describe", "--always", "--long")) - .replace(Regex("(-0)?-[^-]+$"), "") + gitVersion } - return versionName.ifEmpty { "0.0" } + return versionName.replace(Regex("(-0)?-[^-]+$"), "").ifEmpty { "0.0" } } fun getGitHash(): String = diff --git a/src/web_service/web_backend.cpp b/src/web_service/web_backend.cpp index dff380cca..fdf3ac846 100644 --- a/src/web_service/web_backend.cpp +++ b/src/web_service/web_backend.cpp @@ -32,9 +32,14 @@ struct Client::Impl { Impl(std::string host_, std::string username_, std::string token_) : host{std::move(host_)}, username{std::move(username_)}, token{std::move(token_)} { std::scoped_lock lock{jwt_cache.mutex}; - if (username == jwt_cache.username && token == jwt_cache.token) { + if (this->username == jwt_cache.username && this->token == jwt_cache.token) { jwt = jwt_cache.jwt; } + + // Normalize host expression + if (!this->host.empty() && this->host.back() == '/') { + static_cast<void>(this->host.pop_back()); + } } /// A generic function handles POST, GET and DELETE request together @@ -71,18 +76,16 @@ struct Client::Impl { const std::string& jwt_ = "", const std::string& username_ = "", const std::string& token_ = "") { if (cli == nullptr) { - cli = std::make_unique<httplib::Client>(host); + cli = std::make_unique<httplib::Client>(host.c_str()); + cli->set_connection_timeout(TIMEOUT_SECONDS); + cli->set_read_timeout(TIMEOUT_SECONDS); + cli->set_write_timeout(TIMEOUT_SECONDS); } - if (!cli->is_valid()) { - LOG_ERROR(WebService, "Client is invalid, skipping request!"); - return {}; + LOG_ERROR(WebService, "Invalid URL {}", host + path); + return WebResult{WebResult::Code::InvalidURL, "Invalid URL", ""}; } - cli->set_connection_timeout(TIMEOUT_SECONDS); - cli->set_read_timeout(TIMEOUT_SECONDS); - cli->set_write_timeout(TIMEOUT_SECONDS); - httplib::Headers params; if (!jwt_.empty()) { params = { @@ -107,15 +110,15 @@ struct Client::Impl { request.headers = params; request.body = data; - httplib::Response response; - httplib::Error error; + httplib::Result result = cli->send(request); - if (!cli->send(request, response, error)) { - LOG_ERROR(WebService, "{} to {} returned null (httplib Error: {})", method, host + path, - httplib::to_string(error)); + if (!result) { + LOG_ERROR(WebService, "{} to {} returned null", method, host + path); return WebResult{WebResult::Code::LibError, "Null response", ""}; } + httplib::Response response = result.value(); + if (response.status >= 400) { LOG_ERROR(WebService, "{} to {} returned error status code: {}", method, host + path, response.status); diff --git a/src/yuzu/configuration/configure_hotkeys.cpp b/src/yuzu/configuration/configure_hotkeys.cpp index 3d18670ce..3f68de12d 100644 --- a/src/yuzu/configuration/configure_hotkeys.cpp +++ b/src/yuzu/configuration/configure_hotkeys.cpp @@ -45,15 +45,23 @@ ConfigureHotkeys::ConfigureHotkeys(Core::HID::HIDCore& hid_core, QWidget* parent controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1); - connect(timeout_timer.get(), &QTimer::timeout, [this] { SetPollingResult({}, true); }); + connect(timeout_timer.get(), &QTimer::timeout, [this] { + const bool is_button_pressed = pressed_buttons != Core::HID::NpadButton::None || + pressed_home_button || pressed_capture_button; + SetPollingResult(!is_button_pressed); + }); connect(poll_timer.get(), &QTimer::timeout, [this] { - const auto buttons = controller->GetNpadButtons(); - const auto home_pressed = controller->GetHomeButtons().home != 0; - const auto capture_pressed = controller->GetCaptureButtons().capture != 0; - if (home_pressed || capture_pressed) { - SetPollingResult(buttons.raw, false); - return; + pressed_buttons |= controller->GetNpadButtons().raw; + pressed_home_button |= this->controller->GetHomeButtons().home != 0; + pressed_capture_button |= this->controller->GetCaptureButtons().capture != 0; + if (pressed_buttons != Core::HID::NpadButton::None || pressed_home_button || + pressed_capture_button) { + const QString button_name = + GetButtonCombinationName(pressed_buttons, pressed_home_button, + pressed_capture_button) + + QStringLiteral("..."); + model->setData(button_model_index, button_name); } }); RetranslateUI(); @@ -154,16 +162,14 @@ void ConfigureHotkeys::ConfigureController(QModelIndex index) { const auto previous_key = model->data(index); - input_setter = [this, index, previous_key](const Core::HID::NpadButton button, - const bool cancel) { + input_setter = [this, index, previous_key](const bool cancel) { if (cancel) { model->setData(index, previous_key); return; } - const auto home_pressed = this->controller->GetHomeButtons().home != 0; - const auto capture_pressed = this->controller->GetCaptureButtons().capture != 0; + const QString button_string = - GetButtonCombinationName(button, home_pressed, capture_pressed); + GetButtonCombinationName(pressed_buttons, pressed_home_button, pressed_capture_button); const auto [key_sequence_used, used_action] = IsUsedControllerKey(button_string); @@ -177,17 +183,22 @@ void ConfigureHotkeys::ConfigureController(QModelIndex index) { } }; + button_model_index = index; + pressed_buttons = Core::HID::NpadButton::None; + pressed_home_button = false; + pressed_capture_button = false; + model->setData(index, tr("[waiting]")); timeout_timer->start(2500); // Cancel after 2.5 seconds - poll_timer->start(200); // Check for new inputs every 200ms + poll_timer->start(100); // Check for new inputs every 100ms // We need to disable configuration to be able to read npad buttons controller->DisableConfiguration(); } -void ConfigureHotkeys::SetPollingResult(Core::HID::NpadButton button, const bool cancel) { +void ConfigureHotkeys::SetPollingResult(const bool cancel) { timeout_timer->stop(); poll_timer->stop(); - (*input_setter)(button, cancel); + (*input_setter)(cancel); // Re-Enable configuration controller->EnableConfiguration(); diff --git a/src/yuzu/configuration/configure_hotkeys.h b/src/yuzu/configuration/configure_hotkeys.h index 5fd1bcbfe..20ea3b515 100644 --- a/src/yuzu/configuration/configure_hotkeys.h +++ b/src/yuzu/configuration/configure_hotkeys.h @@ -4,6 +4,7 @@ #pragma once #include <memory> +#include <QStandardItemModel> #include <QWidget> namespace Common { @@ -54,14 +55,20 @@ private: void RestoreControllerHotkey(QModelIndex index); void RestoreHotkey(QModelIndex index); + void SetPollingResult(bool cancel); + QString GetButtonCombinationName(Core::HID::NpadButton button, bool home, bool capture) const; + std::unique_ptr<Ui::ConfigureHotkeys> ui; QStandardItemModel* model; - void SetPollingResult(Core::HID::NpadButton button, bool cancel); - QString GetButtonCombinationName(Core::HID::NpadButton button, bool home, bool capture) const; + bool pressed_home_button; + bool pressed_capture_button; + QModelIndex button_model_index; + Core::HID::NpadButton pressed_buttons; + Core::HID::EmulatedController* controller; std::unique_ptr<QTimer> timeout_timer; std::unique_ptr<QTimer> poll_timer; - std::optional<std::function<void(Core::HID::NpadButton, bool)>> input_setter; + std::optional<std::function<void(bool)>> input_setter; }; diff --git a/src/yuzu/configuration/configure_ui.cpp b/src/yuzu/configuration/configure_ui.cpp index c8e871151..f3c91586c 100644 --- a/src/yuzu/configuration/configure_ui.cpp +++ b/src/yuzu/configuration/configure_ui.cpp @@ -248,82 +248,22 @@ void ConfigureUi::RetranslateUI() { } void ConfigureUi::InitializeLanguageComboBox() { - // This is a list of lexicographically sorted languages, only the available translations are - // shown to the user. - static const struct { - const QString name; - const char* id; - } languages[] = { - // clang-format off - {QStringLiteral(u"Bahasa Indonesia"), "id"}, // Indonesian - {QStringLiteral(u"Bahasa Melayu"), "ms"}, // Malay - {QStringLiteral(u"Catal\u00E0"), "ca"}, // Catalan - {QStringLiteral(u"\u010Ce\u0161tina"), "cs"}, // Czech - {QStringLiteral(u"Dansk"), "da"}, // Danish - {QStringLiteral(u"Deutsch"), "de"}, // German - {QStringLiteral(u"English"), "en"}, // English - {QStringLiteral(u"Espa\u00F1ol"), "es"}, // Spanish - {QStringLiteral(u"Fran\u00E7ais"), "fr"}, // French - {QStringLiteral(u"Hrvatski"), "hr"}, // Croatian - {QStringLiteral(u"Italiano"), "it"}, // Italian - {QStringLiteral(u"Magyar"), "hu"}, // Hungarian - {QStringLiteral(u"Nederlands"), "nl"}, // Dutch - {QStringLiteral(u"Norsk bokm\u00E5l"), "nb"}, // Norwegian - {QStringLiteral(u"Polski"), "pl"}, // Polish - {QStringLiteral(u"Portugu\u00EAs"), "pt_PT"}, // Portuguese - {QStringLiteral(u"Portugu\u00EAs (Brasil)"), "pt_BR"}, // Portuguese (Brazil) - {QStringLiteral(u"Rom\u00E2n\u0103"), "ro"}, // Romanian - {QStringLiteral(u"Srpski"), "sr"}, // Serbian - {QStringLiteral(u"Suomi"), "fi"}, // Finnish - {QStringLiteral(u"Svenska"), "sv"}, // Swedish - {QStringLiteral(u"Ti\u1EBFng Vi\u1EC7t"), "vi"}, // Vietnamese - {QStringLiteral(u"Ti\u1EBFng Vi\u1EC7t (Vi\u1EC7t Nam)"), "vi_VN"}, // Vietnamese - {QStringLiteral(u"T\u00FCrk\u00E7e"), "tr_TR"}, // Turkish - {QStringLiteral(u"\u0395\u03BB\u03BB\u03B7\u03BD\u03B9\u03BA\u03AC"), "el"}, // Greek - {QStringLiteral(u"\u0420\u0443\u0441\u0441\u043A\u0438\u0439"), "ru_RU"}, // Russian - {QStringLiteral(u"\u0423\u043A\u0440\u0430\u0457\u043D\u0441\u044C\u043A\u0430"), - "uk"}, // Ukrainian - {QStringLiteral(u"\u0627\u0644\u0639\u0631\u0628\u064A\u0629"), "ar"}, // Arabic - {QStringLiteral(u"\u0641\u0627\u0631\u0633\u06CC"), "fa"}, // Farsi - {QStringLiteral(u"\uD55C\uAD6D\uC5B4"), "ko_KR"}, // Korean - {QStringLiteral(u"\u65E5\u672C\u8A9E"), "ja_JP"}, // Japanese - {QStringLiteral(u"\u7B80\u4F53\u4E2D\u6587"), "zh_CN"}, // Simplified Chinese - {QStringLiteral(u"\u7E41\u9AD4\u4E2D\u6587"), "zh_TW"}, // Traditional Chinese - // clang-format on - }; ui->language_combobox->addItem(tr("<System>"), QString{}); - QDir languages_dir{QStringLiteral(":/languages")}; - QStringList language_files = languages_dir.entryList(); - for (const auto& lang : languages) { - if (QString::fromLatin1(lang.id) == QStringLiteral("en")) { - ui->language_combobox->addItem(lang.name, QStringLiteral("en")); - language_files.removeOne(QStringLiteral("en.qm")); - continue; - } - for (int i = 0; i < language_files.size(); ++i) { - QString locale = language_files[i]; - locale.truncate(locale.lastIndexOf(QLatin1Char{'.'})); - if (QString::fromLatin1(lang.id) == locale) { - ui->language_combobox->addItem(lang.name, locale); - language_files.removeAt(i); - break; - } - } - } - // Anything remaining will be at the bottom - for (const QString& file : language_files) { - LOG_CRITICAL(Frontend, "Unexpected Language File: {}", file.toStdString()); - QString locale = file; + ui->language_combobox->addItem(tr("English"), QStringLiteral("en")); + QDirIterator it(QStringLiteral(":/languages"), QDirIterator::NoIteratorFlags); + while (it.hasNext()) { + QString locale = it.next(); locale.truncate(locale.lastIndexOf(QLatin1Char{'.'})); - const QString language_name = QLocale::languageToString(QLocale(locale).language()); - const QString lang = QStringLiteral("%1 [%2]").arg(language_name, locale); - ui->language_combobox->addItem(lang, locale); + locale.remove(0, locale.lastIndexOf(QLatin1Char{'/'}) + 1); + const QString lang = QLocale::languageToString(QLocale(locale).language()); + const QString country = QLocale::countryToString(QLocale(locale).country()); + ui->language_combobox->addItem(QStringLiteral("%1 (%2)").arg(lang, country), locale); } // Unlike other configuration changes, interface language changes need to be reflected on the // interface immediately. This is done by passing a signal to the main window, and then // retranslating when passing back. - connect(ui->language_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, + connect(ui->language_combobox, qOverload<int>(&QComboBox::currentIndexChanged), this, &ConfigureUi::OnLanguageChanged); } diff --git a/src/yuzu/hotkeys.cpp b/src/yuzu/hotkeys.cpp index b7693ad0d..170f14684 100644 --- a/src/yuzu/hotkeys.cpp +++ b/src/yuzu/hotkeys.cpp @@ -193,8 +193,7 @@ void ControllerShortcut::ControllerUpdateEvent(Core::HID::ControllerTriggerType if (!Settings::values.controller_navigation) { return; } - if (button_sequence.npad.raw == Core::HID::NpadButton::None && - button_sequence.capture.raw == 0 && button_sequence.home.raw == 0) { + if (button_sequence.npad.raw == Core::HID::NpadButton::None) { return; } |