mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 12:34:37 +03:00
fix profile manager
This commit is contained in:
@@ -57,12 +57,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||
};
|
||||
|
||||
// Load Manager
|
||||
auto isLoaded = NekoGui::profileManager->Load();
|
||||
if (!isLoaded) {
|
||||
auto defaultGroup = NekoGui::ProfileManager::NewGroup();
|
||||
defaultGroup->name = tr("Default");
|
||||
NekoGui::profileManager->AddGroup(defaultGroup);
|
||||
}
|
||||
NekoGui::profileManager->LoadManager();
|
||||
|
||||
// Setup misc UI
|
||||
themeManager->ApplyTheme(NekoGui::dataStore->theme);
|
||||
@@ -72,11 +67,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||
connect(ui->menu_stop, &QAction::triggered, this, [=]() { neko_stop(); });
|
||||
connect(ui->tabWidget->tabBar(), &QTabBar::tabMoved, this, [=](int from, int to) {
|
||||
// use tabData to track tab & gid
|
||||
NekoGui::profileManager->_groups.clear();
|
||||
NekoGui::profileManager->groupsTabOrder.clear();
|
||||
for (int i = 0; i < ui->tabWidget->tabBar()->count(); i++) {
|
||||
NekoGui::profileManager->_groups += ui->tabWidget->tabBar()->tabData(i).toInt();
|
||||
NekoGui::profileManager->groupsTabOrder += ui->tabWidget->tabBar()->tabData(i).toInt();
|
||||
}
|
||||
NekoGui::profileManager->Save();
|
||||
NekoGui::profileManager->SaveManager();
|
||||
});
|
||||
ui->label_running->installEventFilter(this);
|
||||
ui->label_inbound->installEventFilter(this);
|
||||
@@ -458,13 +453,13 @@ MainWindow::~MainWindow() {
|
||||
// Group tab manage
|
||||
|
||||
inline int tabIndex2GroupId(int index) {
|
||||
if (NekoGui::profileManager->_groups.length() <= index) return -1;
|
||||
return NekoGui::profileManager->_groups[index];
|
||||
if (NekoGui::profileManager->groupsTabOrder.length() <= index) return -1;
|
||||
return NekoGui::profileManager->groupsTabOrder[index];
|
||||
}
|
||||
|
||||
inline int groupId2TabIndex(int gid) {
|
||||
for (int key = 0; key < NekoGui::profileManager->_groups.count(); key++) {
|
||||
if (NekoGui::profileManager->_groups[key] == gid) return key;
|
||||
for (int key = 0; key < NekoGui::profileManager->groupsTabOrder.count(); key++) {
|
||||
if (NekoGui::profileManager->groupsTabOrder[key] == gid) return key;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -646,6 +641,7 @@ void MainWindow::on_commitDataRequest() {
|
||||
}
|
||||
//
|
||||
NekoGui::dataStore->Save();
|
||||
NekoGui::profileManager->SaveManager();
|
||||
qDebug() << "End of data save";
|
||||
}
|
||||
|
||||
@@ -903,7 +899,7 @@ void MainWindow::refresh_groups() {
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
for (const auto &gid: NekoGui::profileManager->_groups) {
|
||||
for (const auto &gid: NekoGui::profileManager->groupsTabOrder) {
|
||||
auto group = NekoGui::profileManager->GetGroup(gid);
|
||||
if (index == 0) {
|
||||
ui->tabWidget->setTabText(0, group->name);
|
||||
@@ -923,7 +919,7 @@ void MainWindow::refresh_groups() {
|
||||
if (NekoGui::profileManager->CurrentGroup() == nullptr) {
|
||||
NekoGui::dataStore->current_group = -1;
|
||||
ui->tabWidget->setCurrentIndex(groupId2TabIndex(0));
|
||||
show_group(NekoGui::profileManager->_groups.count() > 0 ? NekoGui::profileManager->_groups.first() : 0);
|
||||
show_group(NekoGui::profileManager->groupsTabOrder.count() > 0 ? NekoGui::profileManager->groupsTabOrder.first() : 0);
|
||||
} else {
|
||||
ui->tabWidget->setCurrentIndex(groupId2TabIndex(NekoGui::dataStore->current_group));
|
||||
show_group(NekoGui::dataStore->current_group);
|
||||
@@ -944,11 +940,11 @@ void MainWindow::refresh_proxy_list_impl(const int &id, GroupSortAction groupSor
|
||||
ui->proxyListTable->setRowCount(0);
|
||||
// 添加行
|
||||
int row = -1;
|
||||
for (const auto &profile: NekoGui::profileManager->profiles) {
|
||||
for (const auto &[id, profile]: NekoGui::profileManager->profiles) {
|
||||
if (NekoGui::dataStore->current_group != profile->gid) continue;
|
||||
row++;
|
||||
ui->proxyListTable->insertRow(row);
|
||||
ui->proxyListTable->row2Id += profile->id;
|
||||
ui->proxyListTable->row2Id += id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1121,7 +1117,7 @@ void MainWindow::on_menu_move_triggered() {
|
||||
if (ents.isEmpty()) return;
|
||||
|
||||
auto items = QStringList{};
|
||||
for (auto gid: NekoGui::profileManager->_groups) {
|
||||
for (auto gid: NekoGui::profileManager->groupsTabOrder) {
|
||||
auto group = NekoGui::profileManager->GetGroup(gid);
|
||||
if (group == nullptr) continue;
|
||||
items += Int2String(gid) + " " + group->name;
|
||||
@@ -1170,7 +1166,7 @@ void MainWindow::on_menu_profile_debug_info_triggered() {
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(QFileInfo(QString("profiles/%1.json").arg(ents.first()->id)).absoluteFilePath()));
|
||||
} else if (btn == 2) {
|
||||
NekoGui::dataStore->Load();
|
||||
NekoGui::profileManager->Load();
|
||||
NekoGui::profileManager->LoadManager();
|
||||
refresh_proxy_list();
|
||||
}
|
||||
}
|
||||
@@ -1398,7 +1394,7 @@ void MainWindow::on_menu_update_subscription_triggered() {
|
||||
void MainWindow::on_menu_remove_unavailable_triggered() {
|
||||
QList<std::shared_ptr<NekoGui::ProxyEntity>> out_del;
|
||||
|
||||
for (const auto &profile: NekoGui::profileManager->profiles) {
|
||||
for (const auto &[_, profile]: NekoGui::profileManager->profiles) {
|
||||
if (NekoGui::dataStore->current_group != profile->gid) continue;
|
||||
if (profile->latency < 0) out_del += profile;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user