mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* Introduce injection token as competition for injectable setup to have better control of timing of different setups Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Switch to using competition to setup app paths Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Switch to using competition for setupping IPC channel listeners Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Stop running setups in unit tests without need Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Switch to running injection token based setups over legacy DI setups in unit tests Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Consolidate naming for running setups Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Switch to running injection token based setups over legacy DI setups in application roots Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Adapt to typing changes in injectable Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Update injectable Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Introduce concept of runnable as a way to delegate runs to Open Closed Principle compliant runnables Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Deprecate vars in favor of injectables Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Consolidate loading of extensions to injectable instead of setup-code Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Flag injectable causing side effects Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Adapt injectable to auto register using a plugin instead of internal feature that no longer exists Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Simplify late registrations Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Introduce tokens for runnables of specific application events for Open Closed Principle Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Consolidate setup events to more granular timeslots Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Reimplement setup for catalog syncing using runnables instead of non-OCP in index.ts Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Reimplement setup for application menu using runnables instead of non-OCP in index.ts Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Reimplement setup for electron application name using runnables instead of non-OCP in index.ts Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Reimplement setup for immer using runnables instead of non-OCP in index.ts Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Reimplement setup for MobX strictness using runnables instead of non-OCP in index.ts Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Reimplement setup for application proxy using runnables instead of non-OCP in index.ts Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Reimplement setup for system certifications using runnables instead of non-OCP in index.ts Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Reimplement setup for system shutdown using runnables instead of non-OCP in index.ts Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Reimplement setup for main window visibility using runnables instead of non-OCP in index.ts Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Reimplement setup for application quit using runnables instead of non-OCP in index.ts Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Reimplement setup for after application is ready using runnables instead of non-OCP in index.ts Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Reimplement setup for application tray using runnables instead of non-OCP in index.ts Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Reimplement setup for deep linking using runnables instead of non-OCP in index.ts Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Reimplement setup for root frame using runnables instead of non-OCP in index.ts Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove multiple usages of shared global state Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove recently reimplemented stuff from index.ts Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Extract implementation for intent over technical phenomena (here electron events) Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Consolidate naming of event timing window Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Move directories for timing windows among peers Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Consolidate event naming Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Introduce function to remove duplication from things that are startable and stoppable Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Consolidate implementation of something startable and stoppable Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Consolidate naming Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Consolidate more startables and stoppables Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Introduce abstractions for electron application events Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Introduce more abstractions for electron Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Abstract even more Electron specifics to make them overridable in unit tests Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Override dependency for causing side effects Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Make running of many delegatees able to be hierarchical Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Bump async-fn Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Make startable-stoppable also restartable Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Extract "isIntegrationTesting" as dependency for having a side-effect Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Make temporal dependency apparent Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Consolidate all setupping related to single feature to same runnable Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Abstract command line arguments to make them overridable in tests Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Deprecate some globals Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Introduce injectable for __static directory to eliminate side effect on import Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Extract responsibilities from electron Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Extract async initialization from sync-injectable Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Accumulate more global overrides Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Make lifecycle of injectable store work as expected Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Extract responsibilities to delegatees Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Rename delegate for accuracy Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Rename another delegate for accuracy Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Rename yet another delegate for accuracy Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Add new global overrides Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Consolidate variable naming Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Rename injectable for accuracy Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Make difference between soft and hard quit of application apparent Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Make quit triggered by auto update manifest as hard quit instead of just soft quit Soft quit is the stand-by quit where only the renderer quits. Hard quit is the full quit of also main. Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Introduce abstraction for publishing and subscribing between processes Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Revert "Introduce abstraction for publishing and subscribing between processes" This reverts commit 46f2d5a5f28bddcf5ffe124b1c590b19e7b9a15f. Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Adapt code and unit tests to recent changes in application setup and event handling Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Group overrides by category Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Abstract event of application activation from electron Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Abstract event of device shutdown from electron Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Consolidate runnables related to Electron Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Make startableStoppables have ID for better error logging Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Make navigating to Helm Charts not blow up Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Add general override for behavioural tests Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com> * Update snapshot Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Adapt vars after merge Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix code style Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix error about multiple states for React Router being present at once Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Kludge around test setup which is difficult because of circular dependencies Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix setupping of sentry after rebase Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Ensure that LensProxy is setupped before starting the main window Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove redundant import Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Consolidate to use injectable instead of var for static file directory Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Deprecate another var with injectable Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Tweak timing of runnables Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Extract tray icon path as injectable Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Make splash screen not blow up by providing compile-time environment variables Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Introduce a way to run many synchronous runnables Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Make runnables for before application is ready synchronous as this is technical limitation of Electron See: https://github.com/electron/electron/issues/21370 Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Kill dead code Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix application quit by calling Electron's event.preventDefault in a very specific way and preventing async Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix missing injectable postfix in file name Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Tweak timeslot of a runnable Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Make it possible to not stop something that was never started Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Make quit of hidden Lens not blow up Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Extract responsibilities of WindowManager as injectables Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Consolidate code for application window Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Simplify directory structures for runnables Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Flag injectable causing side-effect Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Extract helpers for testing promises to test-utils Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Make script for running unit tests support targeting Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Make startable stoppable support async starting Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Introduce reactive way to get theme from operating system Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Update yarn.lock after rebase Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix code style Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove code-style changes that are not welcome Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Switch to using dependency over using explicit side-effect Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Simplify naming Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Kill dead code Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Add empty mocks comply to lint Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove global state Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Extract responsibility of setting dependencies to own injectable Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Flag injectable causing side effects Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Extract responsibility to injectable Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Tweak typing Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Tweak naming of runnables Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Revert code-style changes Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Tweak types Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Extract injectable with side-effect for exact overriding Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Tweak name of timeslot to make it more apparent that new content for application load can be added Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Tweak name of the splash window for loading to avoid confusion with similarly named phenomenon Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Tweak comment Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Rename injectable for brevity Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Consolidate LensProxy related stuff to directory Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Rename injectables for accuracy Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove usage of extension for injectable for being YAGNI Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Prevent restarting a startableStoppable when already being started Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Rename callback in ApplicationBuilder for accuracy Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix conflicts after rebase Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix merge conflicts Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Revert switch to react-router-dom by installing history as dependency Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Make test more strict Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Make runnable give friendly error about incorrect hierarchy for easier debugging Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix code-style Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix code style Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Switch to using dependency instead of legacy-di Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix timing of injects Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> Co-authored-by: Iku-turso <mikko.aspiala@gmail.com>
357 lines
8.8 KiB
TypeScript
357 lines
8.8 KiB
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
|
|
import { action, comparer, observable, makeObservable, computed } from "mobx";
|
|
import { BaseStore } from "../base-store";
|
|
import migrations from "../../migrations/hotbar-store";
|
|
import { toJS } from "../utils";
|
|
import type { CatalogEntity } from "../catalog";
|
|
import { broadcastMessage } from "../ipc";
|
|
import type { Hotbar, CreateHotbarData, CreateHotbarOptions } from "./types";
|
|
import { defaultHotbarCells, getEmptyHotbar } from "./types";
|
|
import { hotbarTooManyItemsChannel } from "../ipc/hotbar";
|
|
import type { GeneralEntity } from "../catalog-entities";
|
|
import type { Logger } from "../logger";
|
|
import assert from "assert";
|
|
|
|
export interface HotbarStoreModel {
|
|
hotbars: Hotbar[];
|
|
activeHotbarId: string;
|
|
}
|
|
|
|
interface Dependencies {
|
|
readonly catalogCatalogEntity: GeneralEntity;
|
|
readonly logger: Logger;
|
|
}
|
|
|
|
export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
|
readonly displayName = "HotbarStore";
|
|
@observable hotbars: Hotbar[] = [];
|
|
@observable private _activeHotbarId!: string;
|
|
|
|
constructor(private readonly dependencies: Dependencies) {
|
|
super({
|
|
configName: "lens-hotbar-store",
|
|
accessPropertiesByDotNotation: false, // To make dots safe in cluster context names
|
|
syncOptions: {
|
|
equals: comparer.structural,
|
|
},
|
|
migrations,
|
|
});
|
|
|
|
makeObservable(this);
|
|
}
|
|
|
|
@computed get activeHotbarId() {
|
|
return this._activeHotbarId;
|
|
}
|
|
|
|
/**
|
|
* If `hotbar` points to a known hotbar, make it active. Otherwise, ignore
|
|
* @param hotbar The hotbar instance, or the index, or its ID
|
|
*/
|
|
setActiveHotbar(hotbar: Hotbar | number | string) {
|
|
if (typeof hotbar === "number") {
|
|
if (hotbar >= 0 && hotbar < this.hotbars.length) {
|
|
this._activeHotbarId = this.hotbars[hotbar].id;
|
|
}
|
|
} else if (typeof hotbar === "string") {
|
|
if (this.findById(hotbar)) {
|
|
this._activeHotbarId = hotbar;
|
|
}
|
|
} else {
|
|
if (this.hotbars.indexOf(hotbar) >= 0) {
|
|
this._activeHotbarId = hotbar.id;
|
|
}
|
|
}
|
|
}
|
|
|
|
private hotbarIndexById(id: string) {
|
|
return this.hotbars.findIndex((hotbar) => hotbar.id === id);
|
|
}
|
|
|
|
private hotbarIndex(hotbar: Hotbar) {
|
|
return this.hotbars.indexOf(hotbar);
|
|
}
|
|
|
|
@computed get activeHotbarIndex() {
|
|
return this.hotbarIndexById(this.activeHotbarId);
|
|
}
|
|
|
|
@action
|
|
protected fromStore(data: Partial<HotbarStoreModel> = {}) {
|
|
if (!data.hotbars || !data.hotbars.length) {
|
|
const hotbar = getEmptyHotbar("Default");
|
|
const {
|
|
metadata: { uid, name, source },
|
|
} = this.dependencies.catalogCatalogEntity;
|
|
const initialItem = { entity: { uid, name, source }};
|
|
|
|
hotbar.items[0] = initialItem;
|
|
|
|
this.hotbars = [hotbar];
|
|
} else {
|
|
this.hotbars = data.hotbars;
|
|
}
|
|
|
|
this.hotbars.forEach(ensureExactHotbarItemLength);
|
|
|
|
if (data.activeHotbarId) {
|
|
this.setActiveHotbar(data.activeHotbarId);
|
|
}
|
|
|
|
if (!this.activeHotbarId) {
|
|
this.setActiveHotbar(0);
|
|
}
|
|
}
|
|
|
|
toJSON(): HotbarStoreModel {
|
|
const model: HotbarStoreModel = {
|
|
hotbars: this.hotbars,
|
|
activeHotbarId: this.activeHotbarId,
|
|
};
|
|
|
|
return toJS(model);
|
|
}
|
|
|
|
getActive(): Hotbar {
|
|
const hotbar = this.findById(this.activeHotbarId);
|
|
|
|
assert(hotbar, "There MUST always be an active hotbar");
|
|
|
|
return hotbar;
|
|
}
|
|
|
|
findByName(name: string) {
|
|
return this.hotbars.find((hotbar) => hotbar.name === name);
|
|
}
|
|
|
|
findById(id: string) {
|
|
return this.hotbars.find((hotbar) => hotbar.id === id);
|
|
}
|
|
|
|
@action
|
|
add(data: CreateHotbarData, { setActive = false }: CreateHotbarOptions = {}) {
|
|
const hotbar = getEmptyHotbar(data.name, data.id);
|
|
|
|
this.hotbars.push(hotbar);
|
|
|
|
if (setActive) {
|
|
this._activeHotbarId = hotbar.id;
|
|
}
|
|
}
|
|
|
|
@action
|
|
setHotbarName(id: string, name: string): void {
|
|
const index = this.hotbars.findIndex((hotbar) => hotbar.id === id);
|
|
|
|
if (index < 0) {
|
|
return void console.warn(
|
|
`[HOTBAR-STORE]: cannot setHotbarName: unknown id`,
|
|
{ id },
|
|
);
|
|
}
|
|
|
|
this.hotbars[index].name = name;
|
|
}
|
|
|
|
@action
|
|
remove(hotbar: Hotbar) {
|
|
assert(this.hotbars.length >= 2, "Cannot remove the last hotbar");
|
|
|
|
this.hotbars = this.hotbars.filter((h) => h !== hotbar);
|
|
|
|
if (this.activeHotbarId === hotbar.id) {
|
|
this.setActiveHotbar(0);
|
|
}
|
|
}
|
|
|
|
@action
|
|
addToHotbar(item: CatalogEntity, cellIndex?: number) {
|
|
const hotbar = this.getActive();
|
|
const uid = item.getId();
|
|
const name = item.getName();
|
|
|
|
if (typeof uid !== "string") {
|
|
throw new TypeError("CatalogEntity's ID must be a string");
|
|
}
|
|
|
|
if (typeof name !== "string") {
|
|
throw new TypeError("CatalogEntity's NAME must be a string");
|
|
}
|
|
|
|
if (this.isAddedToActive(item)) {
|
|
return;
|
|
}
|
|
|
|
const entity = {
|
|
uid,
|
|
name,
|
|
source: item.metadata.source,
|
|
};
|
|
const newItem = { entity };
|
|
|
|
if (cellIndex === undefined) {
|
|
// Add item to empty cell
|
|
const emptyCellIndex = hotbar.items.indexOf(null);
|
|
|
|
if (emptyCellIndex != -1) {
|
|
hotbar.items[emptyCellIndex] = newItem;
|
|
} else {
|
|
broadcastMessage(hotbarTooManyItemsChannel);
|
|
}
|
|
} else if (0 <= cellIndex && cellIndex < hotbar.items.length) {
|
|
hotbar.items[cellIndex] = newItem;
|
|
} else {
|
|
this.dependencies.logger.error(
|
|
`[HOTBAR-STORE]: cannot pin entity to hotbar outside of index range`,
|
|
{ entityId: uid, hotbarId: hotbar.id, cellIndex },
|
|
);
|
|
}
|
|
}
|
|
|
|
@action
|
|
removeFromHotbar(uid: string): void {
|
|
const hotbar = this.getActive();
|
|
const index = hotbar.items.findIndex((item) => item?.entity.uid === uid);
|
|
|
|
if (index < 0) {
|
|
return;
|
|
}
|
|
|
|
hotbar.items[index] = null;
|
|
}
|
|
|
|
/**
|
|
* Remove all hotbar items that reference the `uid`.
|
|
* @param uid The `EntityId` that each hotbar item refers to
|
|
* @returns A function that will (in an action) undo the removing of the hotbar items. This function will not complete if the hotbar has changed.
|
|
*/
|
|
@action
|
|
removeAllHotbarItems(uid: string) {
|
|
for (const hotbar of this.hotbars) {
|
|
const index = hotbar.items.findIndex((i) => i?.entity.uid === uid);
|
|
|
|
if (index >= 0) {
|
|
hotbar.items[index] = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
findClosestEmptyIndex(from: number, direction = 1) {
|
|
let index = from;
|
|
const hotbar = this.getActive();
|
|
|
|
while (hotbar.items[index] != null) {
|
|
index += direction;
|
|
}
|
|
|
|
return index;
|
|
}
|
|
|
|
@action
|
|
restackItems(from: number, to: number): void {
|
|
const { items } = this.getActive();
|
|
const source = items[from];
|
|
const moveDown = from < to;
|
|
|
|
if (
|
|
from < 0 ||
|
|
to < 0 ||
|
|
from >= items.length ||
|
|
to >= items.length ||
|
|
isNaN(from) ||
|
|
isNaN(to)
|
|
) {
|
|
throw new Error("Invalid 'from' or 'to' arguments");
|
|
}
|
|
|
|
if (from == to) {
|
|
return;
|
|
}
|
|
|
|
items.splice(from, 1, null);
|
|
|
|
if (items[to] == null) {
|
|
items.splice(to, 1, source);
|
|
} else {
|
|
// Move cells up or down to closes empty cell
|
|
items.splice(this.findClosestEmptyIndex(to, moveDown ? -1 : 1), 1);
|
|
items.splice(to, 0, source);
|
|
}
|
|
}
|
|
|
|
switchToPrevious() {
|
|
let index = this.activeHotbarIndex - 1;
|
|
|
|
if (index < 0) {
|
|
index = this.hotbars.length - 1;
|
|
}
|
|
|
|
this.setActiveHotbar(index);
|
|
}
|
|
|
|
switchToNext() {
|
|
let index = this.activeHotbarIndex + 1;
|
|
|
|
if (index >= this.hotbars.length) {
|
|
index = 0;
|
|
}
|
|
|
|
this.setActiveHotbar(index);
|
|
}
|
|
|
|
/**
|
|
* Checks if entity already pinned to the active hotbar
|
|
*/
|
|
isAddedToActive(entity: CatalogEntity | null | undefined): boolean {
|
|
if (!entity) {
|
|
return false;
|
|
}
|
|
|
|
const indexInActiveHotbar = this.getActive().items.findIndex(item => item?.entity.uid === entity.getId());
|
|
|
|
return indexInActiveHotbar >= 0;
|
|
}
|
|
|
|
getDisplayLabel(hotbar: Hotbar): string {
|
|
return `${this.getDisplayIndex(hotbar)}: ${hotbar.name}`;
|
|
}
|
|
|
|
getDisplayIndex(hotbar: Hotbar): string {
|
|
const index = this.hotbarIndex(hotbar);
|
|
|
|
if (index < 0) {
|
|
return "??";
|
|
}
|
|
|
|
return `${index + 1}`;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* This function ensures that there are always exactly `defaultHotbarCells`
|
|
* worth of items in the hotbar.
|
|
* @param hotbar The hotbar to modify
|
|
*/
|
|
function ensureExactHotbarItemLength(hotbar: Hotbar) {
|
|
// if there are not enough items
|
|
while (hotbar.items.length < defaultHotbarCells) {
|
|
hotbar.items.push(null);
|
|
}
|
|
|
|
// if for some reason the hotbar was overfilled before, remove as many entries
|
|
// as needed, but prefer empty slots and items at the end first.
|
|
while (hotbar.items.length > defaultHotbarCells) {
|
|
const lastNull = hotbar.items.lastIndexOf(null);
|
|
|
|
if (lastNull >= 0) {
|
|
hotbar.items.splice(lastNull, 1);
|
|
} else {
|
|
hotbar.items.length = defaultHotbarCells;
|
|
}
|
|
}
|
|
}
|