Skip to content

Feat/Fix: Static Work Windows and Enhanced Task Reliability#162

Open
rochasjk wants to merge 3 commits intovinaghost:mainfrom
rochasjk:rochastudies
Open

Feat/Fix: Static Work Windows and Enhanced Task Reliability#162
rochasjk wants to merge 3 commits intovinaghost:mainfrom
rochasjk:rochastudies

Conversation

@rochasjk
Copy link
Copy Markdown

@rochasjk rochasjk commented Mar 2, 2026

🚀 Overview
This PR transitions the bot's scheduling logic from a duration-based model to a static daily work window and introduces several robustness improvements to the core execution engine and browser interactions.

🔩 Core Logic: Static Work Windows
New Scheduling Model: Replaced WorkTimeMin/Max (random intervals) with fixed WorkStart and WorkEnd daily windows.

Precision Control: Added minute-level granularity (WorkStartMinute, WorkEndMinute) and a user-configurable SleepRandomMinute offset to maintain human-like behavior.

Compatibility: Updated SleepTask and RxQueue to handle these new windows while maintaining default values that ensure backward compatibility.

🛠 Reliability & Stability
Auto-Recovery: Implemented an auto-restart mechanism in TimerManager. Fatal errors now trigger a screenshot, log the failure, and force an AccountInit cycle to recover the session without manual intervention.

Browser Resilience: Added StaleElementReferenceException handling in WaitForLogo and improved navigation commands (ToDorf, ToBuildingByLocation) with explicit page-render waits.

Thread Safety: Fixed CollectionWasModified exceptions in DebugViewModel by using snapshots during log reloads.

🧱 Architectural Housekeeping
Refactored AccountSettingInput and its validator to support the new time properties.

Updated XAML views and ViewModels to expose the new UI controls (MinuteInputUc).

Note on Project Files: Adjusted OutputType to Library and cleaned up unused Tampermonkey resources.

🧩 Testing
Extended AccountSettingInputTest to verify that the new minute and randomness settings persist correctly through the settings cycle.

@vinaghost
Copy link
Copy Markdown
Owner

can you send me a few screenshot what did you change ?

// before trying to locate a building link, make sure the page is stable
// (logo rendered). using an empty fragment avoids hanging if we're already
// on a non-dorf page such as a build screen.
var waitResult = await browser.WaitPageChanged("", cancellationToken);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i saw the comment but what does it do? Comment is for explaining why the code is there, not how the code run

also wait page changed not work like this, you only need waitpageload

// `WaitPageChanged` takes a URL fragment but we only care about the logo being
// visible; passing an empty string makes the URL check no‑op and still waits
// for the logo, avoiding deadlocks when we're on a non-dorf page.
var waitResult = await browser.WaitPageChanged("", cancellationToken);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same with tobuildingbylocationcommand.cs, wait page changed not work like this, you only need waitpageload

if (workEndMinute < 0 || workEndMinute > 59) workEndMinute = 0;

// randomness range from 0 (no offset) up to configured max
var random = new Random();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Random.Shared

.Where(x => x.AccountId == accountId.Value)
.Where(x => x.Setting == setting.Key)
.ExecuteUpdate(x => x.SetProperty(x => x.Value, setting.Value));
var entity = context.AccountsSetting
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is done when account creating,, don't do this

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure this is a good idea, but we can keep it

{
Hour = Hour >= 23 ? 0 : Hour + 1;
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we has installed ReactiveUI.SourceGenerator, please use "[ReactiveCommand]" and "[Reactive]"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we has installed ReactiveUI.SourceGenerator, please use "[ReactiveCommand]" and "[Reactive]"

Comment thread MainCore/MainCore.csproj
<SelfContained>true</SelfContained>

<AssemblyVersion>1975.4.30</AssemblyVersion>
<AssemblyVersion>2603.01.4.0</AssemblyVersion>
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep the number, don't change

Comment thread MainCore/MainCore.csproj

</ItemGroup>
<ItemGroup>
<EmbeddedResource Remove="Infrasturecture\ExtensionFiles\tampermonkey_stable.crx" />
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want an additional extension, please make another PR,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want an additional extension, please make another PR,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants