mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-12-04 22:21:41 +09:00
* fix: use text button for local proxy learn more * feat: pin page header and collapse large title on scroll * fix: enable page scrolling only when content overflows * refactor: drop qml focus hacks and simplify list selectors - remove unused objectNames, dead functions and focus timers - handle back/escape in FocusController instead of PageStart keys - declare static menus as items instead of list<QtObject> models - make radio/segment selection binding-driven, reuseItems opt-in - fix full access share default server preselection * refactor: convert config models to Q_PROPERTY and merge MtProto pages - config models: QObject with properties instead of single-row list models - protocol/service pages: Flickable layout, write-through edits, no save focus hack - MtProxy/Telemt settings share PageServiceMtProtoSettingsBase - question drawer requested via Dialogs singleton * chore: bump version * refactor: create rarely shown controls on demand - focus ring and selection glow create MultiEffect only while visible - text fields create the context menu, action buttons and attached button on demand - setup page loads the details sheet content when it opens * feat: macOS and iOS 26 app icon from Icon Composer - add images/AppIcon.icon with colour and mono marks - build the app icon from it on macOS, macOS NE and iOS, require Xcode 26 - drop app.icns and the AppIcon asset catalogs * feat: update design system changes - header: centered 18 semibold title in a 56 px row with 48 px buttons, no large title - hide the back arrow on stack root pages - subtitle as the first content block, 16 under the header and 24 to the next block - main toggles as the first content row, desktop only - logs: share and a more menu instead of three header icons - countries: 48 px gear, search first under the header, chips to list 24 - sheets: 32 px from title to the first block - tab bar: 44 px buttons centered with 18 px gaps - connection key field: Insert while empty, clear button after paste - error toast: default text color, accent error code link - 24 px between the last block and sticky buttons * chore: minor ui fixes * fix: restore trailing buttons in country rows * chore: bump version * chore: build macOS and iOS on macos-26 runners for the Icon Composer app icon * fix: load only one Go runtime in the UI process libAmneziaVPN linked libwg-go and libovpn3 (which pulls in the Go-based libck-ovpn-plugin) without using any of their symbols. With libagw that made three Go runtimes in the UI process. They conflict over signal handlers, and the app crashed at startup with SIGSEGV and no tombstone. Stop linking awg-android and openvpn-pt-android into the app library. Package their .so files through QT_ANDROID_EXTRA_LIBS instead; the VPN service processes still load them from Kotlin. * chore: sync with figma and minor ui fixes * chore: bump version * fix: disable Go async preemption on Apple platforms Build libagw with -X=runtime.godebugDefault=asyncpreemptoff=1 on macOS and iOS to work around the Go runtime crash on macOS (golang/go#75887).
309 lines
8.9 KiB
C++
309 lines
8.9 KiB
C++
#include "logsUiController.h"
|
|
|
|
#include <QClipboard>
|
|
#include <QDateTime>
|
|
#include <QDebug>
|
|
#include <QFile>
|
|
#include <QFutureWatcher>
|
|
#include <QGuiApplication>
|
|
#include <QLocale>
|
|
#include <QtConcurrent>
|
|
|
|
#include "core/controllers/logsController.h"
|
|
#include "core/controllers/settingsController.h"
|
|
#include "systemController.h"
|
|
#include "version.h"
|
|
|
|
#ifdef Q_OS_ANDROID
|
|
#include <QDir>
|
|
#include <QStandardPaths>
|
|
|
|
#include "platforms/android/android_controller.h"
|
|
#endif
|
|
|
|
namespace
|
|
{
|
|
constexpr qsizetype kLiveTailTextLimit = 2 * 1024 * 1024;
|
|
constexpr qsizetype kCopyTextLimit = 512 * 1024;
|
|
|
|
LogsController::Stream streamFromString(const QString &stream)
|
|
{
|
|
return stream == QLatin1String("tunnel") ? LogsController::Stream::Tunnel : LogsController::Stream::App;
|
|
}
|
|
|
|
QString newestAppLogFile()
|
|
{
|
|
const QStringList files = LogsController::files(LogsController::Stream::App);
|
|
return files.isEmpty() ? QString() : files.last();
|
|
}
|
|
|
|
#ifdef Q_OS_ANDROID
|
|
bool shareFile(const QString &fileName, const QByteArray &data, const QString &mimeType)
|
|
{
|
|
QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/share"));
|
|
dir.removeRecursively();
|
|
if (!dir.mkpath(QStringLiteral("."))) {
|
|
qWarning() << "LogsUiController: cannot create" << dir.path();
|
|
return false;
|
|
}
|
|
|
|
QFile file(dir.filePath(fileName));
|
|
if (!file.open(QIODevice::WriteOnly) || file.write(data) != data.size()) {
|
|
qWarning() << "LogsUiController: cannot write" << file.fileName();
|
|
return false;
|
|
}
|
|
file.close();
|
|
|
|
AndroidController::instance()->shareFile(file.fileName(), mimeType);
|
|
return true;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
LogsUiController::LogsUiController(SettingsController *settingsController, QObject *parent)
|
|
: QObject(parent), m_settingsController(settingsController)
|
|
{
|
|
m_liveTailTimer.setInterval(1000);
|
|
connect(&m_liveTailTimer, &QTimer::timeout, this, &LogsUiController::onLiveTailTimeout);
|
|
connect(qGuiApp, &QGuiApplication::applicationStateChanged, this, &LogsUiController::onApplicationStateChanged);
|
|
}
|
|
|
|
QString LogsUiController::appLogSize() const
|
|
{
|
|
return formatSize(LogsController::size(LogsController::Stream::App));
|
|
}
|
|
|
|
QString LogsUiController::tunnelLogSize() const
|
|
{
|
|
return formatSize(LogsController::size(LogsController::Stream::Tunnel));
|
|
}
|
|
|
|
bool LogsUiController::hasLogs() const
|
|
{
|
|
return LogsController::size(LogsController::Stream::App) > 0 || LogsController::size(LogsController::Stream::Tunnel) > 0;
|
|
}
|
|
|
|
QString LogsUiController::viewerStream() const
|
|
{
|
|
return m_viewerStream;
|
|
}
|
|
|
|
void LogsUiController::setViewerStream(const QString &stream)
|
|
{
|
|
if (m_viewerStream == stream) {
|
|
return;
|
|
}
|
|
m_viewerStream = stream;
|
|
emit viewerStreamChanged();
|
|
}
|
|
|
|
bool LogsUiController::busy() const
|
|
{
|
|
return m_busy;
|
|
}
|
|
|
|
void LogsUiController::setBusy(bool busy)
|
|
{
|
|
if (m_busy == busy) {
|
|
return;
|
|
}
|
|
m_busy = busy;
|
|
emit busyChanged();
|
|
}
|
|
|
|
QString LogsUiController::formatSize(qint64 bytes) const
|
|
{
|
|
const QLocale locale = m_settingsController->getAppLanguage();
|
|
if (bytes < 1024) {
|
|
return tr("%1 B").arg(locale.toString(bytes));
|
|
}
|
|
if (bytes < 1024 * 1024) {
|
|
return tr("%1 KB").arg(locale.toString(qRound64(bytes / 1024.0)));
|
|
}
|
|
return tr("%1 MB").arg(locale.toString(bytes / (1024.0 * 1024.0), 'f', 1));
|
|
}
|
|
|
|
void LogsUiController::refreshSizes()
|
|
{
|
|
emit sizesChanged();
|
|
}
|
|
|
|
void LogsUiController::load(const QString &stream)
|
|
{
|
|
const quint64 loadId = ++m_loadId;
|
|
const LogsController::Stream logsStream = streamFromString(stream);
|
|
|
|
auto *watcher = new QFutureWatcher<LoadResult>(this);
|
|
connect(watcher, &QFutureWatcher<LoadResult>::finished, this, [this, watcher, stream, logsStream, loadId]() {
|
|
const LoadResult result = watcher->result();
|
|
watcher->deleteLater();
|
|
|
|
if (loadId != m_loadId) {
|
|
return;
|
|
}
|
|
|
|
m_lastText = result.text;
|
|
if (logsStream == LogsController::Stream::App) {
|
|
m_tailFile = result.tailFile;
|
|
m_tailSize = result.tailSize;
|
|
}
|
|
emit streamLoaded(stream, result.text);
|
|
});
|
|
|
|
watcher->setFuture(QtConcurrent::run([logsStream]() {
|
|
LoadResult result;
|
|
if (logsStream == LogsController::Stream::App) {
|
|
result.tailFile = newestAppLogFile();
|
|
}
|
|
result.text = LogsController::readTail(logsStream, &result.tailSize);
|
|
return result;
|
|
}));
|
|
}
|
|
|
|
void LogsUiController::startLiveTail()
|
|
{
|
|
m_liveTailEnabled = true;
|
|
m_tailFile = newestAppLogFile();
|
|
m_tailSize = LogsController::fileSize(m_tailFile);
|
|
m_liveTailTimer.start();
|
|
}
|
|
|
|
void LogsUiController::stopLiveTail()
|
|
{
|
|
m_liveTailEnabled = false;
|
|
m_liveTailTimer.stop();
|
|
}
|
|
|
|
void LogsUiController::copyLoaded()
|
|
{
|
|
QString text = m_lastText;
|
|
if (text.size() > kCopyTextLimit) {
|
|
text = text.right(kCopyTextLimit);
|
|
const qsizetype firstNewline = text.indexOf(QLatin1Char('\n'));
|
|
if (firstNewline >= 0) {
|
|
text.remove(0, firstNewline + 1);
|
|
}
|
|
}
|
|
QGuiApplication::clipboard()->setText(text);
|
|
}
|
|
|
|
void LogsUiController::exportStream(const QString &stream, const QString &fileName)
|
|
{
|
|
const LogsController::Stream logsStream = streamFromString(stream);
|
|
runExport([logsStream]() { return LogsController::readAll(logsStream); },
|
|
[fileName](const QByteArray &data, bool *cancelled) {
|
|
return SystemController::saveFile(fileName, data, QStringLiteral("text/plain"), cancelled);
|
|
});
|
|
}
|
|
|
|
void LogsUiController::saveAll(const QString &fileName)
|
|
{
|
|
runExport([]() { return LogsController::zipAll(); },
|
|
[fileName](const QByteArray &data, bool *cancelled) {
|
|
return SystemController::saveFile(fileName, data, QStringLiteral("application/zip"), cancelled);
|
|
});
|
|
}
|
|
|
|
void LogsUiController::shareStream(const QString &stream)
|
|
{
|
|
#ifdef Q_OS_ANDROID
|
|
const LogsController::Stream logsStream = streamFromString(stream);
|
|
const QString fileName = defaultFileName(stream);
|
|
runExport([logsStream]() { return LogsController::readAll(logsStream); },
|
|
[fileName](const QByteArray &data, bool *) { return shareFile(fileName, data, QStringLiteral("text/plain")); });
|
|
#else
|
|
Q_UNUSED(stream);
|
|
#endif
|
|
}
|
|
|
|
void LogsUiController::runExport(const std::function<QByteArray()> &build,
|
|
const std::function<bool(const QByteArray &, bool *)> &deliver)
|
|
{
|
|
if (m_busy) {
|
|
return;
|
|
}
|
|
setBusy(true);
|
|
|
|
auto *watcher = new QFutureWatcher<QByteArray>(this);
|
|
connect(watcher, &QFutureWatcher<QByteArray>::finished, this, [this, watcher, deliver]() {
|
|
const QByteArray data = watcher->result();
|
|
watcher->deleteLater();
|
|
|
|
bool cancelled = false;
|
|
const bool success = deliver(data, &cancelled);
|
|
if (!success) {
|
|
qInfo() << "LogsUiController: save or share" << (cancelled ? "was cancelled" : "failed");
|
|
}
|
|
setBusy(false);
|
|
emit exportFinished(success, !success && cancelled);
|
|
});
|
|
|
|
watcher->setFuture(QtConcurrent::run(build));
|
|
}
|
|
|
|
QString LogsUiController::defaultFileName(const QString &kind) const
|
|
{
|
|
const QString timestamp = QDateTime::currentDateTime().toString(QStringLiteral("yyyyMMdd-HHmmss"));
|
|
if (kind == QLatin1String("all")) {
|
|
return QStringLiteral("%1-logs-%2.zip").arg(APPLICATION_NAME, timestamp);
|
|
}
|
|
|
|
const QString stream = kind == QLatin1String("tunnel") ? QStringLiteral("tunnel") : QStringLiteral("app");
|
|
return QStringLiteral("%1-%2-%3.log").arg(APPLICATION_NAME, stream, timestamp);
|
|
}
|
|
|
|
void LogsUiController::onLiveTailTimeout()
|
|
{
|
|
const QString file = newestAppLogFile();
|
|
QFile logFile(file);
|
|
const qint64 size = logFile.open(QIODevice::ReadOnly) ? logFile.size() : 0;
|
|
|
|
if (file != m_tailFile || size < m_tailSize) {
|
|
m_tailFile = file;
|
|
m_tailSize = size;
|
|
emit reloadRequired();
|
|
return;
|
|
}
|
|
|
|
if (size == m_tailSize) {
|
|
return;
|
|
}
|
|
|
|
if (!logFile.seek(m_tailSize)) {
|
|
return;
|
|
}
|
|
|
|
QByteArray delta = logFile.read(size - m_tailSize);
|
|
const qsizetype lastNewline = delta.lastIndexOf('\n');
|
|
if (lastNewline < 0) {
|
|
return;
|
|
}
|
|
delta.truncate(lastNewline + 1);
|
|
m_tailSize += delta.size();
|
|
|
|
const QString text = QString::fromUtf8(delta);
|
|
m_lastText += text;
|
|
if (m_lastText.size() > kLiveTailTextLimit) {
|
|
emit reloadRequired();
|
|
return;
|
|
}
|
|
emit appended(text);
|
|
}
|
|
|
|
void LogsUiController::onApplicationStateChanged(Qt::ApplicationState state)
|
|
{
|
|
if (!m_liveTailEnabled) {
|
|
return;
|
|
}
|
|
|
|
if (state == Qt::ApplicationHidden || state == Qt::ApplicationSuspended) {
|
|
m_liveTailTimer.stop();
|
|
return;
|
|
}
|
|
|
|
if (!m_liveTailTimer.isActive()) {
|
|
m_liveTailTimer.start();
|
|
emit reloadRequired();
|
|
}
|
|
}
|