Skip to content

refactor(store): rework printer/server initalisation - #2627

Draft
meteyou wants to merge 32 commits into
developfrom
feat/rework-init-process
Draft

meteyou wants to merge 32 commits into
developfrom
feat/rework-init-process

Conversation

@meteyou

@meteyou meteyou commented Aug 4, 2026

Copy link
Copy Markdown
Member

Description

This PR is just to track the progress in the refactoring of the printer/server store and the init process of it.

Related Tickets & Documents

none

Mobile & Desktop Screenshots/Recordings

none

[optional] Are there any post-deployment tasks we need to perform?

none

* refactor: rework the server init process to display current step

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor: add strict typing for emitAndWait RPC methods

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor: remove unused file

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor: fix description in the MoonrakerRPCInterface.ts

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor: refactor init server process

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor: split all files in smaller parts for better overview like the moonraker docs

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor: remove reexports in types/moonraker/index

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor: update from emitAndWait commit and create new splited type files

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor: simplify error handling in TheConnectingDialog component

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor: enhance error handling and type definitions for JSON-RPC responses

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor: streamline server initialization and enhance data handling

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor(server): simplify Klipper connection polling logic

Replace complex dual-timer polling system with unified async approach:
- Consolidate 7 actions into 4 by extracting shared checkAndUpdateKlippyState()
- Replace callback-based emit() with async emitAndWait()
- Merge klippy_connected_timer and klippy_state_timer into single klippy_polling_timer
- Load printer/initGcodes only when gcode.commands is empty
- Add printer.info RPC type definition

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor(server): add log method

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor(server): streamline GCode store initialization and filtering

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor(actions): optimize root directory addition logic

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor(server): simplify server component initialization logic

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor(printer): remove unnecessary webhook handling in payload processing

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor(server): enhance GCode event handling and filtering logic

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* locale: remove unused key

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor: add TODO comments to remove old init after finishing process

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor: add TODO comments to remove old init components after async conversion

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor: replace camelize with convertName for component initialization

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor: update initialization steps for server components and enhance i18n support

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor: remove unused MoonrakerApiIdentifyResponse interface from types

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor: add early return for empty component initialization

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor: update translations for Power module

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor: optimize loop for component initialization

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* fix: remove not existing root parameter in server.database.list

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* fix: complete PrinterRPC interface with all Moonraker methods

Add missing RPC methods according to Moonraker documentation:
- printer.emergency_stop, printer.restart, printer.firmware_restart
- printer.query_endstops.status
- printer.gcode.script, printer.gcode.help
- printer.print.start/pause/resume/cancel

Also add missing fields to printer.info response:
process_id, user_id, group_id

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* fix: complete MachineRPC interface with all Moonraker methods

Add missing RPC methods according to Moonraker documentation:
- machine.sudo.info, machine.sudo.password
- machine.peripherals.usb, machine.peripherals.serial
- machine.peripherals.video, machine.peripherals.canbus

Also add missing fields to machine.proc_stats network interface:
rx_packets, tx_packets, rx_errs, tx_errs, rx_drop, tx_drop

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* fix: complete ServerRPC interface with all Moonraker methods

Add missing RPC methods according to Moonraker documentation:
- server.temperature_store
- server.logs.rollover
- server.restart
- server.websocket.id (deprecated)

Also reorder methods to match documentation structure.

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* fix: add nl at the end of .i18nignore

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* fix: fix type issue in server/action.ts

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* fix: add klippy_state === shutdown fix/edgecase

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* fix: add timeout to emitAndWait to fix issues with printer.info

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* refactor: remove unused import from PrinterRPC

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* fix: fix timout and poll in server/action

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* fix: add GcodeStore to initialization dialog/output and localization

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* fix: improve error message URL encoding in TheConnectingDialog

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* locale(de): add GcodeStore localization to German translation

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* fix: fix missing type connection_id

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* fix: update polling logic to handle timer state correctly

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* fix: correct progress calculation in component initialization

Signed-off-by: Stefan Dej <meteyou@gmail.com>

* fix: set console_cleared_this_session property to server state

Signed-off-by: Stefan Dej <meteyou@gmail.com>

---------

Signed-off-by: Stefan Dej <meteyou@gmail.com>
# Conflicts:
#	src/plugins/webSocketClient.ts
#	src/store/server/actions.ts
#	src/store/server/index.ts
#	src/store/server/types.ts
#	src/types/moonraker/MachineRPC.ts
#	src/types/moonraker/index.ts
state.config is the full ServerConfigResponse with keys config, orig, files.
The getter and default state incorrectly referenced the top-level object
instead of state.config.config which has the dynamic index signature.
Signed-off-by: Stefan Dej <meteyou@gmail.com>
…te snapshot URL check

Signed-off-by: Stefan Dej <meteyou@gmail.com>
…tore/server/mutations.ts

Signed-off-by: Stefan Dej <meteyou@gmail.com>
Signed-off-by: Stefan Dej <meteyou@gmail.com>
Signed-off-by: Stefan Dej <meteyou@gmail.com>
Signed-off-by: Stefan Dej <meteyou@gmail.com>
…ions

- Handle JsonRpcError in mainsail namespace fetch
- Improve handling of nested values in socket emission

Signed-off-by: Stefan Dej <meteyou@gmail.com>
Introduces a runtime type guard that narrows an unknown error to the
JsonRpcError interface, replacing unsafe `as JsonRpcError` casts in call
sites.
- Replace unsafe `as JsonRpcError` cast with isJsonRpcError type guard
- Extract NAMESPACE_NOT_FOUND (-32601) as a named constant
- Wrap getDefaults() in try/catch so a missing theme default.json falls
  back to an empty payload instead of aborting the whole init flow
- Await dispatch('restoreValues') to surface write errors properly
- Throw on non-404 errors from default.json instead of silently returning {}
- Add isRecord() guard before iterating namespace defaults in restoreValues
…e into ControlMixin

Remove the getDefaultControlActionButton Vuex getter and inline the logic
directly in the ControlMixin. Also remove the now-redundant override of
defaultActionButton in SettingsControlTab (already provided by the mixin).
…Theme' getter

Rename the gui/theme Vuex getter to gui/getThemeName for consistency with
other getter naming conventions. Remove the derived getTheme getter and
inline the theme-object lookup directly in ThemeMixin, reducing store
coupling. Update all call sites (ThemeMixin, SettingsUiSettingsTab).
Replace the loose Record<string, unknown> typing on datasetSettings with
a dedicated GuiTempchartDatasetSetting interface that explicitly models
the temperature, target, power, speed, color and additionalSensors fields.
…ponent

- Add explicit return types to all gui getters
- Narrow getDatasetValue to be generic over keyof GuiTempchartDatasetSetting
- Replace local 'legends' interface in tempHistory getter with Record<string, boolean>
- Add explicit string[] types for available_sensors / available_monitors
- Narrow serieName prop to keyof GuiTempchartDatasetSetting in TemperaturePanelListItemEditChartSerie
Signed-off-by: Stefan Dej <meteyou@gmail.com>
Signed-off-by: Stefan Dej <meteyou@gmail.com>
Signed-off-by: Stefan Dej <meteyou@gmail.com>
Signed-off-by: Stefan Dej <meteyou@gmail.com>
Signed-off-by: Stefan Dej <meteyou@gmail.com>
Signed-off-by: Stefan Dej <meteyou@gmail.com>
Signed-off-by: Stefan Dej <meteyou@gmail.com>
Signed-off-by: Stefan Dej <meteyou@gmail.com>
Signed-off-by: Stefan Dej <meteyou@gmail.com>
Signed-off-by: Stefan Dej <meteyou@gmail.com>
Signed-off-by: Stefan Dej <meteyou@gmail.com>
Signed-off-by: Stefan Dej <meteyou@gmail.com>
Signed-off-by: Stefan Dej <meteyou@gmail.com>
@Cstm3DBldr

Copy link
Copy Markdown

Not a bug you introduced, but the refactor makes it load-bearing:

emitAndWait promises are never settled when the socket closes. waits is only cleared by removeWaitById, which runs on a response or the optional timeout — onclose/onerror/connect() don't touch it. 41 of the 42 call sites pass no timeout.

On develop that barely matters, 5 call sites. Here it's 42, and server/init is a 13-deep await chain, so a Moonraker restart mid-init parks it forever: the await never returns, the catch never fires, and the dialog sits on whatever step it reached. onOpen then starts a second chain on reconnect.

Rejecting pending waits in onclose would cover it.

@meteyou

meteyou commented Aug 30, 2026

Copy link
Copy Markdown
Member Author

Thx for the hint, but I'm not finished this part of code, because I have to finish all child stores first.

When I'm finished this step, I will pay attention on the init process/workflow again.

(Sry if you get this message twice, I had network issues)

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