-
Notifications
You must be signed in to change notification settings - Fork 355
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
Add support for external auth providers in code search #6919
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,26 @@ | ||
package com.sourcegraph.find.browser; | ||
|
||
import com.intellij.openapi.util.Disposer; | ||
import com.intellij.ui.jcef.JBCefBrowser; | ||
import com.sourcegraph.cody.config.notification.CodySettingChangeListener; | ||
import com.sourcegraph.config.ThemeUtil; | ||
import javax.swing.*; | ||
import org.cef.CefApp; | ||
import org.cef.browser.CefBrowser; | ||
import org.cef.handler.CefLifeSpanHandlerAdapter; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class SourcegraphJBCefBrowser extends JBCefBrowser { | ||
private final JavaToJSBridge javaToJSBridge; | ||
public SourcegraphJBCefBrowser( | ||
@NotNull JSToJavaBridgeRequestHandler requestHandler, String endpointUrl) { | ||
super(endpointUrl.replaceAll("/+$", "").replace("https://", "http://") + "/html/index.html"); | ||
|
||
public SourcegraphJBCefBrowser(@NotNull JSToJavaBridgeRequestHandler requestHandler) { | ||
super("http://sourcegraph/html/index.html"); | ||
// Create and set up JCEF browser | ||
CefApp.getInstance() | ||
.registerSchemeHandlerFactory("http", "sourcegraph", new HttpSchemeHandlerFactory()); | ||
|
||
// Create bridges, set up handlers, then run init function | ||
String initJSCode = "window.initializeSourcegraph();"; | ||
JSToJavaBridge jsToJavaBridge = new JSToJavaBridge(this, requestHandler, initJSCode); | ||
Disposer.register(this, jsToJavaBridge); | ||
javaToJSBridge = new JavaToJSBridge(this); | ||
|
||
requestHandler | ||
.getProject() | ||
.getService(CodySettingChangeListener.class) | ||
.setJavaToJSBridge(javaToJSBridge); | ||
|
||
UIManager.addPropertyChangeListener( | ||
propertyChangeEvent -> { | ||
if (propertyChangeEvent.getPropertyName().equals("lookAndFeel")) { | ||
javaToJSBridge.callJS("themeChanged", ThemeUtil.getCurrentThemeAsJson()); | ||
// Schema registration need to happen in a callback, or it may crash in IJ 2023.2: | ||
// https://youtrack.jetbrains.com/issue/JBR-5853 | ||
CefLifeSpanHandlerAdapter lifeSpanHandler = | ||
new CefLifeSpanHandlerAdapter() { | ||
public void onAfterCreated(CefBrowser browser) { | ||
CefApp.getInstance() | ||
.registerSchemeHandlerFactory("http", null, new HttpSchemeHandlerFactory()); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
@NotNull | ||
public JavaToJSBridge getJavaToJSBridge() { | ||
return javaToJSBridge; | ||
this.getJBCefClient().addLifeSpanHandler(lifeSpanHandler, this.getCefBrowser()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,8 +19,6 @@ class CodySettingChangeListener(project: Project) : ChangeListener(project) { | |
CodySettingChangeActionNotifier.TOPIC, | ||
object : CodySettingChangeActionNotifier { | ||
override fun afterAction(context: CodySettingChangeContext) { | ||
// Notify JCEF about the config changes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't we need to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That config was already not containing any info useful for sourcegraph search. |
||
javaToJSBridge?.callJS("pluginSettingsChanged", ConfigUtil.getConfigAsJson(project)) | ||
|
||
if (context.oldCodyEnabled != context.newCodyEnabled) { | ||
if (context.newCodyEnabled) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice