mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
updated desktop icon. rerouted all stdout and stderr logs to logfile
This commit is contained in:
@@ -115,7 +115,7 @@ jobs:
|
||||
"$STAGING/install_nearby_file_share.sh"
|
||||
install -m 0644 sharing/linux/qml_tray_app/nearby-file-share.desktop \
|
||||
"$STAGING/share/applications/nearby-file-share.desktop"
|
||||
install -m 0644 sharing/linux/qml_tray_app/tray_icon.png \
|
||||
install -m 0644 sharing/linux/qml_tray_app/nearby-linux-desktop.png \
|
||||
"$STAGING/share/icons/hicolor/256x256/apps/nearby-file-share.png"
|
||||
install -m 0644 sharing/linux/nearby_sharing_api.h \
|
||||
"$STAGING/include/sharing/linux/nearby_sharing_api.h"
|
||||
|
||||
@@ -8,7 +8,7 @@ app for file sharing via Nearby Sharing, wired to:
|
||||
- Receive mode (incoming requests + accept/reject)
|
||||
- Transfer status list (progress + transfer status)
|
||||
- Persistent tray behavior (window close hides app to tray)
|
||||
- File logging to `/tmp/nearby_qml_file_tray.log`
|
||||
- Process log redirection to file (`stdout`/`stderr`)
|
||||
|
||||
## Files
|
||||
|
||||
@@ -31,7 +31,10 @@ app for file sharing via Nearby Sharing, wired to:
|
||||
- Shows pending incoming transfer requests.
|
||||
- Lets you accept/reject incoming requests.
|
||||
- Transfers are shown with target, direction, status, and progress.
|
||||
- Logs are appended to `/tmp/nearby_qml_file_tray.log`.
|
||||
- `stdout` and `stderr` are redirected at startup to the configured `logPath`
|
||||
setting.
|
||||
- Default log path is `/tmp/nearby_qml_file_tray.log` when `logPath` is unset.
|
||||
- If `logPath` is changed from Settings, restart the app to apply redirection.
|
||||
|
||||
## Building
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
#include "file_share_tray_controller.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QFileInfo>
|
||||
#include <QMetaObject>
|
||||
#include <QSettings>
|
||||
#include <QSysInfo>
|
||||
#include <QTextStream>
|
||||
#include <QVariantMap>
|
||||
|
||||
namespace {
|
||||
@@ -26,15 +24,10 @@ FileShareTrayController::FileShareTrayController(QObject* parent)
|
||||
|
||||
LoadSettings();
|
||||
CreateService();
|
||||
ReopenLogFile();
|
||||
LogLine(QStringLiteral("Started file share tray controller"));
|
||||
}
|
||||
|
||||
FileShareTrayController::~FileShareTrayController() {
|
||||
stop();
|
||||
if (log_file_.isOpen()) {
|
||||
log_file_.close();
|
||||
}
|
||||
}
|
||||
|
||||
void FileShareTrayController::CreateService() {
|
||||
@@ -55,9 +48,6 @@ void FileShareTrayController::AttachServiceListeners() {
|
||||
QString::fromStdString(info.device_name),
|
||||
QStringLiteral("Unknown device"));
|
||||
UpsertTarget(info.id, name, info.is_incoming);
|
||||
LogLine(QStringLiteral("Target discovered id=%1 name=%2")
|
||||
.arg(info.id)
|
||||
.arg(name));
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
};
|
||||
@@ -70,9 +60,6 @@ void FileShareTrayController::AttachServiceListeners() {
|
||||
QString::fromStdString(info.device_name),
|
||||
QStringLiteral("Unknown device"));
|
||||
UpsertTarget(info.id, name, info.is_incoming);
|
||||
LogLine(QStringLiteral("Target updated id=%1 name=%2")
|
||||
.arg(info.id)
|
||||
.arg(name));
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
};
|
||||
@@ -82,7 +69,6 @@ void FileShareTrayController::AttachServiceListeners() {
|
||||
this,
|
||||
[this, share_target_id]() {
|
||||
RemoveTarget(share_target_id);
|
||||
LogLine(QStringLiteral("Target lost id=%1").arg(share_target_id));
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
};
|
||||
@@ -119,18 +105,7 @@ void FileShareTrayController::AttachServiceListeners() {
|
||||
NearbySharingApi::TransferStatus::kAwaitingLocalConfirmation) {
|
||||
if (auto_accept_incoming_) {
|
||||
service_->Accept(
|
||||
update.share_target_id,
|
||||
[this, id = update.share_target_id](
|
||||
NearbySharingApi::StatusCode result) {
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this, id, result]() {
|
||||
LogLine(QStringLiteral("Accept(%1): %2")
|
||||
.arg(id)
|
||||
.arg(StatusToString(result)));
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
});
|
||||
update.share_target_id, [](NearbySharingApi::StatusCode) {});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,7 +208,6 @@ void FileShareTrayController::setDeviceName(const QString& device_name) {
|
||||
device_name_ = trimmed;
|
||||
emit deviceNameChanged();
|
||||
SaveSettings();
|
||||
LogLine(QStringLiteral("Device name changed to %1").arg(device_name_));
|
||||
CreateService();
|
||||
|
||||
if (was_running) {
|
||||
@@ -254,7 +228,6 @@ void FileShareTrayController::setLogPath(const QString& path) {
|
||||
log_path_ = trimmed;
|
||||
emit logPathChanged();
|
||||
SaveSettings();
|
||||
ReopenLogFile();
|
||||
}
|
||||
|
||||
void FileShareTrayController::start() {
|
||||
@@ -280,33 +253,9 @@ void FileShareTrayController::stop() {
|
||||
running_ = false;
|
||||
emit runningChanged();
|
||||
|
||||
service_->StopSendMode([this](NearbySharingApi::StatusCode status) {
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this, status]() {
|
||||
LogLine(QStringLiteral("StopSendMode: %1").arg(StatusToString(status)));
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
});
|
||||
|
||||
service_->StopReceiveMode([this](NearbySharingApi::StatusCode status) {
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this, status]() {
|
||||
LogLine(
|
||||
QStringLiteral("StopReceiveMode: %1").arg(StatusToString(status)));
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
});
|
||||
|
||||
service_->Shutdown([this](NearbySharingApi::StatusCode status) {
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this, status]() {
|
||||
LogLine(QStringLiteral("Shutdown: %1").arg(StatusToString(status)));
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
});
|
||||
service_->StopSendMode([](NearbySharingApi::StatusCode) {});
|
||||
service_->StopReceiveMode([](NearbySharingApi::StatusCode) {});
|
||||
service_->Shutdown([](NearbySharingApi::StatusCode) {});
|
||||
|
||||
discovered_targets_.clear();
|
||||
discovered_row_by_target_.clear();
|
||||
@@ -333,7 +282,6 @@ void FileShareTrayController::switchToReceiveMode() {
|
||||
if (mode_ != QStringLiteral("Receive")) {
|
||||
mode_ = QStringLiteral("Receive");
|
||||
emit modeChanged();
|
||||
LogLine(QStringLiteral("Mode changed to Receive"));
|
||||
if (running_) {
|
||||
stop();
|
||||
start();
|
||||
@@ -372,7 +320,6 @@ void FileShareTrayController::switchToSendModeWithFile(const QString& file_path)
|
||||
if (mode_ != QStringLiteral("Send")) {
|
||||
mode_ = QStringLiteral("Send");
|
||||
emit modeChanged();
|
||||
LogLine(QStringLiteral("Mode changed to Send"));
|
||||
if (running_) {
|
||||
stop();
|
||||
start();
|
||||
@@ -416,9 +363,6 @@ void FileShareTrayController::sendPendingFileToTarget(qlonglong share_target_id)
|
||||
this,
|
||||
[this, share_target_id, status]() {
|
||||
const QString target_name = TargetName(share_target_id);
|
||||
LogLine(QStringLiteral("SendFile(%1): %2")
|
||||
.arg(share_target_id)
|
||||
.arg(StatusToString(status)));
|
||||
if (status == NearbySharingApi::StatusCode::kOk) {
|
||||
SetStatus(QStringLiteral("Sending %1 to %2")
|
||||
.arg(pending_send_file_name_, target_name));
|
||||
@@ -455,7 +399,6 @@ void FileShareTrayController::startSendMode() {
|
||||
this,
|
||||
[this, status]() {
|
||||
SetStatus(QStringLiteral("StartSendMode: %1").arg(StatusToString(status)));
|
||||
LogLine(QStringLiteral("StartSendMode: %1").arg(StatusToString(status)));
|
||||
if (status != NearbySharingApi::StatusCode::kOk) {
|
||||
running_ = false;
|
||||
emit runningChanged();
|
||||
@@ -472,8 +415,6 @@ void FileShareTrayController::startReceiveMode() {
|
||||
[this, status]() {
|
||||
SetStatus(
|
||||
QStringLiteral("StartReceiveMode: %1").arg(StatusToString(status)));
|
||||
LogLine(
|
||||
QStringLiteral("StartReceiveMode: %1").arg(StatusToString(status)));
|
||||
if (status != NearbySharingApi::StatusCode::kOk) {
|
||||
running_ = false;
|
||||
emit runningChanged();
|
||||
@@ -570,7 +511,6 @@ void FileShareTrayController::SetStatus(const QString& status) {
|
||||
}
|
||||
status_message_ = status;
|
||||
emit statusMessageChanged();
|
||||
LogLine(QStringLiteral("Status: %1").arg(status_message_));
|
||||
}
|
||||
|
||||
bool FileShareTrayController::HasActiveTransfers() const {
|
||||
@@ -587,28 +527,6 @@ bool FileShareTrayController::HasActiveTransfers() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void FileShareTrayController::LogLine(const QString& line) {
|
||||
if (!log_file_.isOpen()) {
|
||||
ReopenLogFile();
|
||||
}
|
||||
if (!log_file_.isOpen()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QTextStream stream(&log_file_);
|
||||
stream << QDateTime::currentDateTimeUtc().toString(Qt::ISODate) << " " << line
|
||||
<< "\n";
|
||||
stream.flush();
|
||||
}
|
||||
|
||||
void FileShareTrayController::ReopenLogFile() {
|
||||
if (log_file_.isOpen()) {
|
||||
log_file_.close();
|
||||
}
|
||||
log_file_.setFileName(log_path_);
|
||||
log_file_.open(QIODevice::Append | QIODevice::Text | QIODevice::WriteOnly);
|
||||
}
|
||||
|
||||
QString FileShareTrayController::StatusToString(NearbySharingApi::StatusCode status) {
|
||||
return QString::fromStdString(NearbySharingApi::StatusCodeToString(status));
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <QFile>
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
@@ -99,8 +98,6 @@ class FileShareTrayController : public QObject {
|
||||
|
||||
void SetStatus(const QString& status);
|
||||
bool HasActiveTransfers() const;
|
||||
void LogLine(const QString& line);
|
||||
void ReopenLogFile();
|
||||
|
||||
static QString StatusToString(NearbySharingApi::StatusCode status);
|
||||
static QString TransferStatusToString(NearbySharingApi::TransferStatus status);
|
||||
@@ -127,8 +124,6 @@ class FileShareTrayController : public QObject {
|
||||
|
||||
QVariantList transfers_;
|
||||
QHash<qlonglong, int> transfer_row_by_target_;
|
||||
|
||||
QFile log_file_;
|
||||
};
|
||||
|
||||
#endif // SHARING_LINUX_QML_TRAY_APP_FILE_SHARE_TRAY_CONTROLLER_H_
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#include <QIcon>
|
||||
#include <QMenu>
|
||||
#include <QPainter>
|
||||
@@ -8,13 +11,70 @@
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include <QQuickWindow>
|
||||
#include <QSettings>
|
||||
#include <QStyleHints>
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "file_share_tray_controller.h"
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr char kDefaultLogPath[] = "/tmp/nearby_qml_file_tray.log";
|
||||
|
||||
bool EnsureLogDirectory(const QString& file_path) {
|
||||
const QFileInfo file_info(file_path);
|
||||
QDir directory = file_info.absoluteDir();
|
||||
if (directory.exists()) {
|
||||
return true;
|
||||
}
|
||||
return directory.mkpath(QStringLiteral("."));
|
||||
}
|
||||
|
||||
bool RedirectStdStreamsToFile(const QString& file_path) {
|
||||
const QByteArray encoded_path = QFile::encodeName(file_path);
|
||||
const int fd = ::open(encoded_path.constData(), O_CREAT | O_APPEND | O_WRONLY, 0644);
|
||||
if (fd < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool redirected_stdout = ::dup2(fd, STDOUT_FILENO) >= 0;
|
||||
const bool redirected_stderr = ::dup2(fd, STDERR_FILENO) >= 0;
|
||||
::close(fd);
|
||||
return redirected_stdout && redirected_stderr;
|
||||
}
|
||||
|
||||
QString ResolveConfiguredLogPath() {
|
||||
QSettings settings(QStringLiteral("Nearby"), QStringLiteral("QmlFileTrayApp"));
|
||||
const QString configured_path =
|
||||
settings.value(QStringLiteral("logPath"),
|
||||
QString::fromLatin1(kDefaultLogPath))
|
||||
.toString()
|
||||
.trimmed();
|
||||
if (configured_path.isEmpty()) {
|
||||
return QString::fromLatin1(kDefaultLogPath);
|
||||
}
|
||||
return configured_path;
|
||||
}
|
||||
|
||||
void RedirectProcessLogsToConfiguredPath() {
|
||||
QString log_path = ResolveConfiguredLogPath();
|
||||
if (EnsureLogDirectory(log_path) && RedirectStdStreamsToFile(log_path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QString fallback_path = QString::fromLatin1(kDefaultLogPath);
|
||||
if (log_path == fallback_path) {
|
||||
return;
|
||||
}
|
||||
if (!EnsureLogDirectory(fallback_path)) {
|
||||
return;
|
||||
}
|
||||
RedirectStdStreamsToFile(fallback_path);
|
||||
}
|
||||
|
||||
QIcon BuildTintedSymbolicIcon(const QString& source, const QColor& color) {
|
||||
QIcon source_icon(source);
|
||||
if (source_icon.isNull()) {
|
||||
@@ -46,6 +106,8 @@ QIcon BuildTintedSymbolicIcon(const QString& source, const QColor& color) {
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
RedirectProcessLogsToConfiguredPath();
|
||||
|
||||
QApplication app(argc, argv);
|
||||
app.setQuitOnLastWindowClosed(false);
|
||||
|
||||
|
||||
@@ -71,7 +71,12 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
BIN_SRC="$SCRIPT_DIR/bin/nearby_qml_file_tray_app"
|
||||
LIB_SRC="$SCRIPT_DIR/lib/libnearby_sharing_api_shared.so"
|
||||
DESKTOP_SRC="$SCRIPT_DIR/share/applications/nearby-file-share.desktop"
|
||||
ICON_SRC="$SCRIPT_DIR/share/icons/hicolor/256x256/apps/nearby-file-share.png"
|
||||
ICON_SRC_STAGED="$SCRIPT_DIR/share/icons/hicolor/256x256/apps/nearby-file-share.png"
|
||||
ICON_SRC_FALLBACK="$SCRIPT_DIR/nearby-linux-desktop.png"
|
||||
ICON_SRC="$ICON_SRC_STAGED"
|
||||
if [[ ! -f "$ICON_SRC" && -f "$ICON_SRC_FALLBACK" ]]; then
|
||||
ICON_SRC="$ICON_SRC_FALLBACK"
|
||||
fi
|
||||
HEADER_SRC="$SCRIPT_DIR/include/sharing/linux/nearby_sharing_api.h"
|
||||
|
||||
for required in "$BIN_SRC" "$LIB_SRC" "$DESKTOP_SRC" "$ICON_SRC"; do
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 45 KiB |
Reference in New Issue
Block a user