Jump to content

Is there anyway that emby can load JavaScript code when login


shure

Recommended Posts

shure

I have stored some JavaScript code in my plugin configuration that can make my emby more fascinating.

Is there anyway that emby can load these code when I login ?

Just for now, I have to open the page of my plugin and these code can be loaded.

Thanks for helping 

Link to comment
Share on other sites

mickle026
2 hours ago, shure said:

I have stored some JavaScript code in my plugin configuration that can make my emby more fascinating.

Is there anyway that emby can load these code when I login ?

Just for now, I have to open the page of my plugin and these code can be loaded.

Thanks for helping 

Not sure what you are trying to achieve, but you can read your config file using server entry point when emby loads the plugin at startup

using Extend_Provider_Ids;
using MediaBrowser.Common;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Plugins;
using System.Net;
using System.Threading;
using System.Threading.Tasks;

namespace Extend_Provider_Ids
{
    public class ServerEntryPoint : IServerEntryPoint
    {

        public ServerEntryPoint()
        {

        }

        public void Run()
        {
            var config = Plugin.Instance.Configuration;  
            Plugin.Instance.UpdateConfiguration(Plugin.Instance.Configuration);

          // this is a static void in the namespace that loads and sets true/false settings at startup
          // here you can access anything you want the plugin to do from your config file as the plugin is injected into emby
          
            Extend_Provider_Ids.UpdateProviderToggleSettings();

        }

        public void Dispose() 
        {

        }


    }

Here is more of the snippet - perhaps you can modify this somehow to suit your needs?

 

Capture.JPG.10e3dce625578375fb0145a4123eb033.JPG

 

  • Thanks 1
Link to comment
Share on other sites

shure
11 hours ago, mickle026 said:

Not sure what you are trying to achieve, but you can read your config file using server entry point when emby loads the plugin at startup

using Extend_Provider_Ids;
using MediaBrowser.Common;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Plugins;
using System.Net;
using System.Threading;
using System.Threading.Tasks;

namespace Extend_Provider_Ids
{
    public class ServerEntryPoint : IServerEntryPoint
    {

        public ServerEntryPoint()
        {

        }

        public void Run()
        {
            var config = Plugin.Instance.Configuration;  
            Plugin.Instance.UpdateConfiguration(Plugin.Instance.Configuration);

          // this is a static void in the namespace that loads and sets true/false settings at startup
          // here you can access anything you want the plugin to do from your config file as the plugin is injected into emby
          
            Extend_Provider_Ids.UpdateProviderToggleSettings();

        }

        public void Dispose() 
        {

        }


    }

Here is more of the snippet - perhaps you can modify this somehow to suit your needs?

 

Capture.JPG.10e3dce625578375fb0145a4123eb033.JPG

 

thanks for your reply.

I want to show the html page and run the JavaSript code I prepared when user login other than they need to click the  nav of my plugin in the user menu

Link to comment
Share on other sites

shure
events.on(connectionManager, "localusersignedin", function () {
  // JaveScript code to run when the user is signed in
});

I can use this code in front-end, but I have to modify front-end file and just for users who use web client.

I want to find a way that can make it happend in back-end through plugin

Link to comment
Share on other sites

mickle026

Without a kindof hack, i am not sure you can.

You can backup the original webpage and replace it with your own.  Devs will not recommend that but you can.

You can replace the whole gui if you are proficient in html/css/js

Find wherever it is in \Emby-Server\system\dashboard-ui\

 

what you might be looking fo is probably in \Emby-Server\system\dashboard-ui\startup\

 

You can use the server entry point to backup and replace files, then you will be able to do this accross server updates.

Edited by mickle026
Link to comment
Share on other sites

shure
6 minutes ago, mickle026 said:

Without a kindof hack, i am not sure you can.

You can backup the original webpage and replace it with your own.  Devs will not recommend that but you can.

You can replace the whole gui if you are proficient in html/css/js

Find wherever it is in \Emby-Server\system\dashboard-ui\

 

You can use the server entry point to backup and replace files, then you will be able to do this accross server updates.

I'm writing a plugin to help user to add and manage their own js code and css to add some feature such as  photo carousel.

admin also can provide some code, and  user can choose use it or not

 

admin page:

photo_2023-05-13_17-39-50.jpg.50d8ae264bd83912b4a10befc4b5f36a.jpg

user page:

photo_2023-05-13_17-39-57.jpg.12d9dd6ef07e75252e4b0d0032b578fe.jpg

 

everything works fine, only user must click the load button to make their code take effect every time after they sign in .

so, I want to find a way that user's code can take effect when they sign in.

May it happend only through plugin ?

  • Like 2
Link to comment
Share on other sites

Cheesegeezer

I think Mickle is suggesting the correct advice here for you. 
 

its really not that straight forward and quite a lot of work to get done, essentially you need to hack the modules in emby core code. And ensure that your modified modules load everytime the server is restarted.

i would love to see some extension given to us plugin devs to add functionality to the UI, but I don’t think this will ever happen. 
And for the amount of work needed and maintenance we tend to steer clear of hacks. 
 

another option would be use channels. But if you want a custom UI then that wouldn’t work. 
 

Good luck chief 👍

Link to comment
Share on other sites

shure
35 minutes ago, Cheesegeezer said:

I think Mickle is suggesting the correct advice here for you. 
 

its really not that straight forward and quite a lot of work to get done, essentially you need to hack the modules in emby core code. And ensure that your modified modules load everytime the server is restarted.

i would love to see some extension given to us plugin devs to add functionality to the UI, but I don’t think this will ever happen. 
And for the amount of work needed and maintenance we tend to steer clear of hacks. 
 

another option would be use channels. But if you want a custom UI then that wouldn’t work. 
 

Good luck chief 👍

thanks for your reply, it helps me a lot.

for now, I have to add this to app.js to make it happend.

applyCssJS.js will get user's code stored in Local (appSettings) and admin's code stored in Server and make them take effect.

So, I have to suggest my user to use the modified app other than the official one.

 image.jpeg.6033cd8bbbae189356d84ae1aae41c9d.jpeg

  • Like 1
Link to comment
Share on other sites

shure
2 hours ago, mickle026 said:

Without a kindof hack, i am not sure you can.

You can backup the original webpage and replace it with your own.  Devs will not recommend that but you can.

You can replace the whole gui if you are proficient in html/css/js

Find wherever it is in \Emby-Server\system\dashboard-ui\

 

what you might be looking fo is probably in \Emby-Server\system\dashboard-ui\startup\

 

You can use the server entry point to backup and replace files, then you will be able to do this accross server updates.

thanks for your reply

Does it mean that plugin can use the server entry point to replace the front-end file in my elecron app or it works only for web ?

thanks for your help !

Link to comment
Share on other sites

mickle026

No, if you replace the dashboard-ui files, that comes from the server.

I'm not sure how it would affect all client apps, but it would affect ALL client apps not just the web.

This is new territory for us, so you would have to try it yourself and find out.  It would be handy to other developers if you report your findings.

You might have to change more than the login page and store a persistent "session".

 

I have not done this, so my help can only be limited.

  • Agree 1
Link to comment
Share on other sites

Cheesegeezer
On 13/05/2023 at 12:44, shure said:

thanks for your reply

Does it mean that plugin can use the server entry point to replace the front-end file in my elecron app or it works only for web ?

thanks for your help !

Are you creating a plugin or a new front end(client UI)

The plugin infrastructure is not designed for UI development. Trying to hack the Emby components is not the way to go.
 

You should create your own App, with ots own ClientID, deviceId, etc and authenticate each user. 
believe me you will have so much more control for every aspect of your UI and also you will save so much time, rather than figuring out what needs hacking in emby to get the same results. Also if emby change anything your UI breaks and you need to figure it all out again.

  • Agree 1
Link to comment
Share on other sites

shure
53 minutes ago, Cheesegeezer said:

Are you creating a plugin or a new front end(client UI)

The plugin infrastructure is not designed for UI development. Trying to hack the Emby components is not the way to go.
 

You should create your own App, with ots own ClientID, deviceId, etc and authenticate each user. 
believe me you will have so much more control for every aspect of your UI and also you will save so much time, rather than figuring out what needs hacking in emby to get the same results. Also if emby change anything your UI breaks and you need to figure it all out again.

Thanks for your help,  My plugin is done

 

 

 

  • Like 1
Link to comment
Share on other sites

Cheesegeezer
4 minutes ago, shure said:

Thanks for your help,  My plugin is done

 

 

 

Great job, i will certainly check it out. Have you posted the dll in the plugins or tools and utilities section. I’ll be keen to try it out. JS is not my strong language, i hate it to be honest, but its a necessary evil in this day and age!! 
 

So glad you finished it and are happy with it and thanks for sharing!! 👍👍

Link to comment
Share on other sites

shure
1 minute ago, Cheesegeezer said:

Great job, i will certainly check it out. Have you posted the dll in the plugins or tools and utilities section. I’ll be keen to try it out. JS is not my strong language, i hate it to be honest, but its a necessary evil in this day and age!! 
 

So glad you finished it and are happy with it and thanks for sharing!! 👍👍

How to use

you can refer to this, if there is a bug, please let me know, thanks for you opinion !

  • Thanks 1
Link to comment
Share on other sites

Cheesegeezer

Ahh ok got it!! So its more of an extension than a plugin. 👍👍
 

i think you should create a page/thread for this in the tools and utilities section. You will probably get a lot of traction from the CSS and JS power users that like to change how the web UI looks in Emby

Edited by Cheesegeezer
Link to comment
Share on other sites

shure
1 minute ago, Cheesegeezer said:

Ahh ok got it!! So its more of an extension than a plugin. 👍👍

I have tried to make it only a plugin, but it's hard to make custom code take effect when user sign in.

if it is only a plugin,  user have to click the load btn in plugin page to make their code take effect every time they open or reload emby.

I will keep looking for a appropriate  way to solve it.

for the time being, you have to modify front-end part.

Link to comment
Share on other sites

Cheesegeezer

The serverentrypoint.cs (c#) can do this for you and you could create a custom api endpoint in your plugin using the IService interface(seperate class) it’s a good way to interact js with c# and route the JS page to load and validate the user and load their custom JS. 
 

the serverentrypoint.cs handles all this on load after the user is authenticated. This class should inherit from IServerEntryPoint and load in the dependencies that are required. The Run method will be where you do this heavy lifting, and ensure you ensure the Dispose method cleans up anything you don’t want.
 

Link to comment
Share on other sites

shure
8 minutes ago, Cheesegeezer said:

The serverentrypoint.cs (c#) can do this for you and you could create a custom api endpoint in your plugin using the IService interface(seperate class) it’s a good way to interact js with c# and route the JS page to load and validate the user and load their custom JS. 
 

the serverentrypoint.cs handles all this on load after the user is authenticated. This class should inherit from IServerEntryPoint and load in the dependencies that are required. The Run method will be where you do this heavy lifting, and ensure you ensure the Dispose method cleans up anything you don’t want.
 

thanks a lot! I will work on it

Link to comment
Share on other sites

Cheesegeezer
2 minutes ago, shure said:

thanks a lot! I will work on it

I can send a pull request on your github for some basics a bit later. So you understand how the IService works. 
 

I’m not sure how familiar you are with Emby plugin development. If your fine, just let me know 👍

  • Thanks 1
Link to comment
Share on other sites

shure
10 minutes ago, Cheesegeezer said:

I can send a pull request on your github for some basics a bit later. So you understand how the IService works. 
 

I’m not sure how familiar you are with Emby plugin development. If your fine, just let me know 👍

I'm not familiar with emby plugin api, if you would like to provide a brief description of how it works, that would be a great help !

thank you

Link to comment
Share on other sites

Cheesegeezer
7 minutes ago, shure said:

I'm not familiar with emby plugin api, if you would like to provide a brief description of how it works, that would be a great help !

thank you

Ok, but now we're moving to the realms of plugin development for emby and not just an extension. 
 

your source code is delightful but not setup for a plugin. I think you should take a look at tge emby.dev plugin example and create a plugin based on that. 

  • Thanks 1
Link to comment
Share on other sites

shure
4 hours ago, Cheesegeezer said:

Ok, but now we're moving to the realms of plugin development for emby and not just an extension. 
 

your source code is delightful but not setup for a plugin. I think you should take a look at tge emby.dev plugin example and create a plugin based on that. 

I'm not sure is this what you mean 

https://github.com/Shurelol/Emby.CustomCssJS/tree/main/Emby.CustomCssJS

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...