@@ -10,9 +10,11 @@ export type RouteMode = "external" | "local-singbox";
export interface ConfigSnapshotItem {
type : DraftItemType ;
value : string ;
recursive? : boolean ;
}
export interface ConfigSnapshot {
enabled? : boolean ;
routeMode : RouteMode ;
proxy : string ;
selectedServerId : string ;
@@ -31,11 +33,13 @@ export interface PendingChangeRow {
export function configSnapshotFromUi (
routeMode : RouteMode ,
proxyInput : string ,
items : Array < { type : DraftItemType ; value : string } > ,
items : Array < { type : DraftItemType ; value : string ; recursive? : boolean } > ,
selectedServerId? : string ,
selectedServerTag? : string ,
enabled = true ,
) : ConfigSnapshot {
return {
enabled ,
routeMode ,
proxy : routeMode === "external" ? normalizeProxySnapshot ( proxyInput ) : "" ,
selectedServerId :
@@ -53,6 +57,14 @@ export function configChangeRows(
if ( sameConfigSnapshot ( applied , current ) ) return [ ] ;
const rows : PendingChangeRow [ ] = [ ] ;
if ( ( applied . enabled ? ? true ) !== ( current . enabled ? ? true ) ) {
rows . push ( {
id : "profile-enabled" ,
label : "Профиль" ,
before : applied.enabled === false ? "Выключен" : "Включён" ,
after : current.enabled === false ? "Выключен" : "Включён" ,
} ) ;
}
if ( applied . routeMode !== current . routeMode ) {
rows . push ( {
id : "route-mode" ,
@@ -93,6 +105,7 @@ export function sameConfigSnapshot(
right : ConfigSnapshot ,
) {
return (
( left . enabled ? ? true ) === ( right . enabled ? ? true ) &&
left . routeMode === right . routeMode &&
left . proxy === right . proxy &&
left . selectedServerId === right . selectedServerId &&
@@ -100,7 +113,7 @@ export function sameConfigSnapshot(
left . items . length === right . items . length &&
left . items . every ( ( item , index ) = > {
const other = right . items [ index ] ;
return item . type === other . type && item . value === other . value ;
return snapshotItemKey ( item ) === snapshotItemKey ( other ) ;
} )
) ;
}
@@ -135,18 +148,17 @@ function normalizeProxySnapshot(value: string) {
}
function normalizeSnapshotItems (
items : Array < { type : DraftItemType ; value : string } > ,
items : Array < { type : DraftItemType ; value : string ; recursive? : boolean } > ,
) : ConfigSnapshotItem [ ] {
return items
. map ( ( item ) = > ( {
type : item . type ,
value : normalizeItemValue ( item . value , item . type ) . toLowerCase ( ) ,
recursive : item.type === "folder" ? ( item . recursive ? ? true ) : false ,
} ) )
. filter ( ( item ) = > item . value )
. sort ( ( left , right ) = >
` ${ left . type } : ${ left . value } ` . localeCompare (
` ${ right . type } : ${ right . value } ` ,
) ,
snapshotItemKey ( left ) . localeCompare ( snapshotItemKey ( right ) ) ,
) ;
}
@@ -193,9 +205,9 @@ function snapshotItemChangeRows(
}
function snapshotItemKey ( item : ConfigSnapshotItem ) {
return ` ${ item . type } : ${ item . value } ` ;
return ` ${ item . type } : ${ item . value } : ${ item . type === "folder" ? ( item . recursive ? ? true ) : false } ` ;
}
function formatSnapshotItem ( item : ConfigSnapshotItem ) {
return ` ${ itemTypeLabel ( item . type ) } ${ item . value } ` ;
return ` ${ itemTypeLabel ( item . type ) } ${ item . value } ${ item . type === "folder" ? ( item . recursive === false ? " (без подпапок)" : " (с подпапками)" ) : "" } ` ;
}