refactor(app-iced, presenter): M114 rebase 后守 400 行 —— 四处纯搬移(不动语义、不压注释、不挪断言)
主线六条合入后,四个被我碰过的文件越过 400 行;按模块拆开,只搬不改: - `presenter/host/mod.rs` 421→366:账户刷新/皮肤三段(refresh_accounts / attach_skins / request_skins)搬进 `host/accounts/refresh.rs`(`impl CoreHost`,pub(in crate::host)) - `presenter/state.rs` 410→392:`TileCell` + `grid_positions` 搬进 `state/tiles.rs`, `state.rs` 用 `pub use` 再导出,老路径不变 - `app-iced/app/state.rs` 401→394:账户页重建那一段搬进 `app/view/account_page.rs` 的 `App::rebuild_account_page` - `app-iced/app/update.rs` 407→388:`ULL_START_ROUTE` 取值表搬进 `app/update/boot_env.rs` (纯函数、无状态)
This commit is contained in:
1 parent
0f69eec64d
commit
a183adc072
12 files changed
+210
-120
No files matched your search
@@ -10,10 +10,31 @@ use crate::dialogs::{DialogId, DialogRequest};
|
||||
use crate::dto::CreateRequest;
|
||||
use crate::dto::{
|
||||
// 主线(M109 的 Content* / M113 的 Pack*)与 M114 的 Authlib*/AccountNotice 的并集。
|
||||
AccountNotice, AccountView, AgentEvent, AuthlibLoginView, AuthlibRequest, ContentInstallRequest,
|
||||
ContentQuery, ContentResults, DeviceLoginView, DiagnosisReport, InstallProgressView, InstanceId,
|
||||
InstanceRuntime, InstanceSummary, JavaPageView, LoaderKind, LogLine, LogOutcome, LogSession,
|
||||
NoticeView, PackCommand, PackEvent, SessionId, SettingGroupView, VersionCategory,
|
||||
AccountNotice,
|
||||
AccountView,
|
||||
AgentEvent,
|
||||
AuthlibLoginView,
|
||||
AuthlibRequest,
|
||||
ContentInstallRequest,
|
||||
ContentQuery,
|
||||
ContentResults,
|
||||
DeviceLoginView,
|
||||
DiagnosisReport,
|
||||
InstallProgressView,
|
||||
InstanceId,
|
||||
InstanceRuntime,
|
||||
InstanceSummary,
|
||||
JavaPageView,
|
||||
LoaderKind,
|
||||
LogLine,
|
||||
LogOutcome,
|
||||
LogSession,
|
||||
NoticeView,
|
||||
PackCommand,
|
||||
PackEvent,
|
||||
SessionId,
|
||||
SettingGroupView,
|
||||
VersionCategory,
|
||||
VersionSummary,
|
||||
};
|
||||
use crate::toast::Toast;
|
||||
|
||||
@@ -32,6 +32,8 @@ use super::opener;
|
||||
/// 第三方轨(服务发现 / 密码登录 / 皮肤抓取)。
|
||||
pub mod authlib;
|
||||
|
||||
mod refresh;
|
||||
|
||||
mod failure;
|
||||
|
||||
pub use failure::AccountFailure;
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
//! 账户列表的刷新与皮肤抓取(`impl CoreHost` 的这一段,从 `host/mod.rs` 拆出来守 400 行)。
|
||||
//!
|
||||
//! 为什么在这里:`host/mod.rs` 在 M109/M113 之后已经贴着 400 行硬线,而这三段是**账户专属**
|
||||
//! 的编排(读账户库 → 盖皮肤 → 起抓取线程)。放回 `host/accounts.rs` 也不行——那个文件同样
|
||||
//! 380 行。归属仍是 accounts(`mod accounts { mod refresh; }`),只是按功能再分一层。
|
||||
|
||||
use crate::dto::{AccountKind, CoreEvent};
|
||||
|
||||
use super::super::{accounts, job, CoreHost, HostTask};
|
||||
|
||||
impl CoreHost {
|
||||
pub(in crate::host) fn refresh_accounts(&mut self) {
|
||||
self.accounts = accounts::accounts(&self.env, self.active_account.as_deref());
|
||||
if self.active_account.is_none() {
|
||||
// 默认选中第一个账户(没有账户时保持 None = 离线占位)
|
||||
self.active_account = self.accounts.first().map(|account| account.id.clone());
|
||||
self.accounts = accounts::accounts(&self.env, self.active_account.as_deref());
|
||||
}
|
||||
self.attach_skins();
|
||||
self.request_skins();
|
||||
self.send(CoreEvent::AccountsChanged(self.accounts.clone()));
|
||||
}
|
||||
|
||||
/// 把已抓到的皮肤盖到账户视图上。
|
||||
///
|
||||
/// 只盖第三方轨:离线档案没有皮肤,微软轨不做真头像(M114 口径)——
|
||||
/// 「没有皮肤就画首字母块」,绝不给假皮肤/白块。
|
||||
pub(in crate::host) fn attach_skins(&mut self) {
|
||||
for account in &mut self.accounts {
|
||||
if account.kind != AccountKind::Authlib {
|
||||
account.skin = None;
|
||||
continue;
|
||||
}
|
||||
if let Some(skin) = self.skins.get(&account.id) {
|
||||
account.skin = skin.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 给还没抓过皮肤的第三方轨账户起后台抓取(每个账户只抓一次)。
|
||||
///
|
||||
/// 抓不到就记 `None`:错误在面板上不显示(皮肤是装饰,不是业务失败),但也不会重试刷屏。
|
||||
fn request_skins(&mut self) {
|
||||
let mut pending = Vec::new();
|
||||
for account in &self.accounts {
|
||||
if account.kind != AccountKind::Authlib || account.server_url.trim().is_empty() {
|
||||
continue;
|
||||
}
|
||||
if self.skin_requested.insert(account.id.clone()) {
|
||||
pending.push((
|
||||
account.id.clone(),
|
||||
account.server_url.clone(),
|
||||
account.profile_id.clone(),
|
||||
));
|
||||
}
|
||||
}
|
||||
for (id, server, profile) in pending {
|
||||
let tx = self.tx.clone();
|
||||
let env = self.env.clone();
|
||||
job::spawn("account-skin", move || {
|
||||
let skin = accounts::fetch_skin(&env, &server, &profile).ok();
|
||||
let _ = tx.send(HostTask::Avatar { id, skin });
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,25 @@ use std::sync::mpsc::{Receiver, Sender};
|
||||
|
||||
use crate::dto::{
|
||||
// 主线(M109 ContentResults / M105 LoaderKind / M113 PackEvent)与 M114 的账户轨并集。
|
||||
AccountView, AuthlibLoginView, ContentResults, DeviceLoginView, DiagnosisReport,
|
||||
InstallProgressView, InstanceId, InstanceRuntime, JavaPageView, LaunchFinished, LiveLogBatch,
|
||||
LoaderKind, LogLine, LogOutcome, LogSession, NoticeView, PackEvent, SessionId, SkinImage,
|
||||
AccountView,
|
||||
AuthlibLoginView,
|
||||
ContentResults,
|
||||
DeviceLoginView,
|
||||
DiagnosisReport,
|
||||
InstallProgressView,
|
||||
InstanceId,
|
||||
InstanceRuntime,
|
||||
JavaPageView,
|
||||
LaunchFinished,
|
||||
LiveLogBatch,
|
||||
LoaderKind,
|
||||
LogLine,
|
||||
LogOutcome,
|
||||
LogSession,
|
||||
NoticeView,
|
||||
PackEvent,
|
||||
SessionId,
|
||||
SkinImage,
|
||||
VersionSummary,
|
||||
};
|
||||
use crate::toast::Toast;
|
||||
|
||||
@@ -37,8 +37,8 @@ use std::collections::{BTreeMap, BTreeSet, VecDeque};
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::dto::{
|
||||
AccountKind, AccountView, AppCommand, AppEvent, Backend, CoreEvent, DiagnosisReport,
|
||||
InstallProgressView, InstanceRuntime, JavaChainStep, NoticeView, SkinImage,
|
||||
AccountView, AppCommand, AppEvent, Backend, CoreEvent, DiagnosisReport, InstallProgressView,
|
||||
InstanceRuntime, JavaChainStep, NoticeView, SkinImage,
|
||||
};
|
||||
use crate::mock::MockBackend;
|
||||
use crate::toast::{Toast, ToastKind};
|
||||
@@ -222,61 +222,6 @@ impl CoreHost {
|
||||
self.send(CoreEvent::InstancesChanged(instances));
|
||||
}
|
||||
|
||||
fn refresh_accounts(&mut self) {
|
||||
self.accounts = accounts::accounts(&self.env, self.active_account.as_deref());
|
||||
if self.active_account.is_none() {
|
||||
// 默认选中第一个账户(没有账户时保持 None = 离线占位)
|
||||
self.active_account = self.accounts.first().map(|account| account.id.clone());
|
||||
self.accounts = accounts::accounts(&self.env, self.active_account.as_deref());
|
||||
}
|
||||
self.attach_skins();
|
||||
self.request_skins();
|
||||
self.send(CoreEvent::AccountsChanged(self.accounts.clone()));
|
||||
}
|
||||
|
||||
/// 把已抓到的皮肤盖到账户视图上。
|
||||
///
|
||||
/// 只盖第三方轨:离线档案没有皮肤,微软轨不做真头像(M114 口径)——
|
||||
/// 「没有皮肤就画首字母块」,绝不给假皮肤/白块。
|
||||
fn attach_skins(&mut self) {
|
||||
for account in &mut self.accounts {
|
||||
if account.kind != AccountKind::Authlib {
|
||||
account.skin = None;
|
||||
continue;
|
||||
}
|
||||
if let Some(skin) = self.skins.get(&account.id) {
|
||||
account.skin = skin.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 给还没抓过皮肤的第三方轨账户起后台抓取(每个账户只抓一次)。
|
||||
///
|
||||
/// 抓不到就记 `None`:错误在面板上不显示(皮肤是装饰,不是业务失败),但也不会重试刷屏。
|
||||
fn request_skins(&mut self) {
|
||||
let mut pending = Vec::new();
|
||||
for account in &self.accounts {
|
||||
if account.kind != AccountKind::Authlib || account.server_url.trim().is_empty() {
|
||||
continue;
|
||||
}
|
||||
if self.skin_requested.insert(account.id.clone()) {
|
||||
pending.push((
|
||||
account.id.clone(),
|
||||
account.server_url.clone(),
|
||||
account.profile_id.clone(),
|
||||
));
|
||||
}
|
||||
}
|
||||
for (id, server, profile) in pending {
|
||||
let tx = self.tx.clone();
|
||||
let env = self.env.clone();
|
||||
job::spawn("account-skin", move || {
|
||||
let skin = accounts::fetch_skin(&env, &server, &profile).ok();
|
||||
let _ = tx.send(HostTask::Avatar { id, skin });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn refresh_java(&mut self) {
|
||||
let page = java::page(
|
||||
&self.env,
|
||||
|
||||
@@ -7,9 +7,24 @@ use crate::agent::AgentRail;
|
||||
use crate::dialogs::DialogQueue;
|
||||
use crate::dto::{
|
||||
// 主线(M105 的 `LoaderKind` / M113 的 `PackState`)与 M114 的 `AuthlibLoginView` 并集。
|
||||
AccountView, AgentEvent, AppEvent, AuthlibLoginView, CoreEvent, DeviceLoginView,
|
||||
DiagnosisReport, InstallProgressView, InstanceRuntime, InstanceSummary, JavaPageView,
|
||||
LoaderKind, LogLine, LogSession, NoticeView, PackState, Progress, SettingGroupView,
|
||||
AccountView,
|
||||
AgentEvent,
|
||||
AppEvent,
|
||||
AuthlibLoginView,
|
||||
CoreEvent,
|
||||
DeviceLoginView,
|
||||
DiagnosisReport,
|
||||
InstallProgressView,
|
||||
InstanceRuntime,
|
||||
InstanceSummary,
|
||||
JavaPageView,
|
||||
LoaderKind,
|
||||
LogLine,
|
||||
LogSession,
|
||||
NoticeView,
|
||||
PackState,
|
||||
Progress,
|
||||
SettingGroupView,
|
||||
VersionSummary,
|
||||
};
|
||||
use crate::prefs::UiPrefs;
|
||||
@@ -25,27 +40,9 @@ use crate::wizard::WizardState;
|
||||
// 所以这里没有 `mod ai;` / `pub use ai::AiSession;`——M114 r1 曾把旧结构搬到 `state/ai.rs`,
|
||||
// 该文件已随 rebase 删除,**以 main 的 agent 契约为准**。
|
||||
mod accounts;
|
||||
mod tiles;
|
||||
|
||||
/// 磁贴网格单元:位置由 [`grid_positions`] 算好,UI 侧只消费 row/col。
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct TileCell<'a> {
|
||||
/// 实例数据
|
||||
pub instance: &'a InstanceSummary,
|
||||
/// 网格行号(0 起)
|
||||
pub row: usize,
|
||||
/// 网格列号(0 起)
|
||||
pub col: usize,
|
||||
}
|
||||
|
||||
/// 纯函数:把 n 个磁贴摊到 `columns` 列的网格上,返回 `(row, col)`。
|
||||
///
|
||||
/// 特意放在 Rust 侧:声明式 UI 的表达式里做整数除法容易引出隐式浮点,且这段逻辑可以单测。
|
||||
pub fn grid_positions(count: usize, columns: usize) -> Vec<(usize, usize)> {
|
||||
let columns = columns.max(1);
|
||||
(0..count)
|
||||
.map(|index| (index / columns, index % columns))
|
||||
.collect()
|
||||
}
|
||||
pub use tiles::{grid_positions, TileCell};
|
||||
|
||||
/// 实时日志最多保留的行数(滚动窗口;更多行由日志页的筛选/历史会话承担)。
|
||||
pub const MAX_LIVE_LINES: usize = 2_000;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
//! 磁贴网格的纯函数与单元类型(从 `state.rs` 原样搬出,守 400 行硬线)。
|
||||
//!
|
||||
//! **纯搬移**:类型、函数、文档一字未改,只是换了文件;`state.rs` 用 `pub use` 再导出,
|
||||
//! 于是 `crate::state::{TileCell, grid_positions}` 这两个老路径继续可用。
|
||||
|
||||
use crate::dto::InstanceSummary;
|
||||
|
||||
/// 磁贴网格单元:位置由 [`grid_positions`] 算好,UI 侧只消费 row/col。
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct TileCell<'a> {
|
||||
/// 实例数据
|
||||
pub instance: &'a InstanceSummary,
|
||||
/// 网格行号(0 起)
|
||||
pub row: usize,
|
||||
/// 网格列号(0 起)
|
||||
pub col: usize,
|
||||
}
|
||||
|
||||
/// 纯函数:把 n 个磁贴摊到 `columns` 列的网格上,返回 `(row, col)`。
|
||||
///
|
||||
/// 特意放在 Rust 侧:声明式 UI 的表达式里做整数除法容易引出隐式浮点,且这段逻辑可以单测。
|
||||
pub fn grid_positions(count: usize, columns: usize) -> Vec<(usize, usize)> {
|
||||
let columns = columns.max(1);
|
||||
(0..count)
|
||||
.map(|index| (index / columns, index % columns))
|
||||
.collect()
|
||||
}
|
||||
Reference in new issue
Block a user