@@ -37,6 +37,15 @@ pub struct RemoteTabRecord {
3737 pub last_used : i64 , // In ms.
3838 #[ uniffi( default = false ) ]
3939 pub inactive : bool ,
40+ #[ uniffi( default = false ) ]
41+ pub pinned : bool ,
42+ /// The index within the window_id.
43+ #[ uniffi( default = 0 ) ]
44+ pub index : u32 ,
45+ #[ uniffi( default = "" ) ]
46+ pub window_id : String ,
47+ #[ uniffi( default = "" ) ]
48+ pub tab_group_id : String ,
4049}
4150pub type RemoteTab = RemoteTabRecord ;
4251
@@ -49,6 +58,54 @@ pub struct ClientRemoteTabs {
4958 /// Number of ms since the unix epoch (as reported by the server's clock)
5059 pub last_modified : i64 ,
5160 pub remote_tabs : Vec < RemoteTab > ,
61+ pub tab_groups : HashMap < String , TabGroup > ,
62+ pub windows : HashMap < String , Window > ,
63+ }
64+
65+ #[ derive( uniffi:: Enum , Clone , Debug , Default ) ]
66+ #[ repr( u8 ) ]
67+ pub enum WindowType {
68+ #[ default]
69+ Normal = 0 ,
70+ }
71+
72+ impl From < u8 > for WindowType {
73+ fn from ( value : u8 ) -> Self {
74+ match value {
75+ 0 => WindowType :: Normal ,
76+ _ => {
77+ warn ! ( "Unknown window type {}, defaulting to Normal" , value) ;
78+ WindowType :: Normal
79+ }
80+ }
81+ }
82+ }
83+
84+ #[ derive( uniffi:: Record , Debug , Clone ) ]
85+ #[ cfg_attr( test, derive( Default ) ) ]
86+ pub struct Window {
87+ pub id : String ,
88+ pub last_used : Timestamp ,
89+ pub index : u32 ,
90+ pub window_type : WindowType ,
91+ }
92+
93+ /// A tab-group, representing a session store `TabGroupStateData`.
94+ #[ derive( uniffi:: Record , Debug , Clone ) ]
95+ #[ cfg_attr( test, derive( Default ) ) ]
96+ pub struct TabGroup {
97+ pub id : String ,
98+ pub name : String ,
99+ pub color : String ,
100+ pub collapsed : bool ,
101+ }
102+
103+ // This is what we expect clients to supply as their own tabs.
104+ #[ derive( uniffi:: Record , Debug , Clone , Default ) ]
105+ pub struct LocalTabsInfo {
106+ pub tabs : Vec < RemoteTab > ,
107+ pub tab_groups : HashMap < String , TabGroup > ,
108+ pub windows : HashMap < String , Window > ,
52109}
53110
54111pub ( crate ) enum DbConnection {
@@ -70,7 +127,7 @@ pub(crate) enum DbConnection {
70127// (Note however we don't attempt to remove the database when no remote tabs exist, so having
71128// no remote tabs in an existing DB is also a normal situation)
72129pub struct TabsStorage {
73- pub ( crate ) local_tabs : RefCell < Option < Vec < RemoteTab > > > ,
130+ pub ( crate ) local_tabs : RefCell < Option < LocalTabsInfo > > ,
74131 db_path : PathBuf ,
75132 db_connection : DbConnection ,
76133}
@@ -159,8 +216,8 @@ impl TabsStorage {
159216 }
160217 }
161218
162- pub fn update_local_state ( & mut self , local_state : Vec < RemoteTab > ) {
163- let num_tabs = local_state. len ( ) ;
219+ pub fn update_local_state ( & mut self , local_state : LocalTabsInfo ) {
220+ let num_tabs = local_state. tabs . len ( ) ;
164221 self . local_tabs . borrow_mut ( ) . replace ( local_state) ;
165222 info ! ( "update_local_state has {num_tabs} tab entries" ) ;
166223 }
@@ -761,14 +818,7 @@ mod tests {
761818 guid: "device-1" . to_string( ) ,
762819 record: TabsRecord {
763820 id: "device-1" . to_string( ) ,
764- client_name: "Device #1" . to_string( ) ,
765- tabs: vec![ TabsRecordTab {
766- title: "the title" . to_string( ) ,
767- url_history: vec![ "https://mozilla.org/" . to_string( ) ] ,
768- icon: Some ( "https://mozilla.org/icon" . to_string( ) ) ,
769- last_used: 1643764207000 ,
770- ..Default :: default ( )
771- } ] ,
821+ ..Default :: default ( )
772822 } ,
773823 last_modified: 1643764207000 ,
774824 } ,
@@ -777,13 +827,7 @@ mod tests {
777827 record: TabsRecord {
778828 id: "device-outdated" . to_string( ) ,
779829 client_name: "Device outdated" . to_string( ) ,
780- tabs: vec![ TabsRecordTab {
781- title: "the title" . to_string( ) ,
782- url_history: vec![ "https://mozilla.org/" . to_string( ) ] ,
783- icon: Some ( "https://mozilla.org/icon" . to_string( ) ) ,
784- last_used: 1643764207000 ,
785- ..Default :: default ( )
786- } ] ,
830+ ..Default :: default ( )
787831 } ,
788832 last_modified: 1443764207000 , // old
789833 } ,
@@ -918,6 +962,7 @@ mod tests {
918962 last_used: 1711929600015 , // 4/1/2024
919963 ..Default :: default ( )
920964 } ] ,
965+ ..Default :: default ( )
921966 } ,
922967 last_modified: 1711929600015 , // 4/1/2024
923968 } ,
@@ -952,6 +997,7 @@ mod tests {
952997 ..Default :: default ( )
953998 } ,
954999 ] ,
1000+ ..Default :: default ( )
9551001 } ,
9561002 last_modified: 1711929600015 , // 4/1/2024
9571003 } ,
@@ -1100,11 +1146,11 @@ mod tests {
11001146 let new_records = vec ! [ (
11011147 TabsRecord {
11021148 id: "device-not-synced" . to_string( ) ,
1103- client_name: "" . to_string( ) ,
11041149 tabs: vec![ TabsRecordTab {
11051150 url_history: vec![ "https://example2.com" . to_string( ) ] ,
11061151 ..Default :: default ( )
11071152 } ] ,
1153+ ..Default :: default ( )
11081154 } ,
11091155 ServerTimestamp :: from_millis( now. as_millis_i64( ) ) ,
11101156 ) ] ;
@@ -1175,7 +1221,6 @@ mod tests {
11751221 let new_records = vec ! [ (
11761222 TabsRecord {
11771223 id: "device-recent" . to_string( ) ,
1178- client_name: "" . to_string( ) ,
11791224 tabs: vec![
11801225 TabsRecordTab {
11811226 url_history: vec![ "https://example99.com" . to_string( ) ] ,
@@ -1186,6 +1231,7 @@ mod tests {
11861231 ..Default :: default ( )
11871232 } ,
11881233 ] ,
1234+ ..Default :: default ( )
11891235 } ,
11901236 ServerTimestamp :: default ( ) ,
11911237 ) ] ;
@@ -1331,11 +1377,11 @@ mod tests {
13311377 let new_records = vec ! [ (
13321378 TabsRecord {
13331379 id: "device-1" . to_string( ) ,
1334- client_name: "" . to_string( ) ,
13351380 tabs: vec![ TabsRecordTab {
13361381 url_history: vec![ "https://example1.com" . to_string( ) ] ,
13371382 ..Default :: default ( )
13381383 } ] ,
1384+ ..Default :: default ( )
13391385 } ,
13401386 ServerTimestamp :: default ( ) ,
13411387 ) ] ;
0 commit comments