Skip to content
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

add manual mode which does not touch system proxy #15

Open
wants to merge 1 commit into
base: master
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
2 changes: 2 additions & 0 deletions src/GuiConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ void GuiConfig::updateLastUsed() {
GuiConfig::GuiConfig() {
guiConfig.insert("strategy", "");
guiConfig.insert("index", 3);
guiConfig.insert("auto", false);
guiConfig.insert("global", false);
guiConfig.insert("manual", true);
guiConfig.insert("localPort", 1080);
guiConfig.insert("enabled", true);
guiConfig.insert("shareOverLan", false);
Expand Down
48 changes: 36 additions & 12 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ MainWindow::MainWindow(QWidget *parent) :
systemProxyModeManager = new DDEProxyModeManager(this);
if (guiConfig->get("enabled").toBool()) {
on_actionEnable_System_Proxy_triggered(true);
if (guiConfig->get("global").toBool()) {
switchToGlobal();
} else {
switchToPacMode();
}
}
in = 0;
out = 0;
Expand Down Expand Up @@ -175,8 +170,10 @@ void MainWindow::updateTrayIcon() {
out = 0;
if (!GuiConfig::instance()->get("enabled").toBool()) {
icon.append("_none");
} else if (GuiConfig::instance()->get("global").toBool()) {
} else if (GuiConfig::instance()->get("manual").toBool()) {
icon.append("_manual");
} else if (GuiConfig::instance()->get("global").toBool()) {
icon.append("_global");
} else {
icon.append("_auto");
}
Expand Down Expand Up @@ -277,12 +274,20 @@ void MainWindow::updateMenu() {
ui->actionEnable_System_Proxy->setChecked(false);
ui->menuMode->setEnabled(false);
}
if (guiConfig->get("auto").toBool()) {
ui->actionPAC->setChecked(true);
ui->actionGlobal->setChecked(false);
ui->actionManual->setChecked(false);
}
if (guiConfig->get("global").toBool()) {
ui->actionPAC->setChecked(false);
ui->actionGlobal->setChecked(true);
ui->actionManual->setChecked(false);
}
if (guiConfig->get("manual").toBool()) {
ui->actionPAC->setChecked(false);
} else {
ui->actionGlobal->setChecked(false);
ui->actionPAC->setChecked(true);
ui->actionManual->setChecked(true);
}
if (guiConfig->get("useOnlinePac").toBool()) {
ui->actionOnline_PAC->setChecked(true);
Expand Down Expand Up @@ -381,9 +386,12 @@ void MainWindow::on_actionEnable_System_Proxy_triggered(bool flag) {
guiConfig->updateLastUsed();
proxyManager->setConfig(config);
proxyManager->start();
if(guiConfig->get("global").toBool()){
if(guiConfig->get("manual").toBool()){
systemProxyModeManager->switchToNone();
updateMenu();
} else if(guiConfig->get("global").toBool()){
switchToGlobal();
} else{
} else if(guiConfig->get("auto").toBool()){
switchToPacMode();
}
}
Expand All @@ -395,8 +403,10 @@ void MainWindow::on_actionEnable_System_Proxy_triggered(bool flag) {
void MainWindow::on_actionPAC_triggered(bool checked) {
qDebug() << "pac" << checked;
auto guiConfig = GuiConfig::instance();
if (guiConfig->get("global").toBool() == checked) {
guiConfig->set("global", !checked);
guiConfig->set("manual", !checked);
guiConfig->set("global", !checked);
if (guiConfig->get("auto").toBool() != checked) {
guiConfig->set("auto", checked);
switchToPacMode();
}
updateMenu();
Expand All @@ -405,13 +415,27 @@ void MainWindow::on_actionPAC_triggered(bool checked) {
void MainWindow::on_actionGlobal_triggered(bool checked) {
qDebug() << "global" << checked;
auto guiConfig = GuiConfig::instance();
guiConfig->set("auto", !checked);
guiConfig->set("manual", !checked);
if (guiConfig->get("global").toBool() != checked) {
guiConfig->set("global", checked);
switchToGlobal();
}
updateMenu();
}

void MainWindow::on_actionManual_triggered(bool checked) {
qDebug() << "manual" << checked;
auto guiConfig = GuiConfig::instance();
guiConfig->set("auto", !checked);
guiConfig->set("global", !checked);
if (guiConfig->get("manual").toBool() != checked) {
guiConfig->set("manual", checked);
systemProxyModeManager->switchToNone();
}
updateMenu();
}

void MainWindow::on_actionStart_on_Boot_triggered(bool checked) {
// 如果使用flatpak,这里可能有问题
QString url = "/usr/share/applications/shadowsocks-deepin.desktop";
Expand Down
4 changes: 4 additions & 0 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ private slots:

void on_actionGlobal_triggered(bool checked);

void on_actionManual_triggered(bool checked);

void updateTrayIcon();

void on_actionStart_on_Boot_triggered(bool checked);
Expand Down Expand Up @@ -119,6 +121,8 @@ private slots:

void switchToGlobal();

void switchToManual();

// QWidget interface
protected:
void contextMenuEvent(QContextMenuEvent *event) override;
Expand Down
9 changes: 9 additions & 0 deletions src/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
</property>
<addaction name="actionPAC"/>
<addaction name="actionGlobal"/>
<addaction name="actionManual"/>
</widget>
<widget class="QMenu" name="menuServers">
<property name="title">
Expand Down Expand Up @@ -113,6 +114,14 @@
<string>Global</string>
</property>
</action>
<action name="actionManual">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Manual</string>
</property>
</action>
<action name="actionEdit_Servers">
<property name="text">
<string>Edit Servers...</string>
Expand Down
83 changes: 10 additions & 73 deletions src/Resources/ssw_auto128.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions src/Resources/ssw_global128.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 9 additions & 10 deletions src/Resources/ssw_in_auto128.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading