Skip to content

Commit

Permalink
Add useLatest configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mustard-mh committed Apr 25, 2022
1 parent 0827ab8 commit afcf34a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ export interface Config {
gitpodURL: string;
openAsPopup: boolean;
rewritePeriodKeybind: boolean;
useLatest: boolean;
}

export const DEFAULT_CONFIG: Config = {
gitpodURL: "https://gitpod.io",
openAsPopup: false,
rewritePeriodKeybind: false
rewritePeriodKeybind: false,
useLatest: false,
};

export interface ConfigListener {
Expand Down
2 changes: 1 addition & 1 deletion src/injectors/bitbucket-injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ abstract class ButtonInjectorBase implements ButtonInjector {

abstract isApplicableToCurrentPage(): boolean;

inject(urlInfo: UrlInfo, openAsPopup: boolean) {
inject(urlInfo: UrlInfo, openAsPopup: boolean, useLatest: boolean) {
let actionbar = select(this.parent);
if (actionbar && this.up) {
for (let i = 0; i < this.up; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/injectors/github-injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ abstract class ButtonInjectorBase implements ButtonInjector {
// do nothing
}

inject(urlInfo: UrlInfo, openAsPopup: boolean) {
inject(urlInfo: UrlInfo, openAsPopup: boolean, useLatest: boolean) {
const actionbar = select(this.parentSelector);
if (!actionbar) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/injectors/gitlab-injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class RepositoryInjector implements ButtonInjector {
return result;
}

inject(urlInfo: UrlInfo, openAsPopup: boolean) {
inject(urlInfo: UrlInfo, openAsPopup: boolean, useLatest: boolean) {
const parent = select(RepositoryInjector.PARENT_SELECTOR);
if (!parent || !parent.firstElementChild) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/injectors/injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface ButtonInjector {
* Injects the actual button
* @param currentUrl The currently configured Gitpod URL
*/
inject(urlInfo: UrlInfo, openAsPopup: boolean): void;
inject(urlInfo: UrlInfo, openAsPopup: boolean, useLatest: boolean): void;
}

export abstract class InjectorBase implements Injector {
Expand All @@ -55,7 +55,7 @@ export abstract class InjectorBase implements Injector {
const urlInfo = renderGitpodUrl(this.config.gitpodURL);
for (const injector of this.buttonInjectors) {
if (injector.isApplicableToCurrentPage()) {
injector.inject(urlInfo, this.config.openAsPopup);
injector.inject(urlInfo, this.config.openAsPopup, this.config.useLatest);
if (singleInjector) {
break;
}
Expand Down
9 changes: 8 additions & 1 deletion src/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="options.css"/>
<link rel="stylesheet" href="./options.css"/>
</head>
<body>
<div id="content">
<div class="row">
<label>Gitpod installation URL:</label>
<input id="gitpod-url-input" type="url" value=""/>
</div>
<div class="row">
<label for="use-latest">
Latest Release (Unstable)
<div class="label-desc">Use the latest version for each editor. <a class="gp-link" target="_blank" href="https://code.visualstudio.com/blogs/2016/02/01/introducing_insiders_build">Insiders</a> for VS Code, <a class="gp-link" target="_blank" href="https://www.jetbrains.com/resources/eap/">EAP</a> for JetBrains IDEs.</div>
</label>
<input id="use-latest" type="checkbox"/>
</div>
<div class="row">
<label>Open as popup:</label>
<input id="gitpod-open-as-popup" type="checkbox"/>
Expand Down
5 changes: 4 additions & 1 deletion src/options/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ConfigProvider } from "../config";
const gitpodUrlInput = document.getElementById("gitpod-url-input")! as HTMLInputElement;
const gitpodRewriteKeybind = document.getElementById("gitpod-replace-keybind")! as HTMLInputElement;
const gitpodPopupInput = document.getElementById("gitpod-open-as-popup")! as HTMLInputElement;
const useLatestCheckbox = document.getElementById("use-latest")! as HTMLInputElement;
const messageElement = document.getElementById("message")! as HTMLDivElement;


Expand All @@ -12,6 +13,7 @@ const init = async () => {
// Initialize UI
const initialConfig = configProvider.getConfig();
gitpodUrlInput.value = initialConfig.gitpodURL;
useLatestCheckbox.checked = initialConfig.useLatest;
gitpodPopupInput.checked = initialConfig.openAsPopup;
gitpodRewriteKeybind.checked = initialConfig.rewritePeriodKeybind;

Expand All @@ -22,6 +24,7 @@ const init = async () => {
// Update config (propagated internally)
configProvider.setConfig({
gitpodURL: gitpodUrlInput.value || undefined,
useLatest: useLatestCheckbox.checked,
openAsPopup: gitpodPopupInput.checked,
rewritePeriodKeybind: gitpodRewriteKeybind.checked
});
Expand All @@ -38,7 +41,7 @@ const init = async () => {
}
save()
});
[gitpodPopupInput, gitpodRewriteKeybind].forEach((el) => el.addEventListener('change', save))
[useLatestCheckbox, gitpodPopupInput, gitpodRewriteKeybind].forEach((el) => el.addEventListener('change', save))
};

init().catch(err => console.error(err));

0 comments on commit afcf34a

Please sign in to comment.