Skip to content

Commit

Permalink
Show automatically webview on first load of a plugin (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
pras0131 authored Sep 17, 2024
1 parent f42b759 commit b74d7cf
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@

package software.aws.toolkits.eclipse.amazonq.configuration;

import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;

public final class PluginStore {
private static final IEclipsePreferences PREFERENCES = ConfigurationScope.INSTANCE.getNode("software.aws.toolkits.eclipse");
import software.aws.toolkits.eclipse.amazonq.util.PluginLogger;

public final class PluginStore {
private static final Preferences PREFERENCES = Preferences.userRoot().node("software.aws.toolkits.eclipse");
private PluginStore() {
// Prevent instantiation
}

public static void put(final String key, final String value) {
PREFERENCES.put(key, value);
try {
PREFERENCES.flush();
} catch (BackingStoreException e) {
PluginLogger.warn(String.format("Error while saving entry to a preference store - key: %s, value: %s", key, value), e);
}
}

public static String get(final String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.ui.IStartup;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;

import software.aws.toolkits.eclipse.amazonq.configuration.PluginStore;
import software.aws.toolkits.eclipse.amazonq.util.PluginLogger;
import software.aws.toolkits.eclipse.amazonq.views.ViewConstants;

import org.eclipse.lsp4e.LanguageServiceAccessor;
import org.eclipse.lsp4e.LanguageServersRegistry;

Expand All @@ -33,6 +43,27 @@ protected IStatus run(final IProgressMonitor monitor) {
}
};
job.schedule();
if (PluginStore.get(ViewConstants.PREFERENCE_STORE_PLUGIN_FIRST_STARTUP_KEY) == null) {
this.launchWebview();
}
}

private void launchWebview() {
IWorkbench workbench = PlatformUI.getWorkbench();
workbench.getDisplay().asyncExec(new Runnable() {
public void run() {
try {
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage page = window.getActivePage();
page.showView("software.aws.toolkits.eclipse.amazonq.views.ToolkitLoginWebview");
PluginStore.put(ViewConstants.PREFERENCE_STORE_PLUGIN_FIRST_STARTUP_KEY, "true");
}
} catch (PartInitException e) {
PluginLogger.warn("Error occurred during auto loading of plugin", e);
}
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ private ViewConstants() {
}

public static final String COMMAND_FUNCTION_NAME = "ideCommand";
public static final String PREFERENCE_STORE_PLUGIN_FIRST_STARTUP_KEY = "qEclipseFirstLoad";
}

0 comments on commit b74d7cf

Please sign in to comment.