SpikeHD / Dorion

Tiny alternative Discord client with a smaller footprint, snappier startup, themes, plugins and more!
https://spikehd.github.io/projects/dorion/
GNU General Public License v3.0
632 stars 21 forks source link

Support Vencord #7

Closed Liz-chan closed 2 years ago

Liz-chan commented 2 years ago

I'm currently using this client mod called Vencord on the official client and it comes with a lot of useful plugins and also lets you use themes kind of how Dorion does it (it loads it from a .css file). I think it'd be good if Vencord could somehow be integrated with Dorion so that I can continue to use those plugins.

If it makes it any easier, the mod also comes as a browser extension and userscript as well: https://github.com/Vendicated/Vencord/releases/latest/download/extension.zip https://github.com/Vendicated/Vencord/releases/download/devbuild/Vencord.user.js

SpikeHD commented 2 years ago

The userscript DOES make it easier! First problem I encountered was that Vencord stores it's options in localStorage which apparently just isn't a thing: image Seeing as that issue occurs at the end of the script, it's possible Vencord will work fine if the settings are changed to be stored somewhere else, though I have no idea nor am I totally familiar with the project. If you'd like to attempt to fork the project and change that feel free, otherwise it'll be something I look at, but very very low priority.

Liz-chan commented 2 years ago

Hm that's pretty strange, Discord stores a lot of things in localStorage so I'm not sure if it could be undefined. I opened a devtools window from the Edge Webview and it was defined on there.

EDIT: Seems Discord actually delete the localStorage property and that's why it shows as undefined.

SpikeHD commented 2 years ago

Yknow I was just thinking that they did that, how odd. It could probably be rewritten fairly easily to store the configuration into a cookie instead honestly.

OR as a compatibility thing, I could redefine localStorage with a custom implementation in the injected JS (whether that's with cookies or something else)

Liz-chan commented 2 years ago

I found this snippet on SO and it seems like it works:


// If we create an <iframe> and connect it to our document, its
// contentWindow property will return a new Window object with
// a freshly created `localStorage` property. Once we obtain the
// property descriptor, we can disconnect the <iframe> and let it
// be collected — the getter function itself doesn’t depend on
// anything from its origin realm to work**.

function getLocalStoragePropertyDescriptor() {
  const iframe = document.createElement('iframe');
  document.head.append(iframe);
  const pd = Object.getOwnPropertyDescriptor(iframe.contentWindow, 'localStorage');
  iframe.remove();
  return pd;
}

// We have several options for how to use the property descriptor
// once we have it. The simplest is to just redefine it:

Object.defineProperty(window, 'localStorage', getLocalStoragePropertyDescriptor());

window.localStorage.heeeeey; // yr old friend is bak

// You can also use any function application tool, like `bind` or `call`
// or `apply`. If you hold onto a reference to the object somehow, it
// won’t matter if the global property gets deleted again, either.

const localStorage = getLocalStoragePropertyDescriptor().get.call(window);```
SpikeHD commented 2 years ago

Added a commit that redefines window.localStorage (https://github.com/SpikeHD/Dorion/commit/74957e6b24ce5b32b621c3535921f48d0d9e7767). Have yet to test Vencord but I will some time soon.

SpikeHD commented 2 years ago

Good news!

image

So, the gist of the problems I was having, which were plentiful, were that Vencord patches Discord WebPack as fast as it can. Like, literally milliseconds after the page is navigated to Discord. That becomes a problem with the current plugin system, where plugins are loaded much later into the Discord load cycle.

The solution will be that I will be implementing will be an option for plugins to be labelled as "preload", which means they will be loaded almost instantaneously. Making this optional means that some plugins that depends on Discord being, yknow, loaded, will be fine, and compatibility for outliers like Vencord will also exist.

Expect Vencord to work in the next release 👍

SpikeHD commented 2 years ago

Preload plugins are now a part of Dorion, which should allow for Vencord to work. If there are issues with it unrelated to the inital injection, please make a new issue instead of re-opening this one :)