Skip to content

Commit 7819fab

Browse files
authored
Merge pull request #357 from No0ne558/master
Fix Hardware button type: duplicate Server displays and startup bugs
2 parents 514283b + 1086299 commit 7819fab

3 files changed

Lines changed: 65 additions & 88 deletions

File tree

‎docs/changelog.md‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
77
## [Unreleased]
88

99
### Fixed
10+
- **Hardware Button Type: Simplified Server Display Logic (2026-02-05)**
11+
- Completely simplified the server display and terminal initialization logic
12+
- **New Approach**: The FIRST terminal in the list is ALWAYS the server display
13+
- **Changes Made**:
14+
- Rewrote `FindServer()` to simply return the first terminal and ensure it's marked as server
15+
- Simplified remote terminal initialization to skip the first terminal (server) and process others
16+
- Removed complex multi-pass server detection and matching logic
17+
- Removed `have_server` counting and display_host matching complexity
18+
- Added automatic cleanup of duplicate "Server" terminals created by previous buggy code
19+
- **Root Cause**: Previous complex logic with multiple passes, display_host matching, and server flag tracking was causing duplicate server displays to be created and persisted
20+
- **Solution**: Simple rule - first terminal = server, all others = remote displays. FindServer() now removes any duplicate auto-created "Server" terminals found after the first terminal.
21+
- **Impact**: No more duplicate server displays, existing duplicates are automatically cleaned up on startup
22+
- **Files modified**: `main/data/manager.cc`, `main/data/settings.cc`
23+
1024
- **Hardware Button Type: Critical Startup Bugs (2026-02-04)**
1125
- Fixed multiple critical bugs in Hardware button type that caused issues after system reboot
1226
- **Bug 1: Printer Deletion on Every Startup**
@@ -25,7 +39,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
2539
- **Root Cause**: `FindServer()` checked display_host match before IsServer flag, potentially returning wrong terminal
2640
- **Solution**: Changed to two-pass approach - first find explicit server, then check display_host match
2741
- **Impact**: Existing server terminal is always found first
28-
- **⚠️ KNOWN ISSUE**: Duplicate "Server" displays may still appear in some configurations - investigation ongoing
2942
- **Files modified**: `main/data/manager.cc`, `main/data/settings.cc`
3043

3144
- **Tender Settings Button Type: Null Pointer and Record Navigation Bugs (2026-02-04)**

‎main/data/manager.cc‎

Lines changed: 14 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,54 +1259,22 @@ int StartSystem(int my_use_net)
12591259
// for the local terminal.
12601260
int count = 0;
12611261
int allowed = num_terms - 1;
1262-
int have_server = settings->HaveServerTerm();
1262+
1263+
// The first terminal is always the server - handled by FindServer()
1264+
// Process all other terminals as remote displays
12631265
TermInfo *ti = settings->TermList();
1264-
if (have_server > 1)
1265-
{
1266-
// Multiple terminals are marked as server - keep only the first one
1267-
int found = 0;
1268-
while (ti != nullptr)
1269-
{
1270-
if (ti->IsServer())
1271-
{
1272-
if (found)
1273-
{
1274-
// Clear server flag on all but the first server found
1275-
ti->IsServer(0);
1276-
}
1277-
else
1278-
{
1279-
// First server found - update its display host and keep it
1280-
ti->display_host.Set(displaystr.data());
1281-
found = 1;
1282-
}
1283-
}
1284-
ti = ti->next;
1285-
}
1286-
// Save settings after cleaning up duplicate servers
1287-
settings->Save();
1288-
// Reset ti to the head of the list for the second loop
1289-
ti = settings->TermList();
1290-
}
1266+
if (ti != nullptr)
1267+
ti = ti->next; // Skip the first terminal (server)
1268+
12911269
while (ti != nullptr)
12921270
{
1293-
// this early, the TermInfo entry is the server entry if its
1294-
// isserver value is true or if display_host is equal to
1295-
// displaystr. So we only start up a remote terminal if
1296-
// IsServer() returns false and the two display strings do
1297-
// not match. Otherwise, we do a little background maintenance.
1298-
if (ti->display_host.empty() && have_server == 0)
1299-
{
1300-
ti->display_host.Set(displaystr.data());
1301-
ti->IsServer(1);
1302-
have_server = 1; // Update count to prevent setting another terminal as server
1303-
}
1304-
else if (ti->IsServer())
1305-
{
1306-
// make sure the server's display host value is current
1307-
ti->display_host.Set(displaystr.data());
1308-
}
1309-
else if (strcmp(ti->display_host.Value(), displaystr.data()) != 0)
1271+
// Clear any stale server flags on non-first terminals
1272+
if (ti->IsServer())
1273+
ti->IsServer(0);
1274+
1275+
// Open remote terminals that have a different display host
1276+
if (!ti->display_host.empty() &&
1277+
strcmp(ti->display_host.Value(), displaystr.data()) != 0)
13101278
{
13111279
if (count < allowed)
13121280
{
@@ -1316,19 +1284,13 @@ int StartSystem(int my_use_net)
13161284
ti->OpenTerm(MasterControl);
13171285
if (ti->next)
13181286
sleep(OPENTERM_SLEEP);
1287+
count++;
13191288
}
13201289
else
13211290
{
13221291
printf("Not licensed to run terminal '%s'\n", ti->name.Value());
13231292
}
13241293
}
1325-
else if (have_server == 0)
1326-
{
1327-
// this entry isn't explicitly set as server, but we got a match on
1328-
// the display string, so we'll set it now.
1329-
ti->IsServer(1);
1330-
have_server = 1; // Update count to prevent setting another terminal as server
1331-
}
13321294
ti = ti->next;
13331295
}
13341296
}

‎main/data/settings.cc‎

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4470,50 +4470,52 @@ MealInfo *Settings::FindMealByID(int id)
44704470
TermInfo *Settings::FindServer(const genericChar* displaystr)
44714471
{
44724472
FnTrace("Settings::FindServer()");
4473-
TermInfo *retti = nullptr;
44744473
TermInfo *ti = term_list.Head();
44754474

4476-
// First pass: look for a terminal explicitly marked as server
4477-
while (ti != nullptr)
4475+
// The first terminal in the list is ALWAYS the server display
4476+
if (ti != nullptr)
44784477
{
4479-
if (ti->IsServer())
4478+
// Ensure the first terminal is marked as server
4479+
if (!ti->IsServer())
44804480
{
4481-
retti = ti;
4482-
break;
4481+
ti->IsServer(1);
44834482
}
4484-
ti = ti->next;
4485-
}
4486-
4487-
// Second pass: if no server found, look for matching display_host
4488-
if (retti == nullptr)
4489-
{
4490-
ti = term_list.Head();
4491-
while (ti != nullptr)
4483+
4484+
// Remove any other terminals that were previously marked as server
4485+
// and have the default "Server" name (auto-created duplicates)
4486+
TermInfo *other = ti->next;
4487+
while (other != nullptr)
44924488
{
4493-
if (strcmp(displaystr, ti->display_host.Value()) == 0)
4489+
TermInfo *next_other = other->next;
4490+
if (other->IsServer())
44944491
{
4495-
retti = ti;
4496-
// Mark this terminal as the server since it matches our display
4497-
retti->IsServer(1);
4498-
break;
4492+
other->IsServer(0);
44994493
}
4500-
ti = ti->next;
4494+
// Remove auto-created "Server" terminals that are duplicates
4495+
if (strcmp(other->name.Value(), "Server") == 0 &&
4496+
(other->display_host.empty() ||
4497+
strcmp(other->display_host.Value(), displaystr) == 0))
4498+
{
4499+
Remove(other);
4500+
delete other;
4501+
}
4502+
other = next_other;
45014503
}
4502-
}
4503-
4504-
// If still no match, create a new server terminal
4505-
if (retti == nullptr)
4506-
{
4507-
retti = new TermInfo;
4508-
retti->name.Set("Server");
4509-
retti->display_host.Clear();
4510-
retti->type = TERMINAL_NORMAL;
4511-
retti->printer_model = 0;
4512-
retti->printer_port = 0;
4513-
retti->IsServer(1);
4514-
AddFront(retti);
4515-
}
4516-
return retti;
4504+
4505+
return ti;
4506+
}
4507+
4508+
// No terminals exist - create the server terminal
4509+
ti = new TermInfo;
4510+
ti->name.Set("Server");
4511+
ti->display_host.Clear();
4512+
ti->type = TERMINAL_NORMAL;
4513+
ti->printer_model = 0;
4514+
ti->printer_port = 0;
4515+
ti->IsServer(1);
4516+
AddFront(ti);
4517+
4518+
return ti;
45174519
}
45184520

45194521
TermInfo *Settings::FindTerminal(const char* displaystr)

0 commit comments

Comments
 (0)