Fork me on GitHub
#portal
<
2022-05-09
>
wilkerlucio15:05:13

@djblue hello, I've been noticing that Portal IntelliJ plugin got worse at applying the theme, in the past when I ran it a second time it used to get the right theme, but now I have times where I can keep asking for new portal but it doesn't apply the intellij theme

1
wilkerlucio16:05:30

restarting IntelliJ sometimes fixes it, is there a way to ask Portal to change the theme after it is initialized?

wilkerlucio16:05:35

I see the set-theme command, but the intellij one doesn't show in the options

djblue16:05:21

The problem is that the theme is https://github.com/djblue/portal/blob/master/extension-intellij/src/main/clojure/portal/extensions/intellij/factory.clj#L42-L54 and the issues is a race condition around when to apply the theme

wilkerlucio16:05:19

if we are ok with some flickering in the initialization, maybe Portal could delay a bit the theme application to avoid this race condition?

djblue16:05:18

That is one option. Another I'm thinking about is passing the options as a string via query params

wilkerlucio16:05:40

as long as that message doesn't get big enough to blow out the URL size, that should be fine

R.A. Porter17:05:44

I feel pretty dim that I can't suss out what the race condition is, but my best guess is that the calls to .executeJavaScript on the CEFBrowser are async? If that's it, I'm wondering if this would resolve the problem:

Index: extension-intellij/src/main/clojure/portal/extensions/intellij/factory.clj
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/extension-intellij/src/main/clojure/portal/extensions/intellij/factory.clj b/extension-intellij/src/main/clojure/portal/extensions/intellij/factory.clj
--- a/extension-intellij/src/main/clojure/portal/extensions/intellij/factory.clj	(revision Staged)
+++ b/extension-intellij/src/main/clojure/portal/extensions/intellij/factory.clj	(date 1652117683035)
@@ -39,19 +39,22 @@
      :themes
      {::theme (theme/get-theme)}})))
 
-(defn init-options [browser]
-  (run-js browser
-          (str
-           "sessionStorage.setItem(\"PORTAL_EXTENSION_OPTIONS\", " (get-options) ")")))
+(defn- get-ext-opts []
+  (str
+   "sessionStorage.setItem(\"PORTAL_EXTENSION_OPTIONS\", " (get-options) ");"))
+
+(defn init-options [browser]
+  (run-js browser (get-ext-opts)))
 
 (defn patch-options
   ([]
    (doseq [browser (into [] (map :browser) (vals @instances))]
      (patch-options browser)))
   ([browser]
-   (init-options browser)
    (run-js browser
-           (str "portal.ui.options.patch(" (get-options) ")"))))
+           (str
+            (get-ext-opts)
+            "portal.ui.options.patch(" (get-options) ");"))))
 
 (defn -uiSettingsChanged  [_this _] (patch-options))
 (defn -globalSchemeChange [_this _] (patch-options))

djblue17:05:12

I'll have to take a look, but I pushed up https://github.com/djblue/portal/commit/1e0a14a3211fbb7ffb364b0e36dd321911427fac which might help with the race condition :thinking_face:

wilkerlucio13:05:08

@djblue I tried to build it here to test, but I'm getting some error, maybe it needs a more recent node version?

=> npx vsce package
----- Error --------------------------------------------------------------------
Type:     java.lang.IllegalArgumentException
Message:  Cannot open <#object[java.io.OutputStreamWriter 0x6ba20a7b "java.io.OutputStreamWriter@6ba20a7b"]> as an InputStream.

/Users/wilkerlucio/Development/portal/extension-vscode/node_modules/vsce/out/package.js:136
    return (translations ?? [])
                          ^

wilkerlucio13:05:21

(from running bb ext)

R.A. Porter15:05:34

@djblue Did you have a chance to look at my proposal that avoids lock-checking?

djblue02:05:43

@U01GXCWSRMW I can still reproduce the issue with the above diff. I think it's mainly around close/open, because close will kill the old http server, so open will start a new one with a new http port, aka a new domain. Thus run-js is probably running in the context of the old domain since loadURL is async.

👍 1
djblue02:05:19

I think another option instead of using a future to poll is adding some event handlers, but I haven't looked into that yet and if the future option works well enough, I might leave it 😆

R.A. Porter02:05:16

If it works, it works. 😄

djblue02:05:20

@U066U8JQJ not sure why it doesn't work for you but here is the latest build 👌

🙏 1
wilkerlucio02:05:36

@djblue just did the first tests here, no wrong themes so far 😄

awesome 1
djblue02:05:56

Ok... I lied. https://github.com/djblue/portal/commit/471207ffc351efed2eceebf906fbd1f657ce1a10 is the event listener version 😂 Seems to work just as well except the interaction with the Portal UI is a little simpler.

1
djblue02:05:20

And here is the build if you'd like to try it 👌

wilkerlucio03:05:25

seems good 👍

awesome 1