about summary refs log tree commit diff
path: root/sys
diff options
context:
space:
mode:
authorV <v@anomalous.eu>2021-08-05 14:40:20 +0200
committerV <v@anomalous.eu>2021-08-05 14:40:20 +0200
commit14bff4da24732c97dcb691e112418d7fa547e3a1 (patch)
treecdb6da60e5c8235379d1433a3aa03d76e7bffc9a /sys
parentd5fcf5b30357e8ed46edcde0c6ad5f0bd2c9ed00 (diff)
downloadhidit-14bff4da24732c97dcb691e112418d7fa547e3a1.tar.zst
sys: Initial porting work, done by hand HEAD trunk
Diffstat (limited to 'sys')
-rw-r--r--sys/Cargo.toml9
-rw-r--r--sys/src/lib.rs2
-rw-r--r--sys/src/tabs.rs1
-rw-r--r--sys/src/windows.rs211
4 files changed, 223 insertions, 0 deletions
diff --git a/sys/Cargo.toml b/sys/Cargo.toml
new file mode 100644
index 0000000..0379d97
--- /dev/null
+++ b/sys/Cargo.toml
@@ -0,0 +1,9 @@
+[package]
+name = "sys"
+version = "0.1.0"
+authors = ["V <v@anomalous.eu>"]
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/sys/src/lib.rs b/sys/src/lib.rs
new file mode 100644
index 0000000..e391edb
--- /dev/null
+++ b/sys/src/lib.rs
@@ -0,0 +1,2 @@
+pub mod tabs;
+pub mod windows;
diff --git a/sys/src/tabs.rs b/sys/src/tabs.rs
new file mode 100644
index 0000000..bdbd327
--- /dev/null
+++ b/sys/src/tabs.rs
@@ -0,0 +1 @@
+pub struct Tab {}
diff --git a/sys/src/windows.rs b/sys/src/windows.rs
new file mode 100644
index 0000000..c2094f3
--- /dev/null
+++ b/sys/src/windows.rs
@@ -0,0 +1,211 @@
+/// Use the <code>browser.windows</code> API to interact with browser windows. You can use this API to create, modify, and rearrange windows in the browser.
+use crate::tabs;
+
+/// The type of browser window this is. Under some circumstances a Window may not be assigned type property, for example when querying closed windows from the $(ref:sessions) API.
+pub enum WindowType {
+    Normal,
+    Popup,
+    Panel,
+    App,
+    Devtools,
+}
+
+/// The state of this browser window. Under some circumstances a Window may not be assigned state property, for example when querying closed windows from the $(ref:sessions) API.
+pub enum WindowState {
+    Normal,
+    Minimized,
+    Maximized,
+    Fullscreen,
+    Docked,
+}
+
+pub struct Window {
+    /// The ID of the window. Window IDs are unique within a browser session. Under some circumstances a Window may not be assigned an ID, for example when querying windows using the $(ref:sessions) API, in which case a session ID may be present
+    pub id: Option<i64>, // minimum: 0
+    /// Whether the window is currently the focused window.
+    pub focused: bool,
+    /// The offset of the window from the top edge of the screen in pixels. Under some circumstances a Window may not be assigned top property, for example when querying closed windows from the $(ref:sessions) API.
+    pub top: Option<i64>,
+    /// The offset of the window from the left edge of the screen in pixels. Under some circumstances a Window may not be assigned left property, for example when querying closed windows from the $(ref:sessions) API.
+    pub left: Option<i64>,
+    /// The width of the window, including the frame, in pixels. Under some circumstances a Window may not be assigned width property, for example when querying closed windows from the $(ref:sessions) API.
+    pub width: Option<i64>,
+    /// The height of the window, including the frame, in pixels. Under some circumstances a Window may not be assigned height property, for example when querying closed windows from the $(ref:sessions) API.
+    pub height: Option<i64>,
+    /// Array of $(ref:tabs.Tab) objects representing the current tabs in the window.
+    pub tabs: Option<Vec<tabs::Tab>>,
+    /// Whether the window is incognito.
+    pub incognito: bool,
+    /// The type of browser window this is.
+    pub r#type: Option<WindowType>,
+    /// The state of this browser window.
+    pub state: Option<WindowState>,
+    /// Whether the window is set to be always on top.
+    pub always_on_top: bool,
+    /// The session ID used to uniquely identify a Window obtained from the $(ref:sessions) API.
+    pub session_id: Option<String>,
+    /// The title of the window. Read-only.
+    pub title: Option<String>,
+}
+
+/// Specifies what type of browser window to create. The 'panel' and 'detached_panel' types create a popup unless the '--enable-panels' flag is set.
+pub enum CreateType {
+    Normal,
+    Popup,
+    Panel,
+    DetachedPanel,
+}
+
+/// Specifies whether the $(ref:windows.Window) returned should contain a list of the $(ref:tabs.Tab) objects.
+pub struct GetInfo {
+    /// If true, the $(ref:windows.Window) returned will have a <var>tabs</var> property that contains a list of the $(ref:tabs.Tab) objects. The <code>Tab</code> objects only contain the <code>url</code>, <code>title</code> and <code>favIconUrl</code> properties if the extension's manifest file includes the <code>\"tabs\"</code> permission.
+    pub populate: Option<bool>,
+    /// <code>windowTypes</code> is deprecated and ignored on Firefox.
+    pub window_types: Option<Vec<WindowType>>, // DEPRECATED
+}
+
+// ------ Constants ------
+
+/// The windowId value that represents the absence of a browser window.
+pub const WINDOW_ID_NONE: i64 = -1;
+
+/// The windowId value that represents the $(topic:current-window)[current window].
+pub const WINDOW_ID_CURRENT: i64 = -2;
+
+// ------ Functions ------
+
+/// Gets details about a window.
+// #[async(callback)]
+pub fn get(
+    window_id: i64, // minimum: -2
+    get_info: Option<GetInfo>,
+    callback: impl Fn(Window),
+) {
+    todo!()
+}
+
+/// Gets the $(topic:current-window)[current window].
+// #[async(callback)]
+pub fn get_current(get_info: Option<GetInfo>, callback: impl Fn(Window)) {
+    todo!()
+}
+
+/// Gets the window that was most recently focused &mdash; typically the window 'on top'.
+// #[async(callback)]
+pub fn get_last_focused(get_info: Option<GetInfo>, callback: impl Fn(Window)) {
+    todo!()
+}
+
+/// Gets all windows.
+// #[async(callback)]
+pub fn get_all(get_info: Option<GetInfo>, callback: impl Fn(Vec<Window>)) {
+    todo!()
+}
+
+pub enum OneOrMany<T> {
+    One(T),
+    Many(Vec<T>),
+}
+
+// TODO(V): { "type": "string", "format": "relativeUrl" }
+pub type RelativeURL = String;
+
+pub struct CreateData {
+    /// A URL or array of URLs to open as tabs in the window. Fully-qualified URLs must include a scheme (i.e. 'http://www.google.com', not 'www.google.com'). Relative URLs will be relative to the current page within the extension. Defaults to the New Tab Page.
+    pub url: Option<OneOrMany<RelativeURL>>,
+    /// The id of the tab for which you want to adopt to the new window.
+    pub tab_id: Option<i64>, // minimum: 0
+    /// The number of pixels to position the new window from the left edge of the screen. If not specified, the new window is offset naturally from the last focused window. This value is ignored for panels.
+    pub left: Option<i64>,
+    /// The number of pixels to position the new window from the top edge of the screen. If not specified, the new window is offset naturally from the last focused window. This value is ignored for panels.
+    pub top: Option<i64>,
+    /// The width in pixels of the new window, including the frame. If not specified defaults to a natural width.
+    pub width: Option<i64>, // minimum: 0
+    /// The height in pixels of the new window, including the frame. If not specified defaults to a natural height.
+    pub height: Option<i64>, // minimum: 0
+    /// If true, opens an active window. If false, opens an inactive window.
+    // pub focused: Option<bool>,  // disabled, as true is the only valid choice (deprecated with the message "Opening inactive windows is not supported.")
+    /// Whether the new window should be an incognito window.
+    pub incognito: Option<bool>,
+    /// Specifies what type of browser window to create. The 'panel' and 'detached_panel' types create a popup unless the '--enable-panels' flag is set.
+    pub r#type: Option<CreateType>,
+    /// The initial state of the window. The 'minimized', 'maximized' and 'fullscreen' states cannot be combined with 'left', 'top', 'width' or 'height'.
+    pub state: Option<WindowState>,
+    /// Allow scripts to close the window.
+    pub allow_scripts_to_close: Option<bool>,
+    /// The CookieStoreId to use for all tabs that were created when the window is opened.
+    pub cookie_store_id: Option<String>,
+    /// A string to add to the beginning of the window title.
+    pub title_preface: Option<String>,
+}
+
+/// Creates (opens) a new browser with any optional sizing, position or default URL provided.
+// #[async(callback)]
+pub fn create(create_data: Option<CreateData>, callback: Option<impl Fn(Option<Window>)>) {
+    todo!()
+}
+
+pub struct UpdateInfo {
+    /// The offset from the left edge of the screen to move the window to in pixels. This value is ignored for panels.
+    pub left: Option<i64>,
+    /// The offset from the top edge of the screen to move the window to in pixels. This value is ignored for panels.
+    pub top: Option<i64>,
+    /// The width to resize the window to in pixels. This value is ignored for panels.
+    pub width: Option<i64>, // minimum: 0
+    /// The height to resize the window to in pixels. This value is ignored for panels.
+    pub height: Option<i64>, // minimum: 0
+    /// If true, brings the window to the front. If false, brings the next window in the z-order to the front.
+    pub focused: Option<bool>,
+    /// If true, causes the window to be displayed in a manner that draws the user's attention to the window, without changing the focused window. The effect lasts until the user changes focus to the window. This option has no effect if the window already has focus. Set to false to cancel a previous draw attention request.
+    pub draw_attention: Option<bool>,
+    /// The new state of the window. The 'minimized', 'maximized' and 'fullscreen' states cannot be combined with 'left', 'top', 'width' or 'height'.
+    pub state: Option<WindowState>,
+    /// A string to add to the beginning of the window title.
+    pub title_preface: Option<String>,
+}
+
+/// Updates the properties of a window. Specify only the properties that you want to change; unspecified properties will be left unchanged.
+// #[async(callback)]
+pub fn update(
+    window_id: i64, // minimum: -2
+    update_info: UpdateInfo,
+    callback: Option<impl Fn(Window)>,
+) {
+    todo!()
+}
+
+/// Removes (closes) a window, and all the tabs inside it.
+// #[async(callback)]
+pub fn remove(
+    window_id: i64, // minimum: -2
+    callback: Option<impl Fn()>,
+) {
+    todo!()
+}
+
+// ------ Events ------
+
+// Note: we skip the filters property of all events, since we want all events at all times.
+
+/// Fired when a window is created.
+///
+/// * `window`: Details of the window that was created.
+pub fn on_created(window: Window) {
+    todo!()
+}
+
+/// Fired when a window is removed (closed).
+///
+/// * `window_id`: ID of the removed window.
+pub fn on_removed(window_id: i64, // minimum: 0
+) {
+    todo!()
+}
+
+/// Fired when the currently focused window changes. Will be $(ref:windows.WINDOW_ID_NONE) if all browser windows have lost focus. Note: On some Linux window managers, WINDOW_ID_NONE will always be sent immediately preceding a switch from one browser window to another.
+///
+/// * `window_id`: ID of the newly focused window.
+pub fn on_focus_changed(window_id: i64, // minimum: -1
+) {
+    todo!()
+}