Skip to content

Standardize macOS detection and prompt on close #1153

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

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ build-*
*.DS_Store
userdata.ini
Info_Mac.plist
/ci/build_temp
/ci/build_temp
.vscode/
.gitignore
.gitmodules
.cache/
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "QtScrcpy/QtScrcpyCore"]
path = QtScrcpy/QtScrcpyCore
url = git@github.com:barry-ran/QtScrcpyCore.git
url = https://github.com/barry-ran/QtScrcpyCore.git
27 changes: 19 additions & 8 deletions QtScrcpy/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int main(int argc, char *argv[])
qputenv("QTSCRCPY_CONFIG_PATH", "../../../config");
#endif

#ifdef Q_OS_OSX
#ifdef Q_OS_MACOS
qputenv("QTSCRCPY_ADB_PATH", "../../../../../../QtScrcpy/QtScrcpyCore/src/third_party/adb/mac/adb");
qputenv("QTSCRCPY_SERVER_PATH", "../../../../../../QtScrcpy/QtScrcpyCore/src/third_party/scrcpy-server");
qputenv("QTSCRCPY_KEYMAP_PATH", "../../../../../../keymap");
Expand Down Expand Up @@ -58,7 +58,7 @@ int main(int argc, char *argv[])
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#endif
#endif
Expand Down Expand Up @@ -92,7 +92,7 @@ int main(int argc, char *argv[])
}

installTranslator();
#if defined(Q_OS_WIN32) || defined(Q_OS_OSX)
#if defined(Q_OS_WIN32) || defined(Q_OS_MACOS)
MouseTap::getInstance()->initMouseEventTap();
#endif

Expand All @@ -108,20 +108,25 @@ int main(int argc, char *argv[])

qsc::AdbProcess::setAdbPath(Config::getInstance().getAdbPath());

g_mainDlg = new Dialog {};
g_mainDlg = new Dialog{};
g_mainDlg->show();

qInfo() << QObject::tr("This software is completely open source and free. Use it at your own risk. You can download it at the "
"following address:");
"following address:");
qInfo() << QString("QtScrcpy %1 <https://github.com/barry-ran/QtScrcpy>").arg(QCoreApplication::applicationVersion());

qInfo() << QObject::tr("If you need more professional screen projection control software, you can try the following software:");
qInfo() << QObject::tr("If you need more professional batch control mirror software, you can try the following software:");
qInfo() << QString(QObject::tr("QuickMirror") + " <https://lrbnfell4p.feishu.cn/drive/folder/KviYfz5uFlpUT8dXgdjccmfUnse>");

qInfo() << QObject::tr("If you need more professional game keymap mirror software, you can try the following software:");
qInfo() << QString(QObject::tr("QuickAssistant") + " <https://lrbnfell4p.feishu.cn/drive/folder/Hqckfxj5el1Wjpd9uezcX71lnBh>");

qInfo() << QObject::tr("You can contact me with telegram <https://t.me/+Ylf_5V_rDCMyODQ1>");

int ret = a.exec();
delete g_mainDlg;

#if defined(Q_OS_WIN32) || defined(Q_OS_OSX)
#if defined(Q_OS_WIN32) || defined(Q_OS_MACOS)
MouseTap::getInstance()->quitMouseEventTap();
#endif
return ret;
Expand All @@ -132,7 +137,13 @@ void installTranslator()
static QTranslator translator;
QLocale locale;
QLocale::Language language = locale.language();
//language = QLocale::English;

if (Config::getInstance().getLanguage() == "zh_CN") {
language = QLocale::Chinese;
} else if (Config::getInstance().getLanguage() == "en_US") {
language = QLocale::English;
}

QString languagePath = ":/i18n/";
switch (language) {
case QLocale::Chinese:
Expand Down
Binary file modified QtScrcpy/res/i18n/en_US.qm
Binary file not shown.
24 changes: 20 additions & 4 deletions QtScrcpy/res/i18n/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,37 @@
<source>select path</source>
<translation>select path</translation>
</message>
<message>
<source>Clear History</source>
<translation>Clear History</translation>
</message>
</context>
<context>
<name>QObject</name>
<message>
<source>This software is completely open source and free. Use it at your own risk. You can download it at the following address:</source>
<translation>This software is completely open source and free. Use it at your own risk. You can download it at the following address:</translation>
</message>
<message>
<source>If you need more professional screen projection control software, you can try the following software:</source>
<translation>If you need more professional screen projection control software, you can try the following software:</translation>
</message>
<message>
<source>QuickMirror</source>
<translation>QuickMirror</translation>
</message>
<message>
<source>If you need more professional batch control mirror software, you can try the following software:</source>
<translation>If you need more professional batch control mirror software, you can try the following software:</translation>
</message>
<message>
<source>If you need more professional game keymap mirror software, you can try the following software:</source>
<translation>If you need more professional game keymap mirror software, you can try the following software:</translation>
</message>
<message>
<source>QuickAssistant</source>
<translation>QuickAssistant</translation>
</message>
<message>
<source>You can contact me with telegram &lt;https://t.me/+Ylf_5V_rDCMyODQ1&gt;</source>
<translation>You can contact me with telegram &lt;https://t.me/+Ylf_5V_rDCMyODQ1&gt;</translation>
</message>
</context>
<context>
<name>ToolForm</name>
Expand Down
Binary file modified QtScrcpy/res/i18n/zh_CN.qm
Binary file not shown.
24 changes: 20 additions & 4 deletions QtScrcpy/res/i18n/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,37 @@
<source>select path</source>
<translation>选择路径</translation>
</message>
<message>
<source>Clear History</source>
<translation>清理历史</translation>
</message>
</context>
<context>
<name>QObject</name>
<message>
<source>This software is completely open source and free. Use it at your own risk. You can download it at the following address:</source>
<translation>本软件完全开源免费,作者不对使用该软件产生的一切后果负责。你可以在以下地址下载:</translation>
</message>
<message>
<source>If you need more professional screen projection control software, you can try the following software:</source>
<translation>如果你需要更加专业的投屏控制软件,可以尝试作者开发的商业版:</translation>
</message>
<message>
<source>QuickMirror</source>
<translation>极限投屏</translation>
</message>
<message>
<source>If you need more professional batch control mirror software, you can try the following software:</source>
<translation>如果你需要更专业的批量控制投屏软件,你可以尝试下面软件:</translation>
</message>
<message>
<source>If you need more professional game keymap mirror software, you can try the following software:</source>
<translation>如果你需要更专业的游戏映射投屏软件,你可以尝试下面软件:</translation>
</message>
<message>
<source>QuickAssistant</source>
<translation>极限手游助手</translation>
</message>
<message>
<source>You can contact me with telegram &lt;https://t.me/+Ylf_5V_rDCMyODQ1&gt;</source>
<translation>你可以通过QQ群联系我 &lt;901736468&gt;</translation>
</message>
</context>
<context>
<name>ToolForm</name>
Expand Down
111 changes: 99 additions & 12 deletions QtScrcpy/ui/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include <QRandomGenerator>
#include <QTime>
#include <QTimer>
#include <QDialog>
#include <QVBoxLayout>
#include <QRadioButton>
#include <QDialogButtonBox>

#include "config.h"
#include "dialog.h"
Expand Down Expand Up @@ -82,21 +86,21 @@ Dialog::Dialog(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
log = "ip not find, connect to wifi?";
break;
}
ui->deviceIpEdt->setText(ip);
ui->deviceIpEdt->setEditText(ip);
} else if (args.contains("ifconfig") && args.contains("wlan0")) {
QString ip = m_adb.getDeviceIPFromStdOut();
if (ip.isEmpty()) {
log = "ip not find, connect to wifi?";
break;
}
ui->deviceIpEdt->setText(ip);
ui->deviceIpEdt->setEditText(ip);
} else if (args.contains("ip -o a")) {
QString ip = m_adb.getDeviceIPByIpFromStdOut();
if (ip.isEmpty()) {
log = "ip not find, connect to wifi?";
break;
}
ui->deviceIpEdt->setText(ip);
ui->deviceIpEdt->setEditText(ip);
}
break;
}
Expand Down Expand Up @@ -164,6 +168,16 @@ void Dialog::initUI()
ui->lockOrientationBox->addItem("180");
ui->lockOrientationBox->addItem("270");
ui->lockOrientationBox->setCurrentIndex(0);

// 加载IP历史记录
loadIpHistory();

// 为deviceIpEdt添加右键菜单
if (ui->deviceIpEdt->lineEdit()) {
ui->deviceIpEdt->lineEdit()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->deviceIpEdt->lineEdit(), &QWidget::customContextMenuRequested,
this, &Dialog::showIpEditMenu);
}
}

void Dialog::updateBootConfig(bool toView)
Expand Down Expand Up @@ -216,6 +230,12 @@ void Dialog::updateBootConfig(bool toView)
config.autoUpdateDevice = ui->autoUpdatecheckBox->isChecked();
config.showToolbar = ui->showToolbar->isChecked();

// 保存当前IP到历史记录
QString currentIp = ui->deviceIpEdt->currentText().trimmed();
if (!currentIp.isEmpty()) {
saveIpHistory(currentIp);
}

Config::getInstance().setUserBootConfig(config);
}
}
Expand Down Expand Up @@ -275,13 +295,32 @@ void Dialog::slotActivated(QSystemTrayIcon::ActivationReason reason)

void Dialog::closeEvent(QCloseEvent *event)
{
this->hide();
if (!Config::getInstance().getTrayMessageShown()) {
Config::getInstance().setTrayMessageShown(true);
m_hideIcon->showMessage(tr("Notice"),
tr("Hidden here!"),
QSystemTrayIcon::Information,
3000);
// 弹出选择对话框
QDialog choiceDialog(this);
choiceDialog.setWindowTitle(tr("关闭选项"));
QVBoxLayout *layout = new QVBoxLayout(&choiceDialog);
QRadioButton *minimizeRadio = new QRadioButton(tr("最小化窗口"), &choiceDialog);
QRadioButton *exitRadio = new QRadioButton(tr("退出窗口"), &choiceDialog);
minimizeRadio->setChecked(true);
layout->addWidget(minimizeRadio);
layout->addWidget(exitRadio);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &choiceDialog);
layout->addWidget(buttonBox);
// 设置按钮为“确认”和“取消”
buttonBox->button(QDialogButtonBox::Ok)->setText(tr("确认"));
buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("取消"));
connect(buttonBox, &QDialogButtonBox::accepted, &choiceDialog, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, &choiceDialog, &QDialog::reject);
if (choiceDialog.exec() == QDialog::Accepted) {
if (minimizeRadio->isChecked()) {
this->hide();
if (!Config::getInstance().getTrayMessageShown()) {
Config::getInstance().setTrayMessageShown(true);
m_hideIcon->showMessage(tr("Notice"), tr("Hidden here!"), QSystemTrayIcon::Information, 3000);
}
} else {
qApp->quit();
}
}
event->ignore();
}
Expand Down Expand Up @@ -344,7 +383,7 @@ void Dialog::on_wirelessConnectBtn_clicked()
if (checkAdbRun()) {
return;
}
QString addr = ui->deviceIpEdt->text().trimmed();
QString addr = ui->deviceIpEdt->currentText().trimmed();
if (!ui->devicePortEdt->text().isEmpty()) {
addr += ":";
addr += ui->devicePortEdt->text().trimmed();
Expand All @@ -356,6 +395,12 @@ void Dialog::on_wirelessConnectBtn_clicked()
return;
}

// 保存IP历史记录 - 只保存IP部分,不包含端口
QString ip = addr.split(":").first();
if (!ip.isEmpty()) {
saveIpHistory(ip);
}

outLog("wireless connect...", false);
QStringList adbArgs;
adbArgs << "connect";
Expand Down Expand Up @@ -516,7 +561,7 @@ void Dialog::on_wirelessDisConnectBtn_clicked()
if (checkAdbRun()) {
return;
}
QString addr = ui->deviceIpEdt->text().trimmed();
QString addr = ui->deviceIpEdt->currentText().trimmed();
outLog("wireless disconnect...", false);
QStringList adbArgs;
adbArgs << "disconnect";
Expand Down Expand Up @@ -767,3 +812,45 @@ void Dialog::on_autoUpdatecheckBox_toggled(bool checked)
m_autoUpdatetimer.stop();
}
}

void Dialog::loadIpHistory()
{
QStringList ipList = Config::getInstance().getIpHistory();
ui->deviceIpEdt->clear();
ui->deviceIpEdt->addItems(ipList);
ui->deviceIpEdt->setContentsMargins(0, 0, 0, 0);

if (ui->deviceIpEdt->lineEdit()) {
ui->deviceIpEdt->lineEdit()->setMaxLength(128);
ui->deviceIpEdt->lineEdit()->setPlaceholderText("192.168.0.1");
}
}

void Dialog::saveIpHistory(const QString &ip)
{
if (ip.isEmpty()) {
return;
}

Config::getInstance().saveIpHistory(ip);

// 更新ComboBox
loadIpHistory();
ui->deviceIpEdt->setCurrentText(ip);
}

void Dialog::showIpEditMenu(const QPoint &pos)
{
QMenu *menu = ui->deviceIpEdt->lineEdit()->createStandardContextMenu();
menu->addSeparator();

QAction *clearHistoryAction = new QAction(tr("Clear History"), menu);
connect(clearHistoryAction, &QAction::triggered, this, [this]() {
Config::getInstance().clearIpHistory();
loadIpHistory();
});

menu->addAction(clearHistoryAction);
menu->exec(ui->deviceIpEdt->lineEdit()->mapToGlobal(pos));
delete menu;
}
4 changes: 4 additions & 0 deletions QtScrcpy/ui/dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ private slots:

void on_autoUpdatecheckBox_toggled(bool checked);

void showIpEditMenu(const QPoint &pos);

private:
bool checkAdbRun();
void initUI();
Expand All @@ -78,6 +80,8 @@ private slots:
int findDeviceFromeSerialBox(bool wifi);
quint32 getBitRate();
const QString &getServerPath();
void loadIpHistory();
void saveIpHistory(const QString &ip);

protected:
void closeEvent(QCloseEvent *event);
Expand Down
Loading