Skip to content

Commit

Permalink
add feedback and user profile action icon
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangtianyu committed Jun 26, 2024
1 parent d55ef90 commit 4a3baa5
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/zhongan/devpilot/DevPilotIcons.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ public class DevPilotIcons {
public static final Icon ACCOUNT = IconLoader.getIcon("/icons/account.svg", DevPilotIcons.class);

public static final Icon ACCOUNT_DARK = IconLoader.getIcon("/icons/account.svg", DevPilotIcons.class);

public static final Icon FEEDBACK = IconLoader.getIcon("/icons/feedback.svg", DevPilotIcons.class);

public static final Icon USER_PROFILE = IconLoader.getIcon("/icons/user_profile.svg", DevPilotIcons.class);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.zhongan.devpilot.actions.toolbar;

import com.intellij.ide.BrowserUtil;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.zhongan.devpilot.DevPilotIcons;
import com.zhongan.devpilot.util.DevPilotMessageBundle;
import com.zhongan.devpilot.util.LoginUtils;

import org.jetbrains.annotations.NotNull;

import static com.zhongan.devpilot.constant.DefaultConst.FEEDBACK_URL;

public class ToolbarFeedbackAction extends AnAction {
public ToolbarFeedbackAction() {
super(DevPilotMessageBundle.get("devpilot.toolbarFeedbackAction.text"),
DevPilotMessageBundle.get("devpilot.toolbarFeedbackAction.text"),
DevPilotIcons.FEEDBACK);
}

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
BrowserUtil.browse(LoginUtils.buildAuthUrl(FEEDBACK_URL));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.zhongan.devpilot.actions.toolbar;

import com.intellij.ide.BrowserUtil;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.zhongan.devpilot.DevPilotIcons;
import com.zhongan.devpilot.util.DevPilotMessageBundle;
import com.zhongan.devpilot.util.LoginUtils;

import org.jetbrains.annotations.NotNull;

import static com.zhongan.devpilot.constant.DefaultConst.PROFILE_URL;

public class ToolbarUserProfileAction extends AnAction {
public ToolbarUserProfileAction() {
super(DevPilotMessageBundle.get("devpilot.toolbarUserProfileAction.text"),
DevPilotMessageBundle.get("devpilot.toolbarUserProfileAction.text"),
DevPilotIcons.USER_PROFILE);
}

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
BrowserUtil.browse(LoginUtils.buildAuthUrl(PROFILE_URL));
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/zhongan/devpilot/constant/DefaultConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ private DefaultConst() {

public static final String RAG_DEFAULT_HOST = ConfigBundleUtils.getConfig("devpilot.rag.host", "http://localhost:8085") + "/devpilot/v1/rag/git_repo/embedding_info/";

public static final String OFFICIAL_WEBSITE_URL = ConfigBundleUtils.getConfig("devpilot.official.website.host", "http://localhost:8080");

public static final String FEEDBACK_URL = OFFICIAL_WEBSITE_URL + "/feedback";

public static final String PROFILE_URL = OFFICIAL_WEBSITE_URL + "/profile";

public static final String AUTH_INFO_BUILD_TEMPLATE = "authType=%s&token=%s&userId=%s&timestamp=%s";

public static final boolean AUTH_ON = true;

public static final boolean TELEMETRY_ON = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import com.intellij.ui.jcef.JBCefApp;
import com.zhongan.devpilot.actions.toolbar.ToolbarFeedbackAction;
import com.zhongan.devpilot.actions.toolbar.ToolbarUserProfileAction;
import com.zhongan.devpilot.gui.toolwindows.chat.DevPilotChatToolWindowService;

import java.awt.BorderLayout;
import java.util.List;

import javax.swing.JPanel;

Expand All @@ -31,6 +34,7 @@ public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindo
webPanel.add(devPilotChatToolWindow.getDevPilotChatToolWindowPanel());
Content content = contentFactory.createContent(webPanel, "", false);
toolWindow.getContentManager().addContent(content);
toolWindow.setTitleActions(List.of(new ToolbarFeedbackAction(), new ToolbarUserProfileAction()));
}
}
}
32 changes: 32 additions & 0 deletions src/main/java/com/zhongan/devpilot/util/LoginUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.zhongan.devpilot.statusBar.DevPilotStatusBarBaseWidget;
import com.zhongan.devpilot.statusBar.status.DevPilotStatusEnum;

import java.util.Base64;
import java.util.Locale;

import org.jetbrains.ide.BuiltInServerManager;
Expand Down Expand Up @@ -106,6 +107,37 @@ public static String getUsername() {
}
}

public static String buildAuthInfo() {
if (!isAuthOn()) {
return null;
}

var setting = DevPilotLlmSettingsState.getInstance();
var loginType = LoginTypeEnum.getLoginTypeEnum(setting.getLoginType());

switch (loginType) {
case WX:
return WxAuthUtils.buildAuthInfo();
case ZA:
return ZaSsoUtils.buildAuthInfo(ZaSsoEnum.ZA);
case ZA_TI:
return ZaSsoUtils.buildAuthInfo(ZaSsoEnum.ZA_TI);
}

return null;
}

public static String buildAuthUrl(String baseUrl) {
String encodedString = "";
var paramString = buildAuthInfo();

if (paramString != null) {
encodedString = "?token=" + Base64.getEncoder().encodeToString(paramString.getBytes());
}

return baseUrl + encodedString;
}

// is auth turn on
public static boolean isAuthOn() {
return AUTH_ON;
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/zhongan/devpilot/util/WxAuthUtils.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.zhongan.devpilot.util;

import com.zhongan.devpilot.enums.LoginTypeEnum;
import com.zhongan.devpilot.settings.state.TrialServiceSettingsState;

import java.util.Locale;

import org.apache.commons.lang3.StringUtils;

import static com.zhongan.devpilot.constant.DefaultConst.AUTH_INFO_BUILD_TEMPLATE;

public class WxAuthUtils {
public static boolean isLogin() {
var settings = TrialServiceSettingsState.getInstance();
Expand All @@ -25,4 +30,19 @@ public static void login(String token, String username, String userId) {
setting.setWxUsername(username);
setting.setWxUserId(userId);
}

public static String buildAuthInfo() {
if (!isLogin()) {
return null;
}

var settings = TrialServiceSettingsState.getInstance();

return String.format(
AUTH_INFO_BUILD_TEMPLATE,
LoginTypeEnum.WX.getType().toLowerCase(Locale.ROOT),
settings.getWxToken(),
settings.getWxUserId(),
System.currentTimeMillis());
}
}
28 changes: 28 additions & 0 deletions src/main/java/com/zhongan/devpilot/util/ZaSsoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import org.apache.commons.lang3.StringUtils;

import static com.zhongan.devpilot.constant.DefaultConst.AUTH_INFO_BUILD_TEMPLATE;

public class ZaSsoUtils {
public static boolean isLogin(ZaSsoEnum zaSsoEnum) {
var settings = AIGatewaySettingsState.getInstance();
Expand Down Expand Up @@ -74,4 +76,30 @@ public static ZaSsoEnum getSsoEnum() {
public static String getSsoUserName() {
return zaSsoUsername(getSsoEnum());
}

public static String buildAuthInfo(ZaSsoEnum zaSsoEnum) {
if (!isLogin(zaSsoEnum)) {
return null;
}

var settings = AIGatewaySettingsState.getInstance();

switch (zaSsoEnum) {
case ZA_TI:
return String.format(
AUTH_INFO_BUILD_TEMPLATE,
zaSsoEnum.getName().toLowerCase(Locale.ROOT),
settings.getTiSsoToken(),
settings.getTiSsoUsername(),
System.currentTimeMillis());
case ZA:
default:
return String.format(
AUTH_INFO_BUILD_TEMPLATE,
zaSsoEnum.getName().toLowerCase(Locale.ROOT),
settings.getSsoToken(),
settings.getSsoUsername(),
System.currentTimeMillis());
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/icons/feedback.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/main/resources/icons/feedback_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/main/resources/icons/user_profile.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/main/resources/icons/user_profile_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion src/main/resources/messages/devpilot_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,7 @@ devpilot.notification.update.message=An Update for DevPilot is available. We rec
devpilot.notification.installButton=install
devpilot.notification.hideButton=hide

devpilot.error.report=Report to Devpilot
devpilot.error.report=Report to Devpilot

devpilot.toolbarFeedbackAction.text=Send Feedback to DevPilot
devpilot.toolbarUserProfileAction.text=Go to User Profile
5 changes: 4 additions & 1 deletion src/main/resources/messages/devpilot_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,7 @@ devpilot.notification.update.message=DevPilot\u6700\u65B0\u7248\u5DF2\u5C31\u7EE
devpilot.notification.installButton=\u5B89\u88C5
devpilot.notification.hideButton=\u9690\u85CF

devpilot.error.report=\u62A5\u544Adevpilot
devpilot.error.report=\u62A5\u544Adevpilot

devpilot.toolbarFeedbackAction.text=\u53CD\u9988
devpilot.toolbarUserProfileAction.text=\u7528\u6237\u9762\u677f

0 comments on commit 4a3baa5

Please sign in to comment.