Skip to content

Commit

Permalink
feat: auto update device
Browse files Browse the repository at this point in the history
  • Loading branch information
barry-ran committed Jun 20, 2022
1 parent 8bef579 commit d77355a
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 16 deletions.
Binary file modified QtScrcpy/res/i18n/en_US.qm
Binary file not shown.
4 changes: 4 additions & 0 deletions QtScrcpy/res/i18n/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,5 +285,9 @@
<source>stop audio</source>
<translation>stop audio</translation>
</message>
<message>
<source>auto update</source>
<translation>autp update</translation>
</message>
</context>
</TS>
Binary file modified QtScrcpy/res/i18n/zh_CN.qm
Binary file not shown.
4 changes: 4 additions & 0 deletions QtScrcpy/res/i18n/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,5 +285,9 @@
<source>stop audio</source>
<translation>停止音频</translation>
</message>
<message>
<source>auto update</source>
<translation>自动刷新</translation>
</message>
</context>
</TS>
27 changes: 21 additions & 6 deletions QtScrcpy/ui/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ Dialog::Dialog(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
ui->setupUi(this);
initUI();

updateBootConfig(true);

on_useSingleModeCheck_clicked();
on_updateDevice_clicked();

connect(&m_autoUpdatetimer, &QTimer::timeout, this, &Dialog::on_updateDevice_clicked);
if (ui->autoUpdatecheckBox->isChecked()) {
m_autoUpdatetimer.start(5000);
}

connect(&m_adb, &qsc::AdbProcess::adbProcessResult, this, [this](qsc::AdbProcess::ADB_EXEC_RESULT processResult) {
QString log = "";
bool newLine = true;
Expand Down Expand Up @@ -145,12 +155,6 @@ void Dialog::initUI()
ui->lockOrientationBox->addItem("180");
ui->lockOrientationBox->addItem("270");
ui->lockOrientationBox->setCurrentIndex(0);

updateBootConfig(true);

on_useSingleModeCheck_clicked();

on_updateDevice_clicked();
}

void Dialog::updateBootConfig(bool toView)
Expand Down Expand Up @@ -181,6 +185,7 @@ void Dialog::updateBootConfig(bool toView)
ui->closeScreenCheck->setChecked(config.autoOffScreen);
ui->stayAwakeCheck->setChecked(config.keepAlive);
ui->useSingleModeCheck->setChecked(config.simpleMode);
ui->autoUpdatecheckBox->setChecked(config.autoUpdateDevice);
} else {
UserBootConfig config;

Expand All @@ -198,6 +203,7 @@ void Dialog::updateBootConfig(bool toView)
config.framelessWindow = ui->framelessCheck->isChecked();
config.keepAlive = ui->stayAwakeCheck->isChecked();
config.simpleMode = ui->useSingleModeCheck->isChecked();
config.autoUpdateDevice = ui->autoUpdatecheckBox->isChecked();
Config::getInstance().setUserBootConfig(config);
}
}
Expand Down Expand Up @@ -711,3 +717,12 @@ void Dialog::on_installSndcpyBtn_clicked()
}
m_audioOutput.installonly(ui->serialBox->currentText(), 28200);
}

void Dialog::on_autoUpdatecheckBox_toggled(bool checked)
{
if (checked) {
m_autoUpdatetimer.start(5000);
} else {
m_autoUpdatetimer.stop();
}
}
4 changes: 4 additions & 0 deletions QtScrcpy/ui/dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QMenu>
#include <QSystemTrayIcon>
#include <QListWidget>
#include <QTimer>


#include "adbprocess.h"
Expand Down Expand Up @@ -64,6 +65,8 @@ private slots:

void on_installSndcpyBtn_clicked();

void on_autoUpdatecheckBox_toggled(bool checked);

private:
bool checkAdbRun();
void initUI();
Expand All @@ -87,6 +90,7 @@ private slots:
QAction *m_showWindow;
QAction *m_quit;
AudioOutput m_audioOutput;
QTimer m_autoUpdatetimer;
};

#endif // DIALOG_H
37 changes: 27 additions & 10 deletions QtScrcpy/ui/dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,34 @@
</layout>
</item>
<item>
<widget class="QLabel" name="label_10">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Double click to connect:</string>
<layout class="QHBoxLayout" name="horizontalLayout_13">
<property name="topMargin">
<number>0</number>
</property>
</widget>
<item>
<widget class="QLabel" name="label_10">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Double click to connect:</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="autoUpdatecheckBox">
<property name="text">
<string>auto update</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QListWidget" name="connectedPhoneList">
Expand Down
5 changes: 5 additions & 0 deletions QtScrcpy/util/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
#define COMMON_SIMPLE_MODE_KEY "SimpleMode"
#define COMMON_SIMPLE_MODE_DEF false

#define COMMON_AUTO_UPDATE_DEVICE_KEY "AutoUpdateDevice"
#define COMMON_AUTO_UPDATE_DEVICE_DEF true

// device config
#define SERIAL_WINDOW_RECT_KEY_X "WindowRectX"
#define SERIAL_WINDOW_RECT_KEY_Y "WindowRectY"
Expand Down Expand Up @@ -145,6 +148,7 @@ void Config::setUserBootConfig(const UserBootConfig &config)
m_userData->setValue(COMMON_AUTO_OFF_SCREEN_KEY, config.autoOffScreen);
m_userData->setValue(COMMON_KEEP_ALIVE_KEY, config.keepAlive);
m_userData->setValue(COMMON_SIMPLE_MODE_KEY, config.simpleMode);
m_userData->setValue(COMMON_AUTO_UPDATE_DEVICE_KEY, config.autoUpdateDevice);
m_userData->endGroup();
m_userData->sync();
}
Expand All @@ -167,6 +171,7 @@ UserBootConfig Config::getUserBootConfig()
config.autoOffScreen = m_userData->value(COMMON_AUTO_OFF_SCREEN_KEY, COMMON_AUTO_OFF_SCREEN_DEF).toBool();
config.keepAlive = m_userData->value(COMMON_KEEP_ALIVE_KEY, COMMON_KEEP_ALIVE_DEF).toBool();
config.simpleMode = m_userData->value(COMMON_SIMPLE_MODE_KEY, COMMON_SIMPLE_MODE_DEF).toBool();
config.autoUpdateDevice = m_userData->value(COMMON_AUTO_UPDATE_DEVICE_KEY, COMMON_AUTO_UPDATE_DEVICE_DEF).toBool();
m_userData->endGroup();
return config;
}
Expand Down
1 change: 1 addition & 0 deletions QtScrcpy/util/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct UserBootConfig
bool framelessWindow = false;
bool keepAlive = false;
bool simpleMode = false;
bool autoUpdateDevice = true;
};

class QSettings;
Expand Down

0 comments on commit d77355a

Please sign in to comment.