1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 //! This module has to be here because of some hard-to-avoid hacks done for the 6 //! tabs engine... See issue #2590 7 8 use std::collections::HashMap; 9 10 /// Argument to Store::prepare_for_sync. See comment there for more info. Only 11 /// really intended to be used by tabs engine. 12 #[derive(Clone, Debug)] 13 pub struct ClientData { 14 pub local_client_id: String, 15 pub recent_clients: HashMap<String, RemoteClient>, 16 } 17 18 /// Information about a remote client in the clients collection. 19 #[derive(Clone, Debug, Eq, Hash, PartialEq)] 20 pub struct RemoteClient { 21 pub fxa_device_id: Option<String>, 22 pub device_name: String, 23 pub device_type: Option<DeviceType>, 24 } 25 26 /// The type of a client. Please keep these variants in sync with the device 27 /// types in the FxA client and sync manager. 28 #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, serde::Deserialize, serde::Serialize)] 29 pub enum DeviceType { 30 Desktop, 31 Mobile, 32 Tablet, 33 VR, 34 TV, 35 } 36 37 impl DeviceType { try_from_str(d: impl AsRef<str>) -> Option<DeviceType>38 pub fn try_from_str(d: impl AsRef<str>) -> Option<DeviceType> { 39 match d.as_ref() { 40 "desktop" => Some(DeviceType::Desktop), 41 "mobile" => Some(DeviceType::Mobile), 42 "tablet" => Some(DeviceType::Tablet), 43 "vr" => Some(DeviceType::VR), 44 "tv" => Some(DeviceType::TV), 45 _ => None, 46 } 47 } 48 as_str(self) -> &'static str49 pub fn as_str(self) -> &'static str { 50 match self { 51 DeviceType::Desktop => "desktop", 52 DeviceType::Mobile => "mobile", 53 DeviceType::Tablet => "tablet", 54 DeviceType::VR => "vr", 55 DeviceType::TV => "tv", 56 } 57 } 58 } 59