Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
Use /ws.obsidian.md to make Obsidian devs happier?
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy committed Sep 4, 2023
1 parent 4169416 commit d2159c2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var InterceptorPlugin = class extends import_obsidian.Plugin {
if (syncAPI) {
const scheme = syncAPI.startsWith("http:") ? "ws" : "wss";
const syncAPIWithoutScheme = syncAPI.replace(/^https?:\/\//, "");
url = `${scheme}://${syncAPIWithoutScheme}/ws`;
url = `${scheme}://${syncAPIWithoutScheme}/ws.obsidian.md`;
}
console.log("Websocket URL:", url);
return url;
Expand Down
2 changes: 1 addition & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class InterceptorPlugin extends Plugin {
if(syncAPI) {
const scheme = syncAPI.startsWith("http:") ? "ws" : "wss";
const syncAPIWithoutScheme = syncAPI.replace(/^https?:\/\//, "");
url = `${scheme}://${syncAPIWithoutScheme}/ws`;
url = `${scheme}://${syncAPIWithoutScheme}/ws.obsidian.md`;
}

console.log("Websocket URL:", url);
Expand Down

13 comments on commit d2159c2

@acheong08
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they wouldn't want us to do that due to trademark reasons.

@acheong08
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, this is to bypass a check

@t3chguy
Copy link
Contributor Author

@t3chguy t3chguy commented on d2159c2 Sep 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@acheong08 maybe we should use [String.fromCharCode(97, 112, 105), "obsidian", "md"].join(".") instead lol

@tzyGeneral
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is dont work on ios,i cant login

@t3chguy
Copy link
Contributor Author

@t3chguy t3chguy commented on d2159c2 Sep 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tzyGeneral indeed. This now leverages Electron APIs which are only available on Desktop. I don't have access to any iOS device to figure out similar workarounds there. Contributions welcome.

@acheong08
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do happen to have an IOS device. How would I go about debugging on there?

@acheong08
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I downloaded the IPA and the code looks essentially identical:

 (window.request = un), (window.requestUrl = cn);
      var pn =
        "https://" +
        [String.fromCharCode(97, 112, 105), "obsidian", "md"].join(".");
      Zt && (pn = "http://127.0.0.1:3000");
      var fn = "obsidian-account",
function gn(e, t) {
        return v(this, void 0, void 0, function () {
          return y(this, function (n) {
            switch (n.label) {
              case 0:
                return [
                  4,
                  mn(pn + e, {
                    method: "POST",
                    body: JSON.stringify(t),
                    headers: { "Content-Type": "application/json" },
                  }),
                ];
              case 1:
                return [4, n.sent().json()];
              case 2:
                return [2, n.sent()];
            }
          });
        });
      }

@acheong08
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the error I got on IOS:

TypeError: undefined is not an object (evaluating 'window.electronWindow.webContents')

@acheong08
Copy link
Owner

@acheong08 acheong08 commented on d2159c2 Sep 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example code referencing electronWindow

(t.prototype.updateSize = function () {
              if (this.win) {
                var e = this.win.electronWindow;
                if (
                  e &&
                  !e.isMaximized() &&
                  !e.isMinimized() &&
                  !e.isFullScreen()
                ) {
                  var t = e.getBounds();
                  this.size = {
                    x: t.x,
                    y: t.y,
                    width: t.width,
                    height: t.height,
                  };
                }
              }
            }),

electronWindow seems to be at this.win. Whatever this is.

@acheong08
Copy link
Owner

@acheong08 acheong08 commented on d2159c2 Sep 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't understand JavaScript. No idea where this.win is getting defined.

app.js.zip

I found

this.observer.setWindow(
  (9 == e.nodeType ? e : e.ownerDocument).defaultView || window
),

@t3chguy
Copy link
Contributor Author

@t3chguy t3chguy commented on d2159c2 Sep 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@acheong08 the Electron API won't be available outside of desktop: https://docs.obsidian.md/Plugins/Getting+started/Mobile+development#Disable+your+plugin+on+mobile+devices - would need to investigate if the Mobile JS environment being used has any similar hooks.

@acheong08
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I think service workers might work there instead. I was getting

Uncaught (in promise) DOMException: Failed to get ServiceWorkerRegistration objects: The document is in an invalid state

On desktop but that seems to be Linux specific

@acheong08
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm it also failed on IOS but I was unable to get any specific error message.

try {
			this.worker = setupWorker(
				rest.get("*", (req, res, ctx) => {
					new Notice("Request intercepted: " + req.url.href);
					return res(ctx.status(200));
				})
			);

			// await this.worker.start();
		} catch (e) {
			new Notice("Error setting up worker: " + e);
		}

This simply returned "Failed to load plugin", meaning that whatever error it triggered isn't getting caught by try catch

Not gonna put too much effort into this since I barely use my phone

Please sign in to comment.