diff --git a/NetworkManagerP2P/src/SignalHandler.cpp b/NetworkManagerP2P/src/SignalHandler.cpp index 35357cc..f1fe2fc 100644 --- a/NetworkManagerP2P/src/SignalHandler.cpp +++ b/NetworkManagerP2P/src/SignalHandler.cpp @@ -20,7 +20,7 @@ static int ToOsSignalType(SignalHandler::SignalType signalType) case SignalHandler::Hangup: result = SIGHUP; break; default: - throw std::runtime_error("INvalid signal type"); + throw std::runtime_error("Invalid signal type"); } return result; } diff --git a/react/src/AppThemed.tsx b/react/src/AppThemed.tsx index 4845347..f158d4c 100644 --- a/react/src/AppThemed.tsx +++ b/react/src/AppThemed.tsx @@ -36,7 +36,9 @@ import FullscreenIcon from '@mui/icons-material/Fullscreen'; import FullscreenExitIcon from '@mui/icons-material/FullscreenExit'; import List from '@mui/material/List'; import Divider from '@mui/material/Divider'; -import ListItem from '@mui/material/ListItem'; +// import ListItem from '@mui/material/ListItem'; +import ListItemButton from '@mui/material/ListItemButton'; + import ListItemIcon from '@mui/material/ListItemIcon'; import ListItemText from '@mui/material/ListItemText'; import CircularProgress from '@mui/material/CircularProgress'; @@ -403,7 +405,8 @@ const AppThemed = withStyles(appStyles)(class extends ResizeResponsiveComponent< return false; } - onOpenBank(bankId: number) { + handleSpecificBank(bankId: number) { + this.model_.openBank(bankId) .catch((error) => this.model_.showAlert(error.toString())); @@ -491,17 +494,15 @@ const AppThemed = withStyles(appStyles)(class extends ResizeResponsiveComponent< } handleDrawerSelectBank() { + this.setState({ - isDrawerOpen: false, bankDialogOpen: true, editBankDialogOpen: false }); } handleDrawerDonationClick() { - this.setState({ - isDrawerOpen: false, - }); + this.hideDrawer(false); if (this.model_.isAndroidHosted()) { this.model_.showAndroidDonationActivity(); } else { @@ -514,14 +515,12 @@ const AppThemed = withStyles(appStyles)(class extends ResizeResponsiveComponent< handleDrawerAboutClick() { this.setState({ - isDrawerOpen: false, aboutDialogOpen: true }); } handleDrawerRenameBank() { this.setState({ - isDrawerOpen: false, renameBankDialogOpen: true, saveBankAsDialogOpen: false }); @@ -529,7 +528,6 @@ const AppThemed = withStyles(appStyles)(class extends ResizeResponsiveComponent< } handleDrawerSaveBankAs() { this.setState({ - isDrawerOpen: false, renameBankDialogOpen: false, saveBankAsDialogOpen: true }); @@ -657,6 +655,8 @@ const AppThemed = withStyles(appStyles)(class extends ResizeResponsiveComponent< let bankEntries = Math.floor((height - K) / ENTRY_HEIGHT); if (bankEntries < 1) bankEntries = 1; if (bankEntries > 7) bankEntries = 7; + if (bankEntries === 2) bankEntries = 1; + this.setState({ bankDisplayItems: bankEntries }); } @@ -686,27 +686,35 @@ const AppThemed = withStyles(appStyles)(class extends ResizeResponsiveComponent< } shortBankList(banks: BankIndex): BankIndexEntry[] { - let n = this.state.bankDisplayItems; + let nDisplayEntries = this.state.bankDisplayItems; let entries = banks.entries; - if (entries.length < n + 1) { // +1 for the .... entry. - return entries; - } + let nListEntries = entries.length; + let result: BankIndexEntry[] = []; - let selectedIndex = -1; - for (let i = 0; i < entries.length; ++i) { - if (entries[i].instanceId === banks.selectedBank) { - selectedIndex = i; - break; - } - } - if (n > entries.length) n = entries.length; - if (selectedIndex > n) { - for (let i = 0; i < n - 1; ++i) { + + if (nListEntries <= nDisplayEntries) + { + for (let i = 0; i < nListEntries; ++i) { result.push(entries[i]); } - result.push(entries[selectedIndex]); } else { - for (let i = 0; i < n; ++i) { + // a subset of the list CENTERED on the currently selected entry. + let selectedIndex = 0; + for (let i = 0; i < nListEntries; ++i) { + if (entries[i].instanceId === banks.selectedBank) { + selectedIndex = i; + break; + } + } + + let minN = selectedIndex-Math.floor(nDisplayEntries/2); + if (minN < 0) minN = 0; + let maxN = minN + nDisplayEntries; + if (maxN > entries.length) { + maxN = entries.length; + } + for (let i = minN; i < maxN; ++i) + { result.push(entries[i]); } } @@ -831,11 +839,11 @@ const AppThemed = withStyles(appStyles)(class extends ResizeResponsiveComponent< )} { this.hideDrawer(); }} > + is_open={this.state.isDrawerOpen} onClose={() => { this.hideDrawer(false); }} > - { + { ev.stopPropagation(); this.hideDrawer(true); this.setState({ performanceView: true }); @@ -844,7 +852,7 @@ const AppThemed = withStyles(appStyles)(class extends ResizeResponsiveComponent< - + { return ( - this.onOpenBank(bank.instanceId)} + { + ev.stopPropagation(); + this.hideDrawer(false); + this.handleSpecificBank(bank.instanceId); + }} > - + ); }) } { showBankSelectDialog && ( - { + { ev.stopPropagation(); this.hideDrawer(true); this.handleDrawerSelectBank(); @@ -877,7 +889,7 @@ const AppThemed = withStyles(appStyles)(class extends ResizeResponsiveComponent< > - + ) @@ -885,8 +897,8 @@ const AppThemed = withStyles(appStyles)(class extends ResizeResponsiveComponent< - { + { ev.stopPropagation(); this.hideDrawer(true); this.handleDrawerRenameBank() @@ -895,9 +907,9 @@ const AppThemed = withStyles(appStyles)(class extends ResizeResponsiveComponent< - - { + + { ev.stopPropagation(); this.hideDrawer(true); this.handleDrawerSaveBankAs(); @@ -906,9 +918,9 @@ const AppThemed = withStyles(appStyles)(class extends ResizeResponsiveComponent< - - { + + { ev.stopPropagation(); this.hideDrawer(true); this.handleDrawerManageBanks(); @@ -917,12 +929,12 @@ const AppThemed = withStyles(appStyles)(class extends ResizeResponsiveComponent< - + - { + { ev.stopPropagation(); this.hideDrawer(true); this.handleDrawerSettingsClick() @@ -931,9 +943,9 @@ const AppThemed = withStyles(appStyles)(class extends ResizeResponsiveComponent< - - { + + { ev.stopPropagation(); this.hideDrawer(true); this.handleDrawerAboutClick(); @@ -942,18 +954,17 @@ const AppThemed = withStyles(appStyles)(class extends ResizeResponsiveComponent< - - { + + { ev.stopPropagation(); - this.hideDrawer(true); this.handleDrawerDonationClick(); }}> - + diff --git a/src/AvahiService.cpp b/src/AvahiService.cpp index 02f54cc..b56d432 100644 --- a/src/AvahiService.cpp +++ b/src/AvahiService.cpp @@ -482,8 +482,8 @@ void AvahiService::Wait() { default: case ServiceState::Unitialized: - throw std::runtime_error("Invalid state"); - + done = true; + break; case ServiceState::Initializing: case ServiceState::Settling: case ServiceState::Requested: @@ -503,6 +503,8 @@ void AvahiService::Wait() if (clock::now() > waitTime) { Lv2Log::error("DNS/SD announcement timed out."); + done = true; + break; } std::this_thread::sleep_for(std::chrono::milliseconds(20)); diff --git a/src/ConfigMain.cpp b/src/ConfigMain.cpp index 9c953ca..6b5e159 100644 --- a/src/ConfigMain.cpp +++ b/src/ConfigMain.cpp @@ -155,6 +155,49 @@ void DisableService() #endif } +bool disableAvahiConfigLine(SystemConfigFile &avahi, const std::string §ion, const std::string &lineStart) +{ + bool changed = false; + // use-ipv6=no + int line = avahi.GetLineThatStartsWith(lineStart + "yes"); + if (line != -1) + { + avahi.UndoableReplaceLine(line, lineStart + "no"); + changed = true; + } + else + { + if (avahi.GetLineThatStartsWith(lineStart + "no") == -1) + { + line = avahi.GetLineThatStartsWith(section); + if (line == -1) + { + throw std::runtime_error("Unable to find [server] section."); + } + { + ++line; + // increment to end of section. + while (line < avahi.GetLineCount()) + { + const auto &txt = avahi.Get(line); + if (txt.empty()) + { + break; + } + if (txt.starts_with("[")) // start of next section. + { + break; + } + ++line; + } + } + avahi.UndoableAddLine(line,lineStart+"no"); + changed = true; + } + } + return changed; +} + static void RestartAvahiService() { silentSysExec(SS(SYSTEMCTL_BIN << " restart avahi-daemon.service").c_str()); @@ -169,41 +212,10 @@ static void AvahiInstall() SystemConfigFile avahi(avahiConfig); bool changed = avahi.RemoveUndoableActions(); - int line = avahi.GetLineThatStartsWith("use-ipv6=yes"); - if (line != -1) - { - avahi.UndoableReplaceLine(line, "use-ipv6=no"); - changed = true; - } - else - { - if (avahi.GetLineThatStartsWith("use-ipv6=no") == -1) - { - line = avahi.GetLineThatStartsWith("[server]"); - if (line == 1) - { - throw std::runtime_error("Unable to find [server] section."); - } - { - // increment to end of section. - while (line < avahi.GetLineCount()) - { - const auto &txt = avahi.Get(line); - if (txt.empty()) - { - break; - } - if (txt.starts_with("[")) // start of next section. - { - break; - } - ++line; - } - } - avahi.UndoableAddLine(avahi.GetLineCount(), "use-ipv6=no"); - changed = true; - } - } + + changed |= disableAvahiConfigLine(avahi, "[server]", "use-ipv6="); + changed |= disableAvahiConfigLine(avahi, "[publish]", "publish-aaaa-on-ipv4="); + if (changed) { avahi.Save(); @@ -914,7 +926,7 @@ void Install(const fs::path &programPrefix, const std::string endpointAddress) try { // apply policy changes we dropped into the polkit configuration files (allows pipedal_d to use NetworkManager dbus apis). - silentSysExec(SYSTEMCTL_BIN " restart polkit"); + silentSysExec(SYSTEMCTL_BIN " restart polkit"); DeployVarConfig(); @@ -995,7 +1007,6 @@ void Install(const fs::path &programPrefix, const std::string endpointAddress) // add to netdev group sysExec(USERMOD_BIN " -a -G " NETDEV_GROUP_NAME " " SERVICE_ACCOUNT_NAME); - // create and configure /var directory. fs::path varDirectory("/var/pipedal"); @@ -1211,11 +1222,11 @@ static void PrintHelp() << "\n\n" << "One of the following hotspot options can be specifed. If no hotspot option is given, the hotspot will always be enabled. " << "If one of the hotspot options are given, the PiPedal server will turn the hotspot on or off automatically, as conditions change." - << "\n\n" + << "\n\n" << "--home-network \n" << AddIndent(4) << "Hotspot is disabled if the specificed Wi-Fi network is detected.\n" << AddIndent(-4) - << "--no-ethernet\n" + << "--no-ethernet\n" << AddIndent(4) << "Hotspot is disabled if an ethernet network is connected.\n" << AddIndent(-4) << "--no-wifi\n" @@ -1336,9 +1347,9 @@ int main(int argc, char **argv) parser.AddOption("--port", &portOption); parser.AddOption("--enable-hotspot", &enable_hotspot); parser.AddOption("--disable-hotspot", &disable_hotspot); - parser.AddOption("--home-network",&homeNetwork); - parser.AddOption("--no-ethernet",&noEthernet); - parser.AddOption("--no-wifi",&noWifi); + parser.AddOption("--home-network", &homeNetwork); + parser.AddOption("--no-ethernet", &noEthernet); + parser.AddOption("--no-wifi", &noWifi); try { parser.Parse(argc, (const char **)argv); @@ -1367,9 +1378,7 @@ int main(int argc, char **argv) } } int hotspotOptionCount = - (homeNetwork.length() != 0 ? 1: 0) - + noEthernet - + noWifi; + (homeNetwork.length() != 0 ? 1 : 0) + noEthernet + noWifi; if (enable_hotspot) { @@ -1377,7 +1386,9 @@ int main(int argc, char **argv) { throw std::runtime_error("Only one hotspot option at a time can be specified."); } - } else { + } + else + { if (hotspotOptionCount > 0) { throw std::runtime_error("Hotspot options only only valid when the --enable-hotspot option has been supplied."); @@ -1432,7 +1443,8 @@ int main(int argc, char **argv) } if (install) { - try { + try + { fs::path prefix; if (prefixOption.length() != 0) { @@ -1465,8 +1477,8 @@ int main(int argc, char **argv) } Install(prefix, portOption); FileSystemSync(); - - } catch (const std::exception&e) + } + catch (const std::exception &e) { cout << "ERROR: " << e.what() << endl; FileSystemSync(); @@ -1475,10 +1487,12 @@ int main(int argc, char **argv) } else if (uninstall) { - try { + try + { Uninstall(); FileSystemSync(); - } catch (const std::exception &e) + } + catch (const std::exception &e) { cout << "ERROR: " << e.what() << endl; FileSystemSync(); @@ -1489,7 +1503,6 @@ int main(int argc, char **argv) { RequireNetworkManager(); StopService(); - } else if (start) { @@ -1506,14 +1519,12 @@ int main(int argc, char **argv) RequireNetworkManager(); EnableService(); FileSystemSync(); - } else if (disable) { RequireNetworkManager(); DisableService(); FileSystemSync(); - } else if (enable_p2p) { @@ -1541,8 +1552,7 @@ int main(int argc, char **argv) settings.Load(); settings.enable_ = false; SetWifiDirectConfig(settings); - - + RestartService(true); return EXIT_SUCCESS; } @@ -1557,15 +1567,17 @@ int main(int argc, char **argv) if (homeNetwork.length() != 0) { startMode = HotspotAutoStartMode::NotAtHome; - } else if (noEthernet) + } + else if (noEthernet) { startMode = HotspotAutoStartMode::NoEthernetConnection; - } else if (noWifi) + } + else if (noWifi) { startMode = HotspotAutoStartMode::NoRememberedWifiConections; } - settings.ParseArguments(argv,startMode,homeNetwork); + settings.ParseArguments(argv, startMode, homeNetwork); if (settings.hasPassword_) {