diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..2eb39bd2 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib"] + path = lib + url = git@github.com:Seelen-Inc/slu-lib.git diff --git a/lib b/lib new file mode 160000 index 00000000..c3777e1e --- /dev/null +++ b/lib @@ -0,0 +1 @@ +Subproject commit c3777e1e198ee24f30d84052823b4058557b6564 diff --git a/lib/Cargo.lock b/lib/Cargo.lock deleted file mode 100644 index 4714e975..00000000 --- a/lib/Cargo.lock +++ /dev/null @@ -1,458 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "aho-corasick" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -dependencies = [ - "memchr", -] - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "convert_case" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" - -[[package]] -name = "dyn-clone" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "getrandom" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - -[[package]] -name = "indexmap" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c" -dependencies = [ - "equivalent", - "hashbrown", -] - -[[package]] -name = "itoa" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" - -[[package]] -name = "libc" -version = "0.2.158" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" - -[[package]] -name = "memchr" -version = "2.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" - -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - -[[package]] -name = "proc-macro2" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "regex" -version = "1.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" - -[[package]] -name = "ryu" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" - -[[package]] -name = "schemars" -version = "0.8.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" -dependencies = [ - "dyn-clone", - "schemars_derive", - "serde", - "serde_json", -] - -[[package]] -name = "schemars_derive" -version = "0.8.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" -dependencies = [ - "proc-macro2", - "quote", - "serde_derive_internals", - "syn 2.0.75", -] - -[[package]] -name = "seelen-core" -version = "1.9.7" -dependencies = [ - "regex", - "schemars", - "serde", - "serde_alias", - "serde_json", - "serde_yaml", - "sys-locale", - "uuid", - "windows", -] - -[[package]] -name = "serde" -version = "1.0.208" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_alias" -version = "0.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2be4d78e3674912678d7c86b8c507fa72ebff66a8dd3359dc54ec97164b68474" -dependencies = [ - "convert_case", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "serde_derive" -version = "1.0.208" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.75", -] - -[[package]] -name = "serde_derive_internals" -version = "0.29.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.75", -] - -[[package]] -name = "serde_json" -version = "1.0.125" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83c8e735a073ccf5be70aa8066aa984eaf2fa000db6c8d0100ae605b366d31ed" -dependencies = [ - "itoa", - "memchr", - "ryu", - "serde", -] - -[[package]] -name = "serde_yaml" -version = "0.9.34+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" -dependencies = [ - "indexmap", - "itoa", - "ryu", - "serde", - "unsafe-libyaml", -] - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6af063034fc1935ede7be0122941bafa9bacb949334d090b77ca98b5817c7d9" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "sys-locale" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e801cf239ecd6ccd71f03d270d67dd53d13e90aab208bf4b8fe4ad957ea949b0" -dependencies = [ - "libc", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unsafe-libyaml" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" - -[[package]] -name = "uuid" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" -dependencies = [ - "getrandom", -] - -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "windows" -version = "0.58.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" -dependencies = [ - "windows-core", - "windows-targets", -] - -[[package]] -name = "windows-core" -version = "0.58.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" -dependencies = [ - "windows-implement", - "windows-interface", - "windows-result", - "windows-strings", - "windows-targets", -] - -[[package]] -name = "windows-implement" -version = "0.58.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.75", -] - -[[package]] -name = "windows-interface" -version = "0.58.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.75", -] - -[[package]] -name = "windows-result" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-strings" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" -dependencies = [ - "windows-result", - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/lib/Cargo.toml b/lib/Cargo.toml deleted file mode 100644 index 5578ca31..00000000 --- a/lib/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "seelen-core" -version = "1.9.7" -edition = "2021" - -[dependencies] -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -serde_yaml = "0.9.34" -serde_alias = "0.0.2" -schemars = "0.8.21" -regex = "1.10.4" -sys-locale = "0.3.1" -uuid = { version = "1.8.0", features = ["v4"] } - -[dependencies.windows] -version = "=0.58.0" -features = ["Win32_Foundation"] diff --git a/lib/src/error.rs b/lib/src/error.rs deleted file mode 100644 index 1ee331f7..00000000 --- a/lib/src/error.rs +++ /dev/null @@ -1,41 +0,0 @@ -macro_rules! define_app_errors { - ($( - $variant:ident($error_type:ty); - )*) => { - #[derive(Debug)] - pub enum SeelenLibError { - $( - $variant($error_type), - )* - } - - $( - impl From<$error_type> for SeelenLibError { - fn from(err: $error_type) -> Self { - SeelenLibError::$variant(err) - } - } - )* - }; -} - -define_app_errors!( - Custom(String); - Io(std::io::Error); - SerdeJson(serde_json::Error); - SerdeYaml(serde_yaml::Error); -); - -impl From<&str> for SeelenLibError { - fn from(err: &str) -> Self { - err.to_owned().into() - } -} - -impl std::fmt::Display for SeelenLibError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{:?}", self) - } -} - -pub type Result = std::result::Result; diff --git a/lib/src/handlers/events.ts b/lib/src/handlers/events.ts deleted file mode 100644 index 716a8b2f..00000000 --- a/lib/src/handlers/events.ts +++ /dev/null @@ -1,53 +0,0 @@ -// This file was generated via rust macros. Don't modify manually. -export enum SeelenEvent { - WorkspacesChanged = 'workspaces-changed', - ActiveWorkspaceChanged = 'active-workspace-changed', - GlobalFocusChanged = 'global-focus-changed', - GlobalMouseMove = 'global-mouse-move', - GlobalMonitorsChanged = 'global-monitors-changed', - HandleLayeredHitboxes = 'handle-layered', - MediaSessions = 'media-sessions', - MediaInputs = 'media-inputs', - MediaOutputs = 'media-outputs', - NetworkDefaultLocalIp = 'network-default-local-ip', - NetworkAdapters = 'network-adapters', - NetworkInternetConnection = 'network-internet-connection', - NetworkWlanScanned = 'wlan-scanned', - Notifications = 'notifications', - PowerStatus = 'power-status', - BatteriesStatus = 'batteries-status', - ColorsChanged = 'colors-changed', - TrayInfo = 'tray-info', - ToolbarOverlaped = 'set-auto-hide', - WegOverlaped = 'set-auto-hide', - WegSetFocusedHandle = 'set-focused-handle', - WegSetFocusedExecutable = 'set-focused-executable', - WegUpdateOpenAppInfo = 'update-open-app-info', - WegAddOpenApp = 'add-open-app', - WegRemoveOpenApp = 'remove-open-app', - WMSetReservation = 'set-reservation', - WMUpdateHeight = 'update-height', - WMUpdateWidth = 'update-width', - WMResetWorkspaceSize = 'reset-workspace-size', - WMFocus = 'focus', - WMSetActiveWorkspace = 'set-active-workspace', - WMAddWindow = 'add-window', - WMUpdateWindow = 'update-window', - WMRemoveWindow = 'remove-window', - WMForceRetiling = 'wm-force-retiling', - WMSetLayout = 'wm-set-layout', - WMSetOverlayVisibility = 'wm-set-overlay-visibility', - WMSetActiveWindow = 'wm-set-active-window', - WallStop = 'wall-stop', - StateSettingsChanged = 'settings-changed', - StateWegItemsChanged = 'weg-items', - StateThemesChanged = 'themes', - StatePlaceholdersChanged = 'placeholders', - StateLayoutsChanged = 'layouts', - StateSettingsByAppChanged = 'settings-by-app', - StateHistoryChanged = 'history', - StateIconPacksChanged = 'icon-packs', - StatePluginsChanged = 'plugins-changed', - StateWidgetsChanged = 'widgets-changed', - StateProfilesChanged = 'profiles-changed', -} \ No newline at end of file diff --git a/lib/src/handlers/index.ts b/lib/src/handlers/index.ts deleted file mode 100644 index bec9afd8..00000000 --- a/lib/src/handlers/index.ts +++ /dev/null @@ -1,22 +0,0 @@ -export * from './invokers'; -export * from './events'; - -import { invoke } from '@tauri-apps/api/core'; -import { listen, UnlistenFn } from '@tauri-apps/api/event'; - -import { SeelenEvent } from './events'; -import { SeelenCommand } from './invokers'; - -export function Obtainable(invokeKey: SeelenCommand, eventKey: SeelenEvent) { - return class { - static async getAsync(): Promise { - return await invoke(invokeKey); - } - - static async onChange(cb: (value: T) => void): Promise { - return listen(eventKey, (event) => { - cb(event.payload); - }); - } - }; -} diff --git a/lib/src/handlers/invokers.ts b/lib/src/handlers/invokers.ts deleted file mode 100644 index d5dfc721..00000000 --- a/lib/src/handlers/invokers.ts +++ /dev/null @@ -1,104 +0,0 @@ -import { invoke as tauriInvoke, InvokeArgs, InvokeOptions } from '@tauri-apps/api/core'; - -import { Plugin } from '../state/plugin'; -import { Profile } from '../state/profile'; - -export enum SeelenCommand { - // General - Run = 'run', - IsDevMode = 'is_dev_mode', - OpenFile = 'open_file', - RunAsAdmin = 'run_as_admin', - SelectFileOnExplorer = 'select_file_on_explorer', - IsVirtualDesktopSupported = 'is_virtual_desktop_supported', - GetUserEnvs = 'get_user_envs', - ShowAppSettings = 'show_app_settings', - SwitchWorkspace = 'switch_workspace', - SendKeys = 'send_keys', - GetIcon = 'get_icon', - GetSystemColors = 'get_system_colors', - SimulateFullscreen = 'simulate_fullscreen', - CheckForUpdates = 'check_for_updates', - /** Restart the app after install the update so it returns a promise resolved with `never` */ - InstallLastAvailableUpdate = 'install_last_available_update', - - // Seelen Settings - SetAutoStart = 'set_auto_start', - GetAutoStartStatus = 'get_auto_start_status', - StateGetThemes = 'state_get_themes', - StateGetPlaceholders = 'state_get_placeholders', - StateGetLayouts = 'state_get_layouts', - StateGetWegItems = 'state_get_weg_items', - StateGetSettings = 'state_get_settings', - StateGetSpecificAppsConfigurations = 'state_get_specific_apps_configurations', - StateGetWallpaper = 'state_get_wallpaper', - StateSetWallpaper = 'state_set_wallpaper', - StateGetHistory = 'state_get_history', - StateGetPlugins = 'state_get_plugins', - StateGetWidgets = 'state_get_widgets', - stateGetProfiles = 'state_get_profiles', - - // Media - MediaPrev = 'media_prev', - MediaTogglePlayPause = 'media_toggle_play_pause', - MediaNext = 'media_next', - SetVolumeLevel = 'set_volume_level', - MediaToggleMute = 'media_toggle_mute', - MediaSetDefaultDevice = 'media_set_default_device', - - // Brightness - GetMainMonitorBrightness = 'get_main_monitor_brightness', - SetMainMonitorBrightness = 'set_main_monitor_brightness', - - // Power - LogOut = 'log_out', - Suspend = 'suspend', - Restart = 'restart', - Shutdown = 'shutdown', - - // SeelenWeg - WegCloseApp = 'weg_close_app', - WegToggleWindowState = 'weg_toggle_window_state', - WegRequestUpdatePreviews = 'weg_request_update_previews', - WegPinItem = 'weg_pin_item', - - // Windows Manager - SetWindowPosition = 'set_window_position', - RequestFocus = 'request_focus', - - // App Launcher - LauncherGetApps = 'launcher_get_apps', - - // Tray Icons - TempGetByEventTrayInfo = 'temp_get_by_event_tray_info', - OnClickTrayIcon = 'on_click_tray_icon', - OnContextMenuTrayIcon = 'on_context_menu_tray_icon', - - // Network - WlanGetProfiles = 'wlan_get_profiles', - WlanStartScanning = 'wlan_start_scanning', - WlanStopScanning = 'wlan_stop_scanning', - WlanConnect = 'wlan_connect', - WlanDisconnect = 'wlan_disconnect', - - // Notifications - NotificationsClose = 'notifications_close', - NotificationsCloseAll = 'notifications_close_all', -} - -type ReturnTypeByCommand = Record & { - [SeelenCommand.CheckForUpdates]: boolean; - [SeelenCommand.InstallLastAvailableUpdate]: never; - [SeelenCommand.StateGetPlugins]: Plugin[]; - [SeelenCommand.stateGetProfiles]: Profile[]; -}; - -export type SeelenCommandReturn = ReturnTypeByCommand[T]; - -export async function invoke( - command: T, - args?: InvokeArgs, - options?: InvokeOptions, -): Promise> { - return tauriInvoke(command, args, options); -} diff --git a/lib/src/handlers/mod.rs b/lib/src/handlers/mod.rs deleted file mode 100644 index 7d671993..00000000 --- a/lib/src/handlers/mod.rs +++ /dev/null @@ -1,92 +0,0 @@ -pub struct SeelenEvent; - -macro_rules! slu_events_declaration { - ($($name:ident = $value:literal,)*) => { - #[allow(non_upper_case_globals)] - impl SeelenEvent { - $( - pub const $name: &str = $value; - )* - - #[allow(dead_code)] - pub(crate) fn generate_ts_file(path: &str) { - let content: Vec = vec![ - "// This file was generated via rust macros. Don't modify manually.".to_owned(), - "export enum SeelenEvent {".to_owned(), - $( - format!(" {} = '{}',", stringify!($name), Self::$name), - )* - "}".to_owned(), - ]; - std::fs::write(path, content.join("\n")).unwrap(); - } - } - }; -} - -slu_events_declaration! { - WorkspacesChanged = "workspaces-changed", - ActiveWorkspaceChanged = "active-workspace-changed", - - GlobalFocusChanged = "global-focus-changed", - GlobalMouseMove = "global-mouse-move", - GlobalMonitorsChanged = "global-monitors-changed", - - HandleLayeredHitboxes = "handle-layered", - - MediaSessions = "media-sessions", - MediaInputs = "media-inputs", - MediaOutputs = "media-outputs", - - NetworkDefaultLocalIp = "network-default-local-ip", - NetworkAdapters = "network-adapters", - NetworkInternetConnection = "network-internet-connection", - NetworkWlanScanned = "wlan-scanned", - - Notifications = "notifications", - - PowerStatus = "power-status", - BatteriesStatus = "batteries-status", - - ColorsChanged = "colors-changed", - - TrayInfo = "tray-info", - - ToolbarOverlaped = "set-auto-hide", - - WegOverlaped = "set-auto-hide", - WegSetFocusedHandle = "set-focused-handle", - WegSetFocusedExecutable = "set-focused-executable", - WegUpdateOpenAppInfo = "update-open-app-info", - WegAddOpenApp = "add-open-app", - WegRemoveOpenApp = "remove-open-app", - - WMSetReservation = "set-reservation", - WMUpdateHeight = "update-height", - WMUpdateWidth = "update-width", - WMResetWorkspaceSize = "reset-workspace-size", - WMFocus = "focus", - WMSetActiveWorkspace = "set-active-workspace", - WMAddWindow = "add-window", - WMUpdateWindow = "update-window", - WMRemoveWindow = "remove-window", - - WMForceRetiling = "wm-force-retiling", - WMSetLayout = "wm-set-layout", - WMSetOverlayVisibility = "wm-set-overlay-visibility", - WMSetActiveWindow = "wm-set-active-window", - - WallStop = "wall-stop", - - StateSettingsChanged = "settings-changed", - StateWegItemsChanged = "weg-items", - StateThemesChanged = "themes", - StatePlaceholdersChanged = "placeholders", - StateLayoutsChanged = "layouts", - StateSettingsByAppChanged = "settings-by-app", - StateHistoryChanged = "history", - StateIconPacksChanged = "icon-packs", - StatePluginsChanged = "plugins-changed", - StateWidgetsChanged = "widgets-changed", - StateProfilesChanged = "profiles-changed", -} diff --git a/lib/src/lib.rs b/lib/src/lib.rs deleted file mode 100644 index e9fabd82..00000000 --- a/lib/src/lib.rs +++ /dev/null @@ -1,7 +0,0 @@ -pub mod error; -pub mod rect; -pub mod state; -pub mod system_state; -pub mod handlers; - -pub use error::SeelenLibError; \ No newline at end of file diff --git a/lib/src/lib.ts b/lib/src/lib.ts deleted file mode 100644 index b64962fd..00000000 --- a/lib/src/lib.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './state'; -export * from './system_state'; -export * from './utils'; -export * from './handlers'; \ No newline at end of file diff --git a/lib/src/main.rs b/lib/src/main.rs deleted file mode 100644 index efe952b3..00000000 --- a/lib/src/main.rs +++ /dev/null @@ -1,25 +0,0 @@ -mod handlers; - -use seelen_core::state::{ - AppConfig, IconPack, Placeholder, Settings, Theme, WegItem, WindowManagerLayout, -}; - -fn write_schema(path: &str) -where - T: schemars::JsonSchema, -{ - let schema = schemars::schema_for!(T); - std::fs::write(path, serde_json::to_string_pretty(&schema).unwrap()).unwrap(); -} - -fn main() { - write_schema::("./dist/settings.schema.json"); - write_schema::("./dist/placeholder.schema.json"); - write_schema::("./dist/theme.schema.json"); - write_schema::("./dist/layout.schema.json"); - write_schema::>("./dist/settings_by_app.schema.json"); - write_schema::>("./dist/weg_items.schema.json"); - write_schema::("./dist/icon_pack.schema.json"); - - handlers::SeelenEvent::generate_ts_file("./src/handlers/events.ts"); -} diff --git a/lib/src/rect.rs b/lib/src/rect.rs deleted file mode 100644 index 6d64b8a2..00000000 --- a/lib/src/rect.rs +++ /dev/null @@ -1,43 +0,0 @@ -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; -use windows::Win32::Foundation::RECT; - -#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)] -pub struct Rect { - pub left: i32, - pub top: i32, - pub right: i32, - pub bottom: i32, -} - -impl From for Rect { - fn from(rect: RECT) -> Self { - Self { - left: rect.left, - top: rect.top, - right: rect.right, - bottom: rect.bottom, - } - } -} - -impl From for RECT { - fn from(val: Rect) -> Self { - RECT { - left: val.left, - top: val.top, - right: val.right, - bottom: val.bottom, - } - } -} - -impl Eq for Rect {} -impl PartialEq for Rect { - fn eq(&self, other: &Self) -> bool { - self.left == other.left - && self.top == other.top - && self.right == other.right - && self.bottom == other.bottom - } -} diff --git a/lib/src/state/icon_pack.rs b/lib/src/state/icon_pack.rs deleted file mode 100644 index 9ad1e2d4..00000000 --- a/lib/src/state/icon_pack.rs +++ /dev/null @@ -1,16 +0,0 @@ -use std::{collections::HashMap, path::PathBuf}; - -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -use super::ResourceMetadata; - -#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct IconPack { - pub info: ResourceMetadata, - /// Key can be user model id, filename or a full path. - /// - /// Value is the path to the icon relative to the icon pack folder. - pub apps: HashMap, -} diff --git a/lib/src/state/icon_pack.ts b/lib/src/state/icon_pack.ts deleted file mode 100644 index 583cae1b..00000000 --- a/lib/src/state/icon_pack.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { ResourceMetadata } from '.'; - -export class IconPack { - info: ResourceMetadata = new ResourceMetadata(); - apps: Record = {}; -} diff --git a/lib/src/state/index.ts b/lib/src/state/index.ts deleted file mode 100644 index 1cdd9708..00000000 --- a/lib/src/state/index.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Obtainable, SeelenCommand, SeelenEvent } from '../handlers'; - -export * from './theme'; -export * from './settings'; -export * from './weg_items'; -export * from './wm_layout'; -export * from './placeholder'; -export * from './settings_by_app'; -export * from './settings_by_monitor'; -export * from './icon_pack'; -export * from './plugin'; -export * from './widget'; -export * from './profile'; - -export interface LauncherHistory { - [x: string]: string[]; -} -export const LauncherHistory = Obtainable( - SeelenCommand.StateGetHistory, - SeelenEvent.StateHistoryChanged, -); - -export class ResourceMetadata { - displayName: string = 'Unknown'; - author: string = 'Unknown'; - description: string = ''; - filename: string = ''; - tags: string[] = []; -} \ No newline at end of file diff --git a/lib/src/state/mod.rs b/lib/src/state/mod.rs deleted file mode 100644 index ab6638bc..00000000 --- a/lib/src/state/mod.rs +++ /dev/null @@ -1,48 +0,0 @@ -mod icon_pack; -mod placeholder; -mod settings; -mod settings_by_app; -mod settings_by_monitor; -mod theme; -mod weg_items; -mod wm_layout; -mod plugin; -mod widget; -mod profile; - -pub use icon_pack::*; -pub use placeholder::*; -pub use settings::*; -pub use settings_by_app::*; -pub use settings_by_monitor::*; -pub use theme::*; -pub use weg_items::*; -pub use wm_layout::*; -pub use plugin::*; -pub use widget::*; -pub use profile::*; - -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct ResourceMetadata { - pub display_name: String, - pub author: String, - pub description: String, - pub filename: String, - pub tags: Vec, -} - -impl Default for ResourceMetadata { - fn default() -> Self { - Self { - display_name: "Unknown".to_string(), - author: "Unknown".to_string(), - description: String::new(), - filename: String::new(), - tags: Vec::new(), - } - } -} diff --git a/lib/src/state/placeholder.rs b/lib/src/state/placeholder.rs deleted file mode 100644 index b9458c04..00000000 --- a/lib/src/state/placeholder.rs +++ /dev/null @@ -1,382 +0,0 @@ -use std::collections::{HashMap, HashSet}; - -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -macro_rules! common_item { - ( - $( - $(#[$scope:meta])* - struct $name:ident { - $($rest:tt)* - } - )* - ) => { - $( - #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] - #[serde(rename_all = "camelCase")] - pub struct $name { - /// Id to identify the item, should be unique. - #[serde(default)] - id: String, - /// Content to display in the item. - /// - /// Should follow the [mathjs expression syntax](https://mathjs.org/docs/expressions/syntax.html). - /// - $(#[$scope])* - #[serde(default)] - template: String, - /// Content to display in tooltip of the item. - /// - /// Should follow the [mathjs expression syntax](https://mathjs.org/docs/expressions/syntax.html). - /// - $(#[$scope])* - tooltip: Option, - /// Badge will be displayed over the item, useful as notifications. - /// - /// Should follow the [mathjs expression syntax](https://mathjs.org/docs/expressions/syntax.html). - /// - $(#[$scope])* - badge: Option, - /// Deprecated use `onClickV2` instead. - on_click: Option, - /// This code will be parsed and executed when the item is clicked. - /// - /// Should follow the [mathjs expression syntax](https://mathjs.org/docs/expressions/syntax.html). - /// - $(#[$scope])* - on_click_v2: Option, - /// Styles to be added to the item. This follow the same interface of React's `style` prop. - #[serde(default)] - style: HashMap>, - $($rest)* - } - )* - }; -} - -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -#[serde(untagged)] -pub enum StyleValue { - String(String), - PosInt(u64), - /// Always less than zero. - NegInt(i64), - /// Always finite. - Float(f64), -} - -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -#[serde(rename_all = "camelCase")] -pub enum DateUpdateInterval { - Millisecond, - Second, - Minute, - Hour, - Day, -} - -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -#[serde(rename_all = "camelCase")] -pub enum WorkspaceToolbarItemMode { - Dotted, - Named, - Numbered, -} - -common_item! { - /// ## Base Item Scope - /// Have all icons defined on [React Icons](https://react-icons.github.io/react-icons) as properties of the object. - /// ```js - /// const icon: object; - /// ``` - /// Haves all environment variables defined on the system as properties of the object. - /// ```js - /// const env: object; - /// ``` - /// Functions to add images to the item. - /// ```js - /// function getIcon(name: string, size: number = 16): string - /// function imgFromUrl (url: string, size: number = 16): string - /// function imgFromPath (path: string, size: number = 16): string - /// function imgFromExe (exe_path: string, size: number = 16): string - /// function t(path: string): string - /// ``` - struct TextToolbarItem {} - - /// ## Generic Item Scope - /// ```ts - /// // the current focused window - /// const window: { - /// name: string; - /// title: string; - /// exe: string | null; - /// }; - /// ``` - struct GenericToolbarItem {} - - /// ## Date Item Scope - /// ```ts - /// const date: string; // the formatted date - /// ``` - struct DateToolbarItem { - /// @deprecated -- v2 uses settings date format instead (it will perform the minimal updates) - #[serde(default = "DateToolbarItem::default_interval")] - each: DateUpdateInterval, - /// @deprecated -- v2 uses settings date format instead - #[serde(default = "DateToolbarItem::default_format")] - format: String, - } - - /// ## Power Item Scope - /// ```ts - /// interface PowerStatus { - /// acLineStatus: number; - /// batteryFlag: number; - /// batteryLifePercent: number; - /// systemStatusFlag: number; - /// batteryLifeTime: number; - /// batteryFullLifeTime: number; - /// } - /// - /// interface Battery { - /// // Static info - /// vendor: string | null; - /// model: string | null; - /// serialNumber: string | null; - /// technology: string; - /// - /// // Common information - /// state: string; - /// capacity: number; - /// temperature: number | null; - /// percentage: number; - /// cycleCount: number | null; - /// smartCharging: boolean; - /// - /// // Energy stats - /// energy: number; - /// energyFull: number; - /// energyFullDesign: number; - /// energyRate: number; - /// voltage: number; - /// - /// // Charge stats - /// timeToFull: number | null; - /// timeToEmpty: number | null; - /// } - /// - /// const power: PowerStatus; - /// const batteries: Battery[]; - /// const battery: Battery | null; - /// ``` - struct PowerToolbarItem {} - - /// ## Network Item Scope - /// ```ts - /// interface NetworkInterface { - /// name: string; - /// description: string; - /// status: 'up' | 'down'; - /// dnsSuffix: string; - /// type: string; - /// gateway: string | null; - /// mac: string; - /// ipv4: string | null; - /// ipv6: string | null; - /// } - /// const online: boolean; - /// const interfaces: NetworkInterface[]; - /// const usingInterface: NetworkInterface | null; - /// ``` - struct NetworkToolbarItem { - /// Show Wi-fi selector popup on click] - #[serde(default)] - with_wlan_selector: bool, - } - - /// ## Media Item Scope - /// ```ts - /// const volume: number; // output master volume from 0 to 1 - /// const isMuted: boolean; // output master volume is muted - /// const inputVolume: number; // input master volume from 0 to 1 - /// const inputIsMuted: boolean; // input master volume is muted - /// - /// interface MediaSession { - /// id: string; - /// title: string; - /// author: string; - /// thumbnail: string | null; // path to temporal media session image - /// playing: boolean; - /// default: boolean; - /// owner: { - /// name: string; - /// iconPath: string | null; - /// } | null; - /// } - /// - /// const mediaSession: MediaSession | null; - /// ``` - struct MediaToolbarItem { - /// Show media controls popup on click - #[serde(default)] - with_media_controls: bool, - } - - /// ## Notifications Item Scope - /// ```ts - /// const count: number; - /// ``` - struct NotificationsToolbarItem {} - - /// ## Workspace Item Scope - /// this module does no expand the scope of the item - struct TrayToolbarItem {} - - /// ## Device Item Scope - /// this module does no expand the scope of the item - struct DeviceToolbarItem {} - - /// ## Settings Item Scope - /// this module does no expand the scope of the item - struct SettingsToolbarItem {} - - /// ## Workspace Item Scope - /// this module does no expand the scope of the item - struct WorkspaceToolbarItem { - #[serde(default = "WorkspaceToolbarItem::default_mode")] - mode: WorkspaceToolbarItemMode, - } -} - -impl DateToolbarItem { - fn default_interval() -> DateUpdateInterval { - DateUpdateInterval::Minute - } - - fn default_format() -> String { - "MMM Do, HH:mm".to_string() - } -} - -impl WorkspaceToolbarItem { - fn default_mode() -> WorkspaceToolbarItemMode { - WorkspaceToolbarItemMode::Dotted - } -} - -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -#[serde(tag = "type", rename_all = "camelCase")] -pub enum ToolbarItem { - Text(TextToolbarItem), - Generic(GenericToolbarItem), - Date(DateToolbarItem), - Power(PowerToolbarItem), - Network(NetworkToolbarItem), - Media(MediaToolbarItem), - Notifications(NotificationsToolbarItem), - Tray(TrayToolbarItem), - Device(DeviceToolbarItem), - Settings(SettingsToolbarItem), - Workspaces(WorkspaceToolbarItem), -} - -impl ToolbarItem { - pub fn id(&self) -> String { - match self { - ToolbarItem::Text(item) => item.id.clone(), - ToolbarItem::Generic(item) => item.id.clone(), - ToolbarItem::Date(item) => item.id.clone(), - ToolbarItem::Power(item) => item.id.clone(), - ToolbarItem::Network(item) => item.id.clone(), - ToolbarItem::Media(item) => item.id.clone(), - ToolbarItem::Notifications(item) => item.id.clone(), - ToolbarItem::Tray(item) => item.id.clone(), - ToolbarItem::Device(item) => item.id.clone(), - ToolbarItem::Settings(item) => item.id.clone(), - ToolbarItem::Workspaces(item) => item.id.clone(), - } - } - - pub fn set_id(&mut self, id: String) { - match self { - ToolbarItem::Text(item) => item.id = id, - ToolbarItem::Generic(item) => item.id = id, - ToolbarItem::Date(item) => item.id = id, - ToolbarItem::Power(item) => item.id = id, - ToolbarItem::Network(item) => item.id = id, - ToolbarItem::Media(item) => item.id = id, - ToolbarItem::Notifications(item) => item.id = id, - ToolbarItem::Tray(item) => item.id = id, - ToolbarItem::Device(item) => item.id = id, - ToolbarItem::Settings(item) => item.id = id, - ToolbarItem::Workspaces(item) => item.id = id, - } - } -} - -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -#[serde(untagged)] -pub enum ToolbarItem2 { - PluginId(String), - Inline(ToolbarItem) -} - -#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct PlaceholderInfo { - /// Display name of the placeholder - pub display_name: String, - /// Author of the placeholder - pub author: String, - /// Description of the placeholder - pub description: String, - /// Filename of the placeholder, is overridden by the program on load. - pub filename: String, -} - -#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct Placeholder { - /// Metadata about the placeholder - pub info: PlaceholderInfo, - /// Items to be displayed in the toolbar - pub left: Vec, - /// Items to be displayed in the toolbar - pub center: Vec, - /// Items to be displayed in the toolbar - pub right: Vec, -} - -impl Placeholder { - fn sanitize_items(dict: &mut HashSet, items: Vec) -> Vec { - let mut result = Vec::new(); - for item in items { - match item { - ToolbarItem2::PluginId(id) => { - if !dict.contains(&id) { - dict.insert(id.clone()); - result.push(ToolbarItem2::PluginId(id)); - } - } - ToolbarItem2::Inline(mut item) => { - if item.id().is_empty() { - item.set_id(uuid::Uuid::new_v4().to_string()); - } - if !dict.contains(&item.id()) { - dict.insert(item.id()); - result.push(ToolbarItem2::Inline(item)); - } - } - } - } - result - } - - pub fn sanitize(&mut self) { - let mut dict = HashSet::new(); - self.left = Self::sanitize_items(&mut dict, std::mem::take(&mut self.left)); - self.center = Self::sanitize_items(&mut dict, std::mem::take(&mut self.center)); - self.right = Self::sanitize_items(&mut dict, std::mem::take(&mut self.right)); - } -} diff --git a/lib/src/state/placeholder.ts b/lib/src/state/placeholder.ts deleted file mode 100644 index 1477c909..00000000 --- a/lib/src/state/placeholder.ts +++ /dev/null @@ -1,117 +0,0 @@ -export enum ToolbarModuleType { - Generic = 'generic', - Text = 'text', - Date = 'date', - Power = 'power', - Settings = 'settings', - Network = 'network', - Workspaces = 'workspaces', - Media = 'media', - Tray = 'tray', - Device = 'device', - Notifications = 'notifications', -} - -export enum WorkspaceTMMode { - Dotted = 'dotted', - Named = 'named', - Numbered = 'numbered', -} - -export enum TimeUnit { - SECOND = 'second', - MINUTE = 'minute', - HOUR = 'hour', - DAY = 'day', -} - -export enum DeviceTMSubType { - Disk = 'disk', - CPU = 'cpu', - Memory = 'memory', -} - -export interface BaseToolbarModule { - id: string; - type: ToolbarModuleType; - template: string; - tooltip: string | null; - badge: string | null; - /** @deprecated, use `onClickV2` instead */ - onClick: string | null; - onClickV2: string | null; - style: Record; -} - -export interface GenericToolbarModule extends BaseToolbarModule { - type: ToolbarModuleType.Generic | ToolbarModuleType.Text; -} - -export interface TrayTM extends BaseToolbarModule { - type: ToolbarModuleType.Tray; -} - -export interface DateToolbarModule extends BaseToolbarModule { - type: ToolbarModuleType.Date; - /** @deprecated v2 uses settings date format instead (it will perform the minimal updates) */ - each: TimeUnit; - /** @deprecated v2 uses settings date format instead */ - format: string; -} - -export interface PowerToolbarModule extends BaseToolbarModule { - type: ToolbarModuleType.Power; -} - -export interface NetworkTM extends BaseToolbarModule { - type: ToolbarModuleType.Network; - withWlanSelector: boolean; -} - -export interface MediaTM extends BaseToolbarModule { - type: ToolbarModuleType.Media; - withMediaControls: boolean; -} - -export interface NotificationsTM extends BaseToolbarModule { - type: ToolbarModuleType.Notifications; -} - -export interface DeviceTM extends BaseToolbarModule { - type: ToolbarModuleType.Device; -} - -export interface SettingsToolbarModule extends BaseToolbarModule { - type: ToolbarModuleType.Settings; -} - -export interface WorkspacesTM extends BaseToolbarModule { - type: ToolbarModuleType.Workspaces; - mode: WorkspaceTMMode; -} - -export type ToolbarModule = - | GenericToolbarModule - | DateToolbarModule - | PowerToolbarModule - | SettingsToolbarModule - | WorkspacesTM - | TrayTM - | NetworkTM - | MediaTM - | DeviceTM - | NotificationsTM; - -export interface CreatorInfo { - displayName: string; - author: string; - description: string; - filename: string; -} - -export interface Placeholder { - info: CreatorInfo; - left: (string | ToolbarModule)[]; - center: (string | ToolbarModule)[]; - right: (string | ToolbarModule)[]; -} diff --git a/lib/src/state/plugin.rs b/lib/src/state/plugin.rs deleted file mode 100644 index 92264c0e..00000000 --- a/lib/src/state/plugin.rs +++ /dev/null @@ -1,10 +0,0 @@ -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Plugin { - pub id: String, - pub target: String, - pub plugin: serde_yaml::Value, - #[serde(default)] - pub bundled: bool, -} \ No newline at end of file diff --git a/lib/src/state/plugin.ts b/lib/src/state/plugin.ts deleted file mode 100644 index fe44e306..00000000 --- a/lib/src/state/plugin.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { listen, UnlistenFn } from '@tauri-apps/api/event'; - -import { invoke, SeelenCommand, SeelenEvent } from '../handlers'; -import { getCurrentWidget } from '../utils'; - -export class Plugin { - id: string = ''; - target: string = ''; - plugin: any = {}; - bundled: boolean = false; -} - -export class PluginList { - private constructor(private inner: Plugin[]) {} - - static async getAsync(): Promise { - return new PluginList(await invoke(SeelenCommand.StateGetPlugins)); - } - - static async onChange(cb: (value: PluginList) => void): Promise { - return listen(SeelenEvent.StatePluginsChanged, (event) => { - cb(new PluginList(event.payload)); - }); - } - - all(): Plugin[] { - return this.inner; - } - - forCurrentWidget(): Plugin[] { - let target = getCurrentWidget().id; - return this.inner.filter((plugin) => plugin.target === target); - } -} diff --git a/lib/src/state/profile.rs b/lib/src/state/profile.rs deleted file mode 100644 index af1e063f..00000000 --- a/lib/src/state/profile.rs +++ /dev/null @@ -1,57 +0,0 @@ -use std::path::Path; - -use serde::{Deserialize, Serialize}; - -use crate::error::Result; - -use super::Placeholder; - -#[derive(Debug, Clone, Default, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ProfileSettings { - themes: Vec, -} - -#[derive(Debug, Clone, Default, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct Profile { - name: String, - toolbar_layout: Placeholder, - settings: ProfileSettings, -} - -impl Profile { - pub fn load(profile_dir: &Path) -> Result { - if !profile_dir.is_dir() { - return Err("Invalid profile path".into()); - } - let profile = Profile { - name: profile_dir - .file_name() - .unwrap() - .to_string_lossy() - .to_string(), - toolbar_layout: serde_yaml::from_reader(std::fs::File::open( - profile_dir.join("toolbar.yml"), - )?)?, - settings: serde_json::from_reader(std::fs::File::open( - profile_dir.join("settings.json"), - )?)?, - }; - Ok(profile) - } - - pub fn save(&self, path: &Path) -> Result<()> { - let folder = path.join(&self.name); - std::fs::create_dir_all(&folder)?; - std::fs::write( - folder.join("toolbar.yml"), - serde_yaml::to_string(&self.toolbar_layout)?, - )?; - std::fs::write( - folder.join("settings.json"), - serde_json::to_string(&self.settings)?, - )?; - Ok(()) - } -} diff --git a/lib/src/state/profile.ts b/lib/src/state/profile.ts deleted file mode 100644 index 86875e8e..00000000 --- a/lib/src/state/profile.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { invoke, SeelenCommand } from '../handlers'; -import { Placeholder } from './placeholder'; - -export interface ProfileSettings { - themes: string[]; -} - -export interface Profile { - name: string; - toolbarLayour: Placeholder; - settings: ProfileSettings; -} - -export class ProfileList { - private constructor(private inner: Profile[]) {} - - static async getAsync(): Promise { - return new ProfileList(await invoke(SeelenCommand.stateGetProfiles)); - } - - toArray(): Profile[] { - return this.inner; - } -} \ No newline at end of file diff --git a/lib/src/state/settings.rs b/lib/src/state/settings.rs deleted file mode 100644 index 14e9a888..00000000 --- a/lib/src/state/settings.rs +++ /dev/null @@ -1,599 +0,0 @@ -/* In this file we use #[serde_alias(SnakeCase)] as backward compatibility from versions below v1.9.8 */ - -use std::{ - collections::{HashMap, HashSet}, - path::PathBuf, -}; - -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; -use serde_alias::serde_alias; - -use crate::rect::Rect; - -use super::MonitorConfiguration; - -// ============== Fancy Toolbar Settings ============== - -#[serde_alias(SnakeCase)] -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct FancyToolbarSettings { - /// enable or disable the fancy toolbar - pub enabled: bool, - /// height of the fancy toolbar - pub height: u32, - /// default placeholder for the fancy toolbar - pub placeholder: String, - /// hide mode - pub hide_mode: HideMode, - /// delay to show the toolbar on Mouse Hover in milliseconds - pub delay_to_show: u32, - /// delay to hide the toolbar on Mouse Leave in milliseconds - pub delay_to_hide: u32, -} - -impl Default for FancyToolbarSettings { - fn default() -> Self { - Self { - enabled: true, - height: 30, - placeholder: String::from("default.yml"), - hide_mode: HideMode::Never, - delay_to_show: 100, - delay_to_hide: 800, - } - } -} - -// ============== SeelenWeg Settings ============== - -#[derive(Debug, Copy, Clone, Serialize, Deserialize, JsonSchema, PartialEq, Eq)] -pub enum SeelenWegMode { - #[serde(rename = "Full-Width")] - FullWidth, - #[serde(rename = "Min-Content")] - MinContent, -} - -#[derive(Debug, Copy, Clone, Serialize, Deserialize, JsonSchema, PartialEq, Eq)] -pub enum HideMode { - /// never hide - Never, - /// auto-hide always on - Always, - /// auto-hide only if is overlaped by the focused window - #[serde(rename = "On-Overlap")] - OnOverlap, -} - -#[derive(Debug, Copy, Clone, Serialize, Deserialize, JsonSchema, PartialEq, Eq)] -pub enum SeelenWegSide { - Left, - Right, - Top, - Bottom, -} - -#[serde_alias(SnakeCase)] -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct SeelenWegSettings { - /// enable or disable the seelenweg - pub enabled: bool, - /// Dock/Taskbar mode - pub mode: SeelenWegMode, - /// When to hide the dock - pub hide_mode: HideMode, - /// Dock position - pub position: SeelenWegSide, - /// enable or disable separators visibility - pub visible_separators: bool, - /// item size in px - pub size: u32, - /// zoomed item size in px - pub zoom_size: u32, - /// Dock/Taskbar margin in px - pub margin: u32, - /// Dock/Taskbar padding in px - pub padding: u32, - /// space between items in px - pub space_between_items: u32, - /// delay to show the toolbar on Mouse Hover in milliseconds - pub delay_to_show: u32, - /// delay to hide the toolbar on Mouse Leave in milliseconds - pub delay_to_hide: u32, -} - -impl Default for SeelenWegSettings { - fn default() -> Self { - Self { - enabled: true, - mode: SeelenWegMode::MinContent, - hide_mode: HideMode::OnOverlap, - position: SeelenWegSide::Bottom, - visible_separators: true, - size: 40, - zoom_size: 70, - margin: 8, - padding: 8, - space_between_items: 8, - delay_to_show: 100, - delay_to_hide: 800, - } - } -} - -impl SeelenWegSettings { - /// total height or width of the dock, depending on the Position - pub fn total_size(&self) -> u32 { - self.size + (self.padding * 2) + (self.margin * 2) - } -} - -// ============== Window Manager Settings ============== - -#[serde_alias(SnakeCase)] -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct Border { - pub enabled: bool, - pub width: f64, - pub offset: f64, -} - -#[serde_alias(SnakeCase)] -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct FloatingWindowSettings { - pub width: f64, - pub height: f64, -} - -#[serde_alias(SnakeCase)] -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct WindowManagerSettings { - /// enable or disable the window manager - pub enabled: bool, - /// enable or disable auto stacking by category - pub auto_stacking_by_category: bool, - /// window manager border - pub border: Border, - /// the resize size in % to be used when resizing via cli - pub resize_delta: f32, - /// default gap between containers - pub workspace_gap: u32, - /// default workspace padding - pub workspace_padding: u32, - /// default workspace margin - #[serde(alias = "global_work_area_offset")] - pub workspace_margin: Rect, - /// floating window settings - pub floating: FloatingWindowSettings, - /// default layout - pub default_layout: String, -} - -impl Default for Border { - fn default() -> Self { - Self { - enabled: true, - width: 3.0, - offset: 0.0, - } - } -} - -impl Default for FloatingWindowSettings { - fn default() -> Self { - Self { - width: 800.0, - height: 500.0, - } - } -} - -impl Default for WindowManagerSettings { - fn default() -> Self { - Self { - enabled: false, - auto_stacking_by_category: true, - border: Border::default(), - resize_delta: 10.0, - workspace_gap: 10, - workspace_padding: 10, - workspace_margin: Rect::default(), - floating: FloatingWindowSettings::default(), - default_layout: String::from("default.yml"), - } - } -} - -// ================= Seelen Launcher ================ - -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -pub enum SeelenLauncherMonitor { - Primary, - #[serde(rename = "Mouse-Over")] - MouseOver, -} - -#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct SeelenLauncherRunner { - pub id: String, - pub label: String, - pub program: String, - pub readonly: bool, -} - -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct SeelenLauncherSettings { - pub enabled: bool, - pub monitor: SeelenLauncherMonitor, - pub runners: Vec, -} - -impl Default for SeelenLauncherSettings { - fn default() -> Self { - Self { - enabled: false, - monitor: SeelenLauncherMonitor::MouseOver, - runners: vec![ - SeelenLauncherRunner { - id: "RUN".to_owned(), - label: "t:app_launcher.runners.explorer".to_owned(), - program: "explorer.exe".to_owned(), - readonly: true, - }, - SeelenLauncherRunner { - id: "CMD".to_owned(), - label: "t:app_launcher.runners.cmd".to_owned(), - program: "cmd.exe".to_owned(), - readonly: true, - }, - ], - } - } -} - -impl SeelenLauncherSettings { - pub fn sanitize(&mut self) { - let mut dict = HashSet::new(); - self.runners - .retain(|runner| !runner.program.is_empty() && dict.insert(runner.program.clone())); - for runner in &mut self.runners { - if runner.id.is_empty() { - runner.id = uuid::Uuid::new_v4().to_string(); - } - } - } -} - -// ================= Seelen Wall ================ - -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -#[serde(rename_all = "camelCase")] -pub struct SeelenWallWallpaper { - pub id: String, - pub path: PathBuf, -} - -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct SeelenWallSettings { - pub enabled: bool, - pub backgrounds: Vec, - /// update interval in seconds - pub interval: u64, - pub randomize: bool, -} - -impl Default for SeelenWallSettings { - fn default() -> Self { - Self { - enabled: true, - backgrounds: vec![], - interval: 60, - randomize: false, - } - } -} - -impl SeelenWallSettings { - pub fn sanitize(&mut self) { - self.backgrounds.retain(|b| b.path.exists()); - } -} - -// ============== Ahk Variables ============== - -#[macro_export] -macro_rules! define_struct_and_hashmap { - ( - $($field:ident),* - ) => { - #[serde_alias(SnakeCase)] - #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] - #[serde(default, rename_all = "camelCase")] - pub struct AhkVarList { - $( - pub $field: AhkVar, - )* - } - - impl AhkVarList { - pub fn as_hash_map(&self) -> HashMap { - let mut map = HashMap::new(); - $( - map.insert( - stringify!($field).to_string(), - self.$field.clone() - ); - )* - map - } - } - }; -} - -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -pub struct AhkVar { - pub fancy: String, - pub ahk: String, - #[serde(default)] - pub readonly: bool, -} - -impl AhkVar { - pub fn new(f: &str, ahk: &str) -> Self { - Self { - fancy: f.to_string(), - ahk: ahk.to_string(), - readonly: false, - } - } - - pub fn readonly(mut self) -> Self { - self.readonly = true; - self - } -} - -define_struct_and_hashmap![ - toggle_launcher, - reserve_top, - reserve_bottom, - reserve_left, - reserve_right, - reserve_float, - reserve_stack, - focus_top, - focus_bottom, - focus_left, - focus_right, - focus_latest, - increase_width, - decrease_width, - increase_height, - decrease_height, - restore_sizes, - switch_workspace_0, - switch_workspace_1, - switch_workspace_2, - switch_workspace_3, - switch_workspace_4, - switch_workspace_5, - switch_workspace_6, - switch_workspace_7, - switch_workspace_8, - switch_workspace_9, - move_to_workspace_0, - move_to_workspace_1, - move_to_workspace_2, - move_to_workspace_3, - move_to_workspace_4, - move_to_workspace_5, - move_to_workspace_6, - move_to_workspace_7, - move_to_workspace_8, - move_to_workspace_9, - send_to_workspace_0, - send_to_workspace_1, - send_to_workspace_2, - send_to_workspace_3, - send_to_workspace_4, - send_to_workspace_5, - send_to_workspace_6, - send_to_workspace_7, - send_to_workspace_8, - send_to_workspace_9, - misc_open_settings, - misc_toggle_lock_tracing, - misc_toggle_win_event_tracing -]; - -impl Default for AhkVarList { - fn default() -> Self { - Self { - // launcher - toggle_launcher: AhkVar::new("Win + Space", "LWin & Space").readonly(), - // wm - reserve_top: AhkVar::new("Win + Shift + I", "#+i"), - reserve_bottom: AhkVar::new("Win + Shift + K", "#+k"), - reserve_left: AhkVar::new("Win + Shift + J", "#+j"), - reserve_right: AhkVar::new("Win + Shift + L", "#+l"), - reserve_float: AhkVar::new("Win + Shift + U", "#+u"), - reserve_stack: AhkVar::new("Win + Shift + O", "#+o"), - focus_top: AhkVar::new("Win + Shift + W", "#+w"), - focus_bottom: AhkVar::new("Win + Shift + S", "#+s"), - focus_left: AhkVar::new("Win + Shift + A", "#+a"), - focus_right: AhkVar::new("Win + Shift + D", "#+d"), - focus_latest: AhkVar::new("Win + Shift + E", "#+e"), - increase_width: AhkVar::new("Win + Alt + =", "#!="), - decrease_width: AhkVar::new("Win + Alt + -", "#!-"), - increase_height: AhkVar::new("Win + Shift + =", "#+="), - decrease_height: AhkVar::new("Win + Shift + -", "#+-"), - restore_sizes: AhkVar::new("Win + Alt + 0", "#!0"), - // virtual desktops - switch_workspace_0: AhkVar::new("Alt + 1", "!1"), - switch_workspace_1: AhkVar::new("Alt + 2", "!2"), - switch_workspace_2: AhkVar::new("Alt + 3", "!3"), - switch_workspace_3: AhkVar::new("Alt + 4", "!4"), - switch_workspace_4: AhkVar::new("Alt + 5", "!5"), - switch_workspace_5: AhkVar::new("Alt + 6", "!6"), - switch_workspace_6: AhkVar::new("Alt + 7", "!7"), - switch_workspace_7: AhkVar::new("Alt + 8", "!8"), - switch_workspace_8: AhkVar::new("Alt + 9", "!9"), - switch_workspace_9: AhkVar::new("Alt + 0", "!0"), - move_to_workspace_0: AhkVar::new("Alt + Shift + 1", "!+1"), - move_to_workspace_1: AhkVar::new("Alt + Shift + 2", "!+2"), - move_to_workspace_2: AhkVar::new("Alt + Shift + 3", "!+3"), - move_to_workspace_3: AhkVar::new("Alt + Shift + 4", "!+4"), - move_to_workspace_4: AhkVar::new("Alt + Shift + 5", "!+5"), - move_to_workspace_5: AhkVar::new("Alt + Shift + 6", "!+6"), - move_to_workspace_6: AhkVar::new("Alt + Shift + 7", "!+7"), - move_to_workspace_7: AhkVar::new("Alt + Shift + 8", "!+8"), - move_to_workspace_8: AhkVar::new("Alt + Shift + 9", "!+9"), - move_to_workspace_9: AhkVar::new("Alt + Shift + 0", "!+0"), - send_to_workspace_0: AhkVar::new("Win + Shift + 1", "#+1"), - send_to_workspace_1: AhkVar::new("Win + Shift + 2", "#+2"), - send_to_workspace_2: AhkVar::new("Win + Shift + 3", "#+3"), - send_to_workspace_3: AhkVar::new("Win + Shift + 4", "#+4"), - send_to_workspace_4: AhkVar::new("Win + Shift + 5", "#+5"), - send_to_workspace_5: AhkVar::new("Win + Shift + 6", "#+6"), - send_to_workspace_6: AhkVar::new("Win + Shift + 7", "#+7"), - send_to_workspace_7: AhkVar::new("Win + Shift + 8", "#+8"), - send_to_workspace_8: AhkVar::new("Win + Shift + 9", "#+9"), - send_to_workspace_9: AhkVar::new("Win + Shift + 0", "#+0"), - // miscellaneous - misc_open_settings: AhkVar::new("Win + K", "#k").readonly(), - misc_toggle_lock_tracing: AhkVar::new("Ctrl + Win + Alt + T", "^#!t").readonly(), - misc_toggle_win_event_tracing: AhkVar::new("Ctrl + Win + Alt + L", "^#!l").readonly(), - } - } -} - -// ========================== Seelen Updates ============================== - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -pub enum UpdateChannel { - Release, - Beta, - Nightly, -} - -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -#[serde(rename_all = "camelCase")] -pub struct UpdaterSettings { - pub channel: UpdateChannel, -} - -impl Default for UpdaterSettings { - fn default() -> Self { - Self { - channel: UpdateChannel::Release, - } - } -} - -// ======================== Final Settings Struct =============================== - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -pub enum VirtualDesktopStrategy { - Native, - Seelen, -} - -#[serde_alias(SnakeCase)] -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct Settings { - /// fancy toolbar config - pub fancy_toolbar: FancyToolbarSettings, - /// seelenweg (dock/taskbar) config - pub seelenweg: SeelenWegSettings, - /// window manager config - pub window_manager: WindowManagerSettings, - /// background and virtual desktops config - pub wall: SeelenWallSettings, - /// App launcher settings - pub launcher: SeelenLauncherSettings, - /// list of monitors - pub monitors: Vec, - /// enable or disable ahk - pub ahk_enabled: bool, - /// ahk variables - pub ahk_variables: AhkVarList, - /// list of selected themes - #[serde(alias = "selected_theme")] - pub selected_themes: Vec, - /// list of selected icon packs - pub icon_packs: Vec, - /// enable or disable dev tools tab in settings - pub dev_tools: bool, - /// language to use, if null the system locale is used - pub language: Option, - /// MomentJS date format - pub date_format: String, - /// what virtual desktop implementation will be used, in case Native is not available we use Seelen - pub virtual_desktop_strategy: VirtualDesktopStrategy, - /// Updater Settings - pub updater: UpdaterSettings, -} - -impl Default for Settings { - fn default() -> Self { - Self { - ahk_enabled: true, - selected_themes: vec!["default".to_string()], - icon_packs: vec!["system".to_string()], - monitors: vec![MonitorConfiguration::default()], - fancy_toolbar: FancyToolbarSettings::default(), - seelenweg: SeelenWegSettings::default(), - window_manager: WindowManagerSettings::default(), - wall: SeelenWallSettings::default(), - launcher: SeelenLauncherSettings::default(), - ahk_variables: AhkVarList::default(), - dev_tools: false, - language: Some(Self::get_system_language()), - date_format: "ddd D MMM, hh:mm A".to_owned(), - virtual_desktop_strategy: VirtualDesktopStrategy::Native, - updater: UpdaterSettings::default(), - } - } -} - -impl Settings { - pub fn get_locale() -> Option { - sys_locale::get_locale() - } - - pub fn get_system_language() -> String { - match sys_locale::get_locale() { - Some(l) => l.split('-').next().unwrap_or("en").to_string(), - None => "en".to_string(), - } - } - - pub fn sanitize(&mut self) { - self.launcher.sanitize(); - self.wall.sanitize(); - - if self.language.is_none() { - self.language = Some(Self::get_system_language()); - } - - let default_theme = "default".to_owned(); - if !self.selected_themes.contains(&default_theme) { - self.selected_themes.insert(0, default_theme); - } - - let default_icon_pack = "system".to_owned(); - if !self.icon_packs.contains(&default_icon_pack) { - self.icon_packs.insert(0, default_icon_pack); - } - } -} diff --git a/lib/src/state/settings.ts b/lib/src/state/settings.ts deleted file mode 100644 index 433136df..00000000 --- a/lib/src/state/settings.ts +++ /dev/null @@ -1,204 +0,0 @@ -import { Obtainable, SeelenCommand, SeelenEvent } from '../handlers'; -import { Rect } from '../utils'; -import { MonitorConfiguration } from './settings_by_monitor'; - -export enum VirtualDesktopStrategy { - Native = 'Native', - Seelen = 'Seelen', -} - -export enum SeelenWegMode { - FullWidth = 'Full-Width', - MinContent = 'Min-Content', -} - -export enum HideMode { - Never = 'Never', - Always = 'Always', - OnOverlap = 'On-Overlap', -} - -export enum SeelenWegSide { - Left = 'Left', - Right = 'Right', - Top = 'Top', - Bottom = 'Bottom', -} - -export class SeelenWallWallpaper { - id: string = crypto.randomUUID(); - path: string = ''; -} - -export class SeelenWallSettings { - enabled: boolean = true; - backgrounds: SeelenWallWallpaper[] = []; - /** Interval in seconds */ - interval: number = 60; - randomize: boolean = false; -} - -export enum SeelenLauncherMonitor { - Primary = 'Primary', - MouseOver = 'Mouse-Over', -} - -export class SeelenLauncherRunner { - id: string = crypto.randomUUID(); - label: string = ''; - program: string = ''; - readonly: boolean = false; -} - -export class SeelenLauncherSettings { - enabled: boolean = false; - monitor: SeelenLauncherMonitor = SeelenLauncherMonitor.MouseOver; - runners: SeelenLauncherRunner[] = []; -} - -export enum UpdateChannel { - Release = 'Release', - Beta = 'Beta', - Nightly = 'Nightly', -} - -export class UpdaterSettings { - channel: UpdateChannel = UpdateChannel.Nightly; -} - -export class Settings extends Obtainable( - SeelenCommand.StateGetSettings, - SeelenEvent.StateSettingsChanged, -) { - fancyToolbar: FancyToolbarSettings = new FancyToolbarSettings(); - seelenweg: SeelenWegSettings = new SeelenWegSettings(); - windowManager: WindowManagerSettings = new WindowManagerSettings(); - wall: SeelenWallSettings = new SeelenWallSettings(); - launcher: SeelenLauncherSettings = new SeelenLauncherSettings(); - monitors: MonitorConfiguration[] = [new MonitorConfiguration()]; - ahkEnabled: boolean = true; - ahkVariables: AhkVarList = new AhkVarList(); - selectedThemes: string[] = ['default']; - iconPacks: string[] = ['system']; - devTools: boolean = false; - language: string = ''; - dateFormat: string = 'ddd D MMM, hh:mm A'; - virtualDesktopStrategy: VirtualDesktopStrategy = VirtualDesktopStrategy.Native; - updater: UpdaterSettings = new UpdaterSettings(); -} - -export class FancyToolbarSettings { - enabled: boolean = true; - height: number = 30; - placeholder: string = 'default.yml'; - hideMode: HideMode = HideMode.Never; - delayToShow: number = 100; - delayToHide: number = 800; -} - -export class SeelenWegSettings { - enabled: boolean = true; - mode: SeelenWegMode = SeelenWegMode.MinContent; - hideMode: HideMode = HideMode.OnOverlap; - position: SeelenWegSide = SeelenWegSide.Bottom; - visibleSeparators: boolean = true; - size: number = 40; - zoomSize: number = 70; - margin: number = 8; - padding: number = 8; - spaceBetweenItems: number = 8; - delayToShow: number = 100; - delayToHide: number = 800; -} - -export class Border { - enabled: boolean = true; - width: number = 3.0; - offset: number = 0.0; -} - -export class FloatingWindowSettings { - width: number = 800.0; - height: number = 500.0; -} - -export class WindowManagerSettings { - enabled: boolean = false; - autoStackingByCategory: boolean = true; - border: Border = new Border(); - resizeDelta: number = 10.0; - workspaceGap: number = 10.0; - workspacePadding: number = 10.0; - workspaceMargin: Rect = new Rect(); - floating: FloatingWindowSettings = new FloatingWindowSettings(); - defaultLayout: string = 'default.yml'; -} - -export class AhkVar { - fancy: string; - ahk: string; - readonly: boolean = false; - - constructor(fancy: string = '', ahk: string = '') { - this.fancy = fancy; - this.ahk = ahk; - } -} - -/// TODO: find the way to avoid duplicated code between rust and this class -export class AhkVarList { - // launcher - toggleLauncher = new AhkVar('Win + Space', 'LWin & Space'); - // wm - reserveTop = new AhkVar('Win + Shift + I', '#+i'); - reserveBottom = new AhkVar('Win + Shift + K', '#+k'); - reserveLeft = new AhkVar('Win + Shift + J', '#+j'); - reserveRight = new AhkVar('Win + Shift + L', '#+l'); - reserveFloat = new AhkVar('Win + Shift + U', '#+u'); - reserveStack = new AhkVar('Win + Shift + O', '#+o'); - focusTop = new AhkVar('Win + Shift + W', '#+w'); - focusBottom = new AhkVar('Win + Shift + S', '#+s'); - focusLeft = new AhkVar('Win + Shift + A', '#+a'); - focusRight = new AhkVar('Win + Shift + D', '#+d'); - focusLatest = new AhkVar('Win + Shift + E', '#+e'); - increaseWidth = new AhkVar('Win + Alt + =', '#!='); - decreaseWidth = new AhkVar('Win + Alt + -', '#!-'); - increaseHeight = new AhkVar('Win + Shift + =', '#+='); - decreaseHeight = new AhkVar('Win + Shift + -', '#+-'); - restoreSizes = new AhkVar('Win + Alt + 0', '#!0'); - // virtual desktops - switchWorkspace0 = new AhkVar('Alt + 1', '!1'); - switchWorkspace1 = new AhkVar('Alt + 2', '!2'); - switchWorkspace2 = new AhkVar('Alt + 3', '!3'); - switchWorkspace3 = new AhkVar('Alt + 4', '!4'); - switchWorkspace4 = new AhkVar('Alt + 5', '!5'); - switchWorkspace5 = new AhkVar('Alt + 6', '!6'); - switchWorkspace6 = new AhkVar('Alt + 7', '!7'); - switchWorkspace7 = new AhkVar('Alt + 8', '!8'); - switchWorkspace8 = new AhkVar('Alt + 9', '!9'); - switchWorkspace9 = new AhkVar('Alt + 0', '!0'); - moveToWorkspace0 = new AhkVar('Alt + Shift + 1', '!+1'); - moveToWorkspace1 = new AhkVar('Alt + Shift + 2', '!+2'); - moveToWorkspace2 = new AhkVar('Alt + Shift + 3', '!+3'); - moveToWorkspace3 = new AhkVar('Alt + Shift + 4', '!+4'); - moveToWorkspace4 = new AhkVar('Alt + Shift + 5', '!+5'); - moveToWorkspace5 = new AhkVar('Alt + Shift + 6', '!+6'); - moveToWorkspace6 = new AhkVar('Alt + Shift + 7', '!+7'); - moveToWorkspace7 = new AhkVar('Alt + Shift + 8', '!+8'); - moveToWorkspace8 = new AhkVar('Alt + Shift + 9', '!+9'); - moveToWorkspace9 = new AhkVar('Alt + Shift + 0', '!+0'); - sendToWorkspace0 = new AhkVar('Win + Shift + 1', '#+1'); - sendToWorkspace1 = new AhkVar('Win + Shift + 2', '#+2'); - sendToWorkspace2 = new AhkVar('Win + Shift + 3', '#+3'); - sendToWorkspace3 = new AhkVar('Win + Shift + 4', '#+4'); - sendToWorkspace4 = new AhkVar('Win + Shift + 5', '#+5'); - sendToWorkspace5 = new AhkVar('Win + Shift + 6', '#+6'); - sendToWorkspace6 = new AhkVar('Win + Shift + 7', '#+7'); - sendToWorkspace7 = new AhkVar('Win + Shift + 8', '#+8'); - sendToWorkspace8 = new AhkVar('Win + Shift + 9', '#+9'); - sendToWorkspace9 = new AhkVar('Win + Shift + 0', '#+0'); - // miscellaneous - miscOpenSettings = new AhkVar('Win + K', '#k'); - miscToggleLockTracing = new AhkVar('Ctrl + Win + Alt + T', '^#!t'); - miscToggleWinEventTracing = new AhkVar('Ctrl + Win + Alt + L', '^#!l'); -} diff --git a/lib/src/state/settings_by_app.rs b/lib/src/state/settings_by_app.rs deleted file mode 100644 index 5980031b..00000000 --- a/lib/src/state/settings_by_app.rs +++ /dev/null @@ -1,147 +0,0 @@ -use regex::Regex; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; -use serde_alias::serde_alias; - -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum AppExtraFlag { - /// Start the app in the center of the screen as floating in the wm. - Float, - /// Force manage this app in the wm. - Force, - /// Unmanage this app in the wm. - Unmanage, - /// Pin this app in all the virtual desktops in the wm. - Pinned, - /// Hide this app on the dock/taskbar. - Hidden, -} - -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] -pub enum AppIdentifierType { - #[serde(alias = "exe")] - Exe, - #[serde(alias = "class")] - Class, - #[serde(alias = "title")] - Title, - #[serde(alias = "path")] - Path, -} - -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)] -pub enum MatchingStrategy { - #[serde(alias = "equals", alias = "legacy", alias = "Legacy")] - Equals, - #[serde(alias = "startsWith")] - StartsWith, - #[serde(alias = "endsWith")] - EndsWith, - #[serde(alias = "contains")] - Contains, - #[serde(alias = "regex")] - Regex, -} - -#[serde_alias(SnakeCase)] -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] -#[serde(rename_all = "camelCase")] -pub struct AppIdentifier { - pub id: String, - pub kind: AppIdentifierType, - pub matching_strategy: MatchingStrategy, - #[serde(default)] - pub negation: bool, - #[serde(default)] - pub and: Vec, - #[serde(default)] - pub or: Vec, - #[serde(skip)] - pub regex: Option, -} - -impl AppIdentifier { - pub fn cache_regex(&mut self) { - if matches!(self.matching_strategy, MatchingStrategy::Regex) { - let result = Regex::new(&self.id); - if let Ok(re) = result { - self.regex = Some(re); - } - } - } - - pub fn validate(&self, title: &str, class: &str, exe: &str, path: &str) -> bool { - let mut self_result = match self.matching_strategy { - MatchingStrategy::Equals => match self.kind { - AppIdentifierType::Title => title.eq(&self.id), - AppIdentifierType::Class => class.eq(&self.id), - AppIdentifierType::Exe => exe.eq(&self.id), - AppIdentifierType::Path => path.eq(&self.id), - }, - MatchingStrategy::StartsWith => match self.kind { - AppIdentifierType::Title => title.starts_with(&self.id), - AppIdentifierType::Class => class.starts_with(&self.id), - AppIdentifierType::Exe => exe.starts_with(&self.id), - AppIdentifierType::Path => path.starts_with(&self.id), - }, - MatchingStrategy::EndsWith => match self.kind { - AppIdentifierType::Title => title.ends_with(&self.id), - AppIdentifierType::Class => class.ends_with(&self.id), - AppIdentifierType::Exe => exe.ends_with(&self.id), - AppIdentifierType::Path => path.ends_with(&self.id), - }, - MatchingStrategy::Contains => match self.kind { - AppIdentifierType::Title => title.contains(&self.id), - AppIdentifierType::Class => class.contains(&self.id), - AppIdentifierType::Exe => exe.contains(&self.id), - AppIdentifierType::Path => path.contains(&self.id), - }, - MatchingStrategy::Regex => match self.regex.as_ref() { - Some(re) => match self.kind { - AppIdentifierType::Title => re.is_match(title), - AppIdentifierType::Class => re.is_match(class), - AppIdentifierType::Exe => re.is_match(exe), - AppIdentifierType::Path => re.is_match(path), - }, - None => false, - }, - }; - - if self.negation { - self_result = !self_result; - } - - (self_result && { - self.and - .iter() - .all(|and| and.validate(title, class, exe, path)) - }) || { - self.or - .iter() - .any(|or| or.validate(title, class, exe, path)) - } - } -} - -#[serde_alias(SnakeCase)] -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] -#[serde(rename_all = "camelCase")] -pub struct AppConfig { - /// name of the app - pub name: String, - /// category to group the app under - pub category: Option, - /// monitor index that the app should be bound to - pub bound_monitor: Option, - /// workspace index that the app should be bound to - pub bound_workspace: Option, - /// app identifier - pub identifier: AppIdentifier, - /// extra specific options/settings for the app - #[serde(default)] - pub options: Vec, - /// is this config bundled with seelen ui. - #[serde(default)] - pub is_bundled: bool, -} diff --git a/lib/src/state/settings_by_app.ts b/lib/src/state/settings_by_app.ts deleted file mode 100644 index 111a1226..00000000 --- a/lib/src/state/settings_by_app.ts +++ /dev/null @@ -1,68 +0,0 @@ -export enum AppExtraFlag { - Float = 'float', - Force = 'force', - Unmanage = 'unmanage', - Pinned = 'pinned', - Hidden = 'hidden', -} - -export enum AppIdentifierType { - Exe = 'Exe', - Class = 'Class', - Title = 'Title', - Path = 'Path', -} - -export enum MatchingStrategy { - Equals = 'Equals', - StartsWith = 'StartsWith', - EndsWith = 'EndsWith', - Contains = 'Contains', - Regex = 'Regex', -} - -export interface AppIdentifier { - id: string; - kind: AppIdentifierType; - matchingStrategy: MatchingStrategy; - negation: boolean; - and: AppIdentifier[]; - or: AppIdentifier[]; -} - -export class AppIdentifier { - static placeholder(): AppIdentifier { - return { - id: 'new-app.exe', - kind: AppIdentifierType.Exe, - matchingStrategy: MatchingStrategy.Equals, - negation: false, - and: [], - or: [], - }; - } -} - -export interface AppConfiguration { - name: string; - category: string | null; - boundMonitor: number | null; - boundWorkspace: number | null; - identifier: AppIdentifier; - options: Array; - isBundled: boolean; -} - -export class AppConfiguration { - static placeholder(): AppConfiguration { - return { - name: 'New App', - category: null, - boundWorkspace: null, - boundMonitor: null, - identifier: AppIdentifier.placeholder(), - isBundled: false, - options: [], - }; - } -} diff --git a/lib/src/state/settings_by_monitor.rs b/lib/src/state/settings_by_monitor.rs deleted file mode 100644 index 4f100667..00000000 --- a/lib/src/state/settings_by_monitor.rs +++ /dev/null @@ -1,102 +0,0 @@ -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -use crate::rect::Rect; - -use super::SeelenWallWallpaper; - -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct FancyToolbarSettingsByMonitor { - pub enabled: bool, -} - -impl Default for FancyToolbarSettingsByMonitor { - fn default() -> Self { - Self { enabled: true } - } -} - -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct SeelenWegSettingsByMonitor { - pub enabled: bool, -} - -impl Default for SeelenWegSettingsByMonitor { - fn default() -> Self { - Self { enabled: true } - } -} - -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct WindowManagerSettingsByMonitor { - pub enabled: bool, - pub padding: Option, - pub margin: Option, - pub gap: Option, - pub layout: Option, -} - -impl Default for WindowManagerSettingsByMonitor { - fn default() -> Self { - Self { - enabled: true, - padding: None, - margin: None, - gap: None, - layout: None, - } - } -} - -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct SeelenWallSettingsByMonitor { - pub enabled: bool, - pub backgrounds: Option>, -} - -impl Default for SeelenWallSettingsByMonitor { - fn default() -> Self { - Self { - enabled: true, - backgrounds: None, - } - } -} - -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] -pub enum WorkspaceIdentifierType { - #[serde(alias = "name")] - Name, - #[serde(alias = "index")] - Index, -} - -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] -#[serde(rename_all = "camelCase")] -pub struct WorkspaceIdentifier { - pub id: String, - pub kind: WorkspaceIdentifierType, -} - -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] -#[serde(rename_all = "camelCase")] -pub struct WorkspaceConfiguration { - pub identifier: WorkspaceIdentifier, - pub layout: Option, - pub backgrounds: Option>, -} - -#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct MonitorConfiguration { - pub tb: FancyToolbarSettingsByMonitor, - pub weg: SeelenWegSettingsByMonitor, - pub wm: WindowManagerSettingsByMonitor, - pub wall: SeelenWallSettingsByMonitor, - /// list of settings by workspace on this monitor - pub workspaces_v2: Vec, -} diff --git a/lib/src/state/settings_by_monitor.ts b/lib/src/state/settings_by_monitor.ts deleted file mode 100644 index 3df6601c..00000000 --- a/lib/src/state/settings_by_monitor.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { Rect } from '../utils'; -import { SeelenWallWallpaper } from './settings'; - -export class FancyToolbarSettingsByMonitor { - enabled: boolean = true; -} - -export class SeelenWegSettingsByMonitor { - enabled: boolean = true; -} - -export class WindowManagerSettingsByMonitor { - enabled: boolean = true; - padding: number | null = null; - margin: Rect | null = null; - gap: number | null = null; - layout: string | null = null; -} - -export class SeelenWallSettingsByMonitor { - enabled: boolean = true; - backgrounds: SeelenWallWallpaper[] | null = null; -} - -export enum WorkspaceIdentifierType { - Name = 'name', - Index = 'index', -} - -export class WorkspaceIdentifier { - id: string; - kind: WorkspaceIdentifierType; - - constructor(id: string, kind: WorkspaceIdentifierType) { - this.id = id; - this.kind = kind; - } -} - -export class WorkspaceConfiguration { - identifier: WorkspaceIdentifier; - layout: string | null = null; - backgrounds: SeelenWallWallpaper[] | null = null; - - constructor(identifier: WorkspaceIdentifier) { - this.identifier = identifier; - } -} - -export class MonitorConfiguration { - tb: FancyToolbarSettingsByMonitor = new FancyToolbarSettingsByMonitor(); - wall: SeelenWallSettingsByMonitor = new SeelenWallSettingsByMonitor(); - weg: SeelenWegSettingsByMonitor = new SeelenWegSettingsByMonitor(); - wm: WindowManagerSettingsByMonitor = new WindowManagerSettingsByMonitor(); - /** list of settings by workspace on this monitor */ - workspacesV2: WorkspaceConfiguration[] = []; -} diff --git a/lib/src/state/theme.rs b/lib/src/state/theme.rs deleted file mode 100644 index 1dfc270c..00000000 --- a/lib/src/state/theme.rs +++ /dev/null @@ -1,41 +0,0 @@ -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct ThemeCss { - /// Css Styles for the dock/taskbar - pub weg: String, - /// Css Styles for the toolbar - pub toolbar: String, - /// Css Styles for the window manager - pub wm: String, - /// Css Styles for the app launcher - pub launcher: String, - /// Css Styles for the wall - pub wall: String, -} - -#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct ThemeInfo { - /// Display name of the theme - pub display_name: String, - /// Author of the theme - pub author: String, - /// Description of the theme - pub description: String, - /// Filename of the theme, is overridden by the program on load. - pub filename: String, - /// Tags to be used in search - pub tags: Vec, -} - -#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct Theme { - /// Metadata about the theme - pub info: ThemeInfo, - /// Css Styles of the theme - pub styles: ThemeCss, -} diff --git a/lib/src/state/theme.ts b/lib/src/state/theme.ts deleted file mode 100644 index dc4ed8d7..00000000 --- a/lib/src/state/theme.ts +++ /dev/null @@ -1,32 +0,0 @@ -export interface ThemeCssByApp { - /** Css Styles for the dock/taskbar */ - weg: string; - /** Css Styles for the window manager */ - toolbar: string; - /** Css Styles for the window manager */ - wm: string; - /** Css Styles for the app launcher */ - launcher: string; - /** Css Styles for the wall */ - wall: string; -} - -export interface ThemeInfo { - /** Display name of the theme */ - displayName: string; - /** Author of the theme */ - author: string; - /** Description of the theme */ - description: string; - /** Filename of the theme, is overridden by the program on load */ - filename: string; - /** Tags to be used in search */ - tags: string[]; -} - -export interface Theme { - /** Metadata about the theme */ - info: ThemeInfo; - /** Css Styles of the theme */ - styles: ThemeCssByApp & Record; -} diff --git a/lib/src/state/weg_items.rs b/lib/src/state/weg_items.rs deleted file mode 100644 index ddc62fe6..00000000 --- a/lib/src/state/weg_items.rs +++ /dev/null @@ -1,126 +0,0 @@ -use std::{collections::HashSet, path::PathBuf}; - -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -pub struct PinnedWegItemData { - /// Direct path to file, forder or program. - /// - /// PWA: In case of pwa programs this will be the creator of the process, will point to the - /// browser executable so this is not unique across PWA apps, and can't be used to identify apps. - /// Also this can't be used to launch the app. - /// - /// UWP: In case of UWP apps this will be the path to the app executable, but this can't be used to - /// invoke the app instead should be used the `shell:AppsFolder` + app user model id. - #[serde(alias = "exe")] - pub path: PathBuf, - /// Program, file or folder to execute/open when clicking the item. - /// - /// Exclusion: On `.lnk` files this is the target of the link and when open action is triggered, - /// this field and arguments are ignored, using the link file as command. - /// - /// Important: This should be unique across all weg items because this is used as identifier, dupes will be removed on load. - /// - /// Note: this field is mandatory and will be filled with `path` if it is not set - #[serde(default, alias = "execution_path")] - pub execution_command: String, - /// true if self.path is a folder - #[serde(default)] - pub is_dir: bool, -} - -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -#[serde(tag = "type")] -pub enum WegItem { - #[serde(alias = "PinnedApp")] - Pinned(PinnedWegItemData), - Temporal(PinnedWegItemData), - Separator { - id: String, - }, - Media, - StartMenu, -} - -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -#[serde(default)] -pub struct WegItems { - pub left: Vec, - pub center: Vec, - pub right: Vec, -} - -impl Default for WegItems { - fn default() -> Self { - Self { - left: vec![WegItem::StartMenu], - center: vec![WegItem::Pinned(PinnedWegItemData { - path: "C:\\Windows\\explorer.exe".into(), - execution_command: "C:\\Windows\\explorer.exe".into(), - is_dir: false, - })], - right: vec![WegItem::Media], - } - } -} - -impl WegItems { - fn sanitize_items(dict: &mut HashSet, items: Vec) -> Vec { - let mut result = Vec::new(); - for mut item in items { - match &mut item { - WegItem::Pinned(data) => { - if !data.path.exists() { - continue; - } - if data.execution_command.is_empty() { - data.execution_command = data.path.to_string_lossy().to_string(); - } - if !dict.contains(&data.execution_command) { - dict.insert(data.execution_command.clone()); - result.push(item); - } - } - WegItem::Temporal(data) => { - if !data.path.exists() { - continue; - } - if data.execution_command.is_empty() { - data.execution_command = data.path.to_string_lossy().to_string(); - } - if !dict.contains(&data.execution_command) { - dict.insert(data.execution_command.clone()); - result.push(item); - } - } - WegItem::Separator { id } => { - if !dict.contains(id) { - dict.insert(id.clone()); - result.push(item); - } - } - WegItem::StartMenu => { - if !dict.contains("StartMenu") { - dict.insert("StartMenu".to_owned()); - result.push(item); - } - } - WegItem::Media => { - if !dict.contains("Media") { - dict.insert("Media".to_owned()); - result.push(item); - } - } - } - } - result - } - - pub fn sanitize(&mut self) { - let mut dict = HashSet::new(); - self.left = Self::sanitize_items(&mut dict, std::mem::take(&mut self.left)); - self.center = Self::sanitize_items(&mut dict, std::mem::take(&mut self.center)); - self.right = Self::sanitize_items(&mut dict, std::mem::take(&mut self.right)); - } -} diff --git a/lib/src/state/weg_items.ts b/lib/src/state/weg_items.ts deleted file mode 100644 index adf6c938..00000000 --- a/lib/src/state/weg_items.ts +++ /dev/null @@ -1,47 +0,0 @@ -export enum SwItemType { - Pinned = 'Pinned', - TemporalApp = 'TemporalPin', - Separator = 'Separator', - Media = 'Media', - Start = 'StartMenu', -} - -export interface PinnedWegItem { - type: SwItemType.Pinned; - path: string; - execution_command: string; - is_dir: boolean; -} - -export interface TemporalPinnedWegItem { - type: SwItemType.TemporalApp; - path: string; - execution_command: string; - is_dir: boolean; -} - -export interface SeparatorWegItem { - type: SwItemType.Separator; - id: string; -} - -export interface MediaWegItem { - type: SwItemType.Media; -} - -export interface StartWegItem { - type: SwItemType.Start; -} - -export type WegItem = - | PinnedWegItem - | TemporalPinnedWegItem - | SeparatorWegItem - | MediaWegItem - | StartWegItem; - -export interface WegItems { - left: WegItem[]; - center: WegItem[]; - right: WegItem[]; -} diff --git a/lib/src/state/widget.rs b/lib/src/state/widget.rs deleted file mode 100644 index e2c7b75a..00000000 --- a/lib/src/state/widget.rs +++ /dev/null @@ -1,6 +0,0 @@ -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Widget { - pub id: String, -} diff --git a/lib/src/state/widget.ts b/lib/src/state/widget.ts deleted file mode 100644 index 8913bedb..00000000 --- a/lib/src/state/widget.ts +++ /dev/null @@ -1,4 +0,0 @@ - -export class Widget { - id: string = ''; -} \ No newline at end of file diff --git a/lib/src/state/wm_layout.rs b/lib/src/state/wm_layout.rs deleted file mode 100644 index e4665563..00000000 --- a/lib/src/state/wm_layout.rs +++ /dev/null @@ -1,201 +0,0 @@ -use std::cell::Cell; - -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -macro_rules! common_item { - ( - $( - struct $name:ident { - $($rest:tt)* - } - )* - ) => { - $( - #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] - #[serde(rename_all = "camelCase")] - pub struct $name { - #[serde(default = "WmNode::default_subtype")] - pub subtype: NodeSubtype, - /// Order in how the tree will be traversed (1 = first, 2 = second, etc.) - #[serde(default = "WmNode::default_priority")] - pub priority: u32, - /// How much of the remaining space this node will take - #[serde(default = "WmNode::default_grow_factor")] - pub grow_factor: Cell, - /// Math Condition for the node to be shown, e.g: n >= 3 - pub condition: Option, - $($rest)* - } - )* - }; -} - -common_item! { - struct WmVerticalNode { - pub children: Vec, - } - struct WmHorizontalNode { - pub children: Vec, - } - struct WmLeafNode { - /// window handle (HWND) in the node - pub handle: Option, - } - struct WmStackNode { - /// active window handle (HWND) in the node - #[serde(skip_deserializing)] - pub active: Option, - /// window handles (HWND) in the node - #[serde(skip_deserializing)] - pub handles: Vec, - } - struct WmFallbackNode { - /// active window handle (HWND) in the node - #[serde(skip_deserializing)] - pub active: Option, - /// window handles (HWND) in the node - #[serde(skip_deserializing)] - pub handles: Vec, - } -} - -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -#[serde(tag = "type")] -pub enum WmNode { - Vertical(WmVerticalNode), - Horizontal(WmHorizontalNode), - Leaf(WmLeafNode), - Stack(WmStackNode), - Fallback(WmFallbackNode), -} - -fn format_children(children: &[WmNode]) -> String { - let mut result = Vec::new(); - for child in children { - result.push(child.to_string()); - } - result.join(", ") -} - -impl std::fmt::Display for WmNode { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - WmNode::Vertical(node) => write!(f, "Vertical [{}]", format_children(&node.children)), - WmNode::Horizontal(node) => { - write!(f, "Horizontal [{}]", format_children(&node.children)) - } - WmNode::Leaf(node) => write!(f, "Leaf({:?})", node.handle), - WmNode::Stack(node) => write!(f, "Stack({:?})", node.handles), - WmNode::Fallback(node) => write!(f, "Fallback({:?})", node.handles), - } - } -} - -impl WmNode { - fn default_subtype() -> NodeSubtype { - NodeSubtype::Permanent - } - - fn default_priority() -> u32 { - 1 - } - - fn default_grow_factor() -> Cell { - Cell::new(1.0) - } - - pub fn priority(&self) -> u32 { - match self { - WmNode::Leaf(n) => n.priority, - WmNode::Stack(n) => n.priority, - WmNode::Fallback(n) => n.priority, - WmNode::Vertical(n) => n.priority, - WmNode::Horizontal(n) => n.priority, - } - } - - pub fn grow_factor(&self) -> &Cell { - match self { - WmNode::Leaf(n) => &n.grow_factor, - WmNode::Stack(n) => &n.grow_factor, - WmNode::Fallback(n) => &n.grow_factor, - WmNode::Vertical(n) => &n.grow_factor, - WmNode::Horizontal(n) => &n.grow_factor, - } - } - - pub fn condition(&self) -> Option<&String> { - match self { - WmNode::Leaf(n) => n.condition.as_ref(), - WmNode::Stack(n) => n.condition.as_ref(), - WmNode::Fallback(n) => n.condition.as_ref(), - WmNode::Vertical(n) => n.condition.as_ref(), - WmNode::Horizontal(n) => n.condition.as_ref(), - } - } - - pub fn len(&self) -> usize { - match self { - WmNode::Leaf(n) => n.handle.is_some() as usize, - WmNode::Stack(n) => n.handles.len(), - WmNode::Fallback(n) => n.handles.len(), - WmNode::Vertical(n) => n.children.iter().map(Self::len).sum(), - WmNode::Horizontal(n) => n.children.iter().map(Self::len).sum(), - } - } - - pub fn is_empty(&self) -> bool { - self.len() == 0 - } -} - -#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct WManagerLayoutInfo { - /// Display name of the layout - pub display_name: String, - /// Author of the layout - pub author: String, - /// Description of the layout - pub description: String, - /// Filename of the layout, is overridden by the program on load. - pub filename: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -pub enum NodeSubtype { - Temporal, - Permanent, -} - -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -pub enum NoFallbackBehavior { - Float, - Unmanaged, -} - -#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] -#[serde(default, rename_all = "camelCase")] -pub struct WindowManagerLayout { - pub info: WManagerLayoutInfo, - pub structure: WmNode, - pub no_fallback_behavior: NoFallbackBehavior, -} - -impl Default for WindowManagerLayout { - fn default() -> Self { - Self { - info: Default::default(), - structure: WmNode::Fallback(WmFallbackNode { - subtype: WmNode::default_subtype(), - priority: WmNode::default_priority(), - grow_factor: WmNode::default_grow_factor(), - condition: None, - active: None, - handles: vec![], - }), - no_fallback_behavior: NoFallbackBehavior::Float, - } - } -} diff --git a/lib/src/state/wm_layout.ts b/lib/src/state/wm_layout.ts deleted file mode 100644 index 5bc09b18..00000000 --- a/lib/src/state/wm_layout.ts +++ /dev/null @@ -1,66 +0,0 @@ -export enum NodeType { - Vertical = 'Vertical', - Horizontal = 'Horizontal', - Leaf = 'Leaf', - Stack = 'Stack', - Fallback = 'Fallback', -} - -export enum NodeSubtype { - Temporal = 'Temporal', - Permanent = 'Permanent', -} - -export enum NoFallbackBehavior { - Float = 'Float', - Unmanaged = 'Unmanaged', -} - -export interface WManagerLayoutInfo { - displayName: string; - author: string; - description: string; - filename: string; -} - -export interface WmNodeBase { - subtype: NodeSubtype; - priority: number; - growFactor: number; - condition: string | null; -} - -export interface WmVerticalNode extends WmNodeBase { - type: NodeType.Vertical; - children: WmNode[]; -} - -export interface WmHorizontalNode extends WmNodeBase { - type: NodeType.Horizontal; - children: WmNode[]; -} - -export interface WmLeafNode extends WmNodeBase { - type: NodeType.Leaf; - handle: number | null; -} - -export interface WmStackNode extends WmNodeBase { - type: NodeType.Stack; - active: number | null; - handles: number[]; -} - -export interface WmFallbackNode extends WmNodeBase { - type: NodeType.Fallback; - active: number | null; - handles: number[]; -} - -export type WmNode = WmVerticalNode | WmHorizontalNode | WmLeafNode | WmStackNode | WmFallbackNode; - -export interface WindowManagerLayout { - info: WManagerLayoutInfo; - structure: WmNode; - noFallbackBehavior: NoFallbackBehavior; -} diff --git a/lib/src/system_state/index.ts b/lib/src/system_state/index.ts deleted file mode 100644 index d00ece2e..00000000 --- a/lib/src/system_state/index.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { Obtainable, SeelenCommand, SeelenEvent } from '../handlers'; - -export interface UIColors { - background: string; - foreground: string; - accent_darkest: string; - accent_darker: string; - accent_dark: string; - accent: string; - accent_light: string; - accent_lighter: string; - accent_lightest: string; - complement: string | null; -} - -export class UIColors extends Obtainable( - SeelenCommand.GetSystemColors, - SeelenEvent.ColorsChanged, -) { - static default(): UIColors { - return { - background: '#ffffff', - foreground: '#000000', - accent_darkest: '#990000', - accent_darker: '#aa0000', - accent_dark: '#bb0000', - accent: '#cc0000', - accent_light: '#dd0000', - accent_lighter: '#ee0000', - accent_lightest: '#ff0000', - complement: null, - }; - } - - static setAssCssVariables(colors: UIColors) { - for (const [key, value] of Object.entries(colors)) { - if (typeof value !== 'string') { - continue; - } - let hex = value.replace('#', '').slice(0, 6); - var color = parseInt(hex, 16); - var r = (color >> 16) & 255; - var g = (color >> 8) & 255; - var b = color & 255; - // replace rust snake case with kebab case - let name = key.replace('_', '-'); - document.documentElement.style.setProperty(`--config-${name}-color`, value.slice(0, 7)); - document.documentElement.style.setProperty(`--config-${name}-color-rgb`, `${r}, ${g}, ${b}`); - } - } -} diff --git a/lib/src/system_state/mod.rs b/lib/src/system_state/mod.rs deleted file mode 100644 index 27b92e5c..00000000 --- a/lib/src/system_state/mod.rs +++ /dev/null @@ -1,16 +0,0 @@ -use serde::Serialize; - -/// https://learn.microsoft.com/is-is/uwp/api/windows.ui.viewmanagement.uicolortype?view=winrt-19041 -#[derive(Debug, Default, Serialize)] -pub struct UIColors { - pub background: String, - pub foreground: String, - pub accent_darkest: String, - pub accent_darker: String, - pub accent_dark: String, - pub accent: String, - pub accent_light: String, - pub accent_lighter: String, - pub accent_lightest: String, - pub complement: Option, -} diff --git a/lib/src/utils/hooks.ts b/lib/src/utils/hooks.ts deleted file mode 100644 index 63294f87..00000000 --- a/lib/src/utils/hooks.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { getCurrentWindow } from '@tauri-apps/api/window'; -import { useEffect, useRef } from 'react'; - -export function useWindowFocusChange(cb: (focused: boolean) => void) { - useEffect(() => { - const promise = getCurrentWindow().onFocusChanged((event) => { - cb(event.payload); - }); - return () => { - promise.then((unlisten) => unlisten()); - }; - }, []); -} - -export function useInterval(cb: () => void, ms: number, deps: any[] = []) { - const ref = useRef(null); - const clearLastInterval = () => { - if (ref.current) { - clearInterval(ref.current); - } - }; - useEffect(() => { - clearLastInterval(); - ref.current = setInterval(cb, ms); - return clearLastInterval; - }, [ms, ...deps]); -} - -export function useTimeout(cb: () => void, ms: number, deps: any[] = []) { - const ref = useRef(null); - const clearLastTimeout = () => { - if (ref.current) { - clearTimeout(ref.current); - } - }; - useEffect(() => { - clearLastTimeout(); - ref.current = setTimeout(cb, ms); - return clearLastTimeout; - }, [ms, ...deps]); -} diff --git a/lib/src/utils/index.ts b/lib/src/utils/index.ts deleted file mode 100644 index 1eaf6ed9..00000000 --- a/lib/src/utils/index.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { getCurrentWindow } from '@tauri-apps/api/window'; - -export * from './hooks'; -export * from './layered_hitbox'; - -export function getRootElement() { - const element = document.getElementById('root'); - if (!element) { - throw new Error('Root element not found'); - } - return element; -} - -export class Rect { - left = 0; - top = 0; - right = 0; - bottom = 0; -} - -export function disableWebviewShortcutsAndContextMenu() { - window.addEventListener('keydown', function (event) { - // prevent refresh - if (event.key === 'F5') { - event.preventDefault(); - } - - // prevent close - if (event.altKey && event.key === 'F4') { - event.preventDefault(); - } - - // others - if (event.ctrlKey) { - switch (event.key) { - case 'r': // reload - case 'f': // search - case 'g': // find - case 'p': // print - case 'j': // downloads - case 'u': // source - event.preventDefault(); - break; - } - } - }); - window.addEventListener('contextmenu', (e) => e.preventDefault(), { capture: true }); - window.addEventListener('drop', (e) => e.preventDefault()); - window.addEventListener('dragover', (e) => e.preventDefault()); -} - -// label schema: user/resource__query__monitor:display5 -export function getCurrentWidget() { - const { label } = getCurrentWindow(); - const parsedLabel = label.replace('__query__', '?').replace(':', '='); - const query = new URLSearchParams(parsedLabel); - return { - id: `@${parsedLabel.split('?')[0]}`, - label, - attachedMonitor: query.get('monitor'), - }; -} \ No newline at end of file diff --git a/lib/src/utils/layered_hitbox.ts b/lib/src/utils/layered_hitbox.ts deleted file mode 100644 index 4bcda515..00000000 --- a/lib/src/utils/layered_hitbox.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow'; - -import { SeelenEvent } from '../handlers'; - -export async function declareDocumentAsLayeredHitbox() { - const webview = getCurrentWebviewWindow(); - const { x, y } = await webview.outerPosition(); - const { width, height } = await webview.outerSize(); - - let webviewRect = { x, y, width, height }; - let ignoring_cursor_events = true; - let is_layered_enabled = true; - await webview.setIgnoreCursorEvents(true); - - webview.onMoved((e) => { - webviewRect.x = e.payload.x; - webviewRect.y = e.payload.y; - }); - - webview.onResized((e) => { - webviewRect.width = e.payload.width; - webviewRect.height = e.payload.height; - }); - - webview.listen(SeelenEvent.HandleLayeredHitboxes, (event) => { - is_layered_enabled = event.payload; - }); - - webview.listen<[x: number, y: number]>(SeelenEvent.GlobalMouseMove, (event) => { - if (!is_layered_enabled) { - return; - } - - const [mouseX, mouseY] = event.payload; - let { x: windowX, y: windowY, width: windowWidth, height: windowHeight } = webviewRect; - - // check if the mouse is inside the window - const isHoverWindow = - mouseX >= windowX && - mouseX <= windowX + windowWidth && - mouseY >= windowY && - mouseY <= windowY + windowHeight; - - if (!isHoverWindow) { - return; - } - - const adjustedX = (mouseX - windowX) / window.devicePixelRatio; - const adjustedY = (mouseY - windowY) / window.devicePixelRatio; - - let isOverBody = document.elementFromPoint(adjustedX, adjustedY) == document.body; - if (isOverBody && !ignoring_cursor_events) { - ignoring_cursor_events = true; - webview.setIgnoreCursorEvents(true); - } - - if (!isOverBody && ignoring_cursor_events) { - ignoring_cursor_events = false; - webview.setIgnoreCursorEvents(false); - } - }); - - window.addEventListener('touchstart', (e) => { - let isOverBody = e.target == document.body; - if (isOverBody && !ignoring_cursor_events) { - ignoring_cursor_events = true; - webview.setIgnoreCursorEvents(true); - } - }); -}