Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing arguments to apps functions #28

Open
theottm opened this issue Dec 16, 2022 · 3 comments
Open

Passing arguments to apps functions #28

theottm opened this issue Dec 16, 2022 · 3 comments

Comments

@theottm
Copy link

theottm commented Dec 16, 2022

Hi!

First of all good job making firefox controllable from emacs !

I have been playing around with the code a bit... and it works great! I just got a bit confused that only the first window is accessible when doing things with tabs.

I am at baby level in web technologies, so I am obviously missing some basics. I have a few questions.

Why are you slitting the functionalities in apps that take EmacsRequests? Is it to avoid js injection?

How would one extend Tabs.ts to receive a parameter specifying a windowId? I see that openSearchTab as well as openTab can get a parameter p. So it seems that I can set p to a key-value structure and access them in the function. On the emacs-side it seems calling (spookfox-tabs--request client "SEARCH_FOR" tab) will call openSearchTab with p being tab, right? So it seems pretty straightforward.

Also if I understand right, if I want to add parameters to the functions in Tabs.ts, I'll have to recompile the addon myself. I'll have a look at contributing.org then ;)

For my use case, since I struggle doing any js, when I want to query some data from firefox, it would be nice to have an app that just returns almost all the state of firefox, and process it in emacs. I imagine it being too slow and overkill but maybe there is a nice threshold to find. It could be nice to have anyway for quick experimentation purposes.

Cheers,

Théo

@bitspook
Copy link
Owner

Hello @theottm!

I just got a bit confused that only the first window is accessible when doing things with tabs.

That's correct and only reason for this behavior is my decision to not bother with multiple windows so far mostly because my own use-case involve only one browser window 99% of the time. If you need multiple windows support, I'd suggest creating another issue on Github. I'll get to it once I have some breathing room. Or you can also take a jibe at implementing it yourself, I'll be very happy to help you in any capacity I can 🙂


Why are you slitting the functionalities in apps that take EmacsRequests? Is it to avoid js injection?

This extension is supposed to run from inside user's machine without any remote capabilities of itself. So avoiding js-injection in any manner isn't a concern right now.

I introduced the concept of 'apps' as an isolation-mechanism so:

  • It is possible for users to create their own apps (which isn't possible right now because of browser policies; more on it below)
  • It is possible for users to enable/disable the apps they want to use. For example org-tabs is kinda buggy right now, and not everyone might want to use it. So a user can enable only tabs app for accessing browser-tabs from Emacs while not enabling syncing the tabs in an org file.
  • Modular software is easy to maintain/extend
  • To provide a thin framework for rapid prototyping. For example state-management in browser. State-management can get hairy really quickly, so I am trying to build a message-passing-based state-management so developers can focus on building the app itself and not the plumbing needed for every app.

You can try thinking of 'apps' in spookfox as emacs packages or firefox addons. That's my intention with them at least, how far I can take it is a different matter of course 😄

I wish it was better documented; that's another thing on my todo list, just waiting for things irl to settle down a bit.


How would one extend Tabs.ts to receive a parameter specifying a windowId? I see that openSearchTab as well as openTab can get a parameter p. So it seems that I can set p to a key-value structure and access them in the function. On the emacs-side it seems calling (spookfox-tabs--request client "SEARCH_FOR" tab) will call openSearchTab with p being tab, right? So it seems pretty straightforward.

You're correct here; it's pretty straight-forward message/request passing b/w Emas and Firefox.


Also if I understand right, if I want to add parameters to the functions in Tabs.ts, I'll have to recompile the addon myself. I'll have a look at contributing.org then ;)

That's correct, and is the reason why apps can't be the "extend Firefox on whim" abstraction I want them to be. Browser won't allow injecting javascript on-the-fly even into browser addons. I intend to introduce a compile-to-js thingy into spookfox to work around this; for example biwascheme. But for now, only way to extend firefox side of things is by building the firefox-addon locally. But for now, if you want to make any change on browser side, you need to re-build the addon.


For my use case, since I struggle doing any js, when I want to query some data from firefox, it would be nice to have an app that just returns almost all the state of firefox, and process it in emacs. I imagine it being too slow and overkill but maybe there is a nice threshold to find. It could be nice to have anyway for quick experimentation purposes.

You can always create your own spookfox 'app' and have it behave in this way; if it works well, other apps can be ported so most of the actual work is done on Emacs side. :-)


I hope I was able to make things a bit clearer. Please feel free to ask any questions or feature requests (preferably as individual github issues so they're easy to track) or if you need help with js (in case you want to hack on it yourself).

Thank you for trying Spookfox out! It brings me great pleasure to know my code was able to help someone out a little :-)

@bitspook
Copy link
Owner

bitspook commented Jan 4, 2023

Hello @theottm,

Today I encountered a bug in my most used workflow (working with active tab in firefox), which was resulted by default windowId for my browser being not 1. During fixing this, I thought of creating a small example for you for passing arguments from emacs side to typescript. Please take a look at these two commits.

I still haven't added support for multiple browser windows all around, but (spookfox-request-active-tab) now accepts an optional window-id argument.

@theottm
Copy link
Author

theottm commented Jan 4, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants