Skip to content
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

feat(vscode): add status bar items to start, stop and open server #988

Merged
merged 26 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e912420
feat(vscode): application status bar
alestiago Aug 30, 2023
e1d4a49
feat: updates status bar
alestiago Aug 30, 2023
560b061
feat: disposing
alestiago Aug 30, 2023
155a7c3
chore: TODO messages
alestiago Aug 30, 2023
a8f57eb
refactor: sorted analysis
alestiago Aug 30, 2023
83da5b9
Merge branch 'main' into alestiago/vscode-application-status-bar
alestiago Aug 30, 2023
cb8ecce
feat: used dart-frog-stop over color change
alestiago Aug 30, 2023
5b4e706
feat: updated icon set
alestiago Aug 30, 2023
ab907e0
feat: new icon set
alestiago Aug 31, 2023
d854292
refactor: defined DartFrogStatusBarItem
alestiago Aug 31, 2023
dd4f189
fix: starting up
alestiago Aug 31, 2023
169beeb
Merge branch 'main' into alestiago/vscode-application-status-bar
alestiago Aug 31, 2023
88ced3e
test: created test files
alestiago Sep 1, 2023
06989d5
chore: updated index.ts
alestiago Sep 1, 2023
5b80c37
test: tested OpenApplicationStatusBarItem
alestiago Sep 1, 2023
72b4f7b
test: StartStopApplicationStatusBarItem
alestiago Sep 1, 2023
46846ba
test: added even more tests
alestiago Sep 1, 2023
a5356b4
refactor: removed console logs
alestiago Sep 1, 2023
c17cd34
Merge branch 'main' into alestiago/vscode-application-status-bar
alestiago Sep 1, 2023
fe30700
chore: resolved warnings
alestiago Sep 1, 2023
f1ee824
fix: remove random import
alestiago Sep 1, 2023
d60f34b
test: OpenApplicationStatusBarItem.dispose
alestiago Sep 1, 2023
86d4f0e
test: StartStopApplicationStatusBarItem.dispose
alestiago Sep 1, 2023
885540e
refactor: used Uri
alestiago Sep 1, 2023
d00273f
refactor: made update abstract
alestiago Sep 1, 2023
30bfda4
refactor: marked as readonly
alestiago Sep 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added extensions/vscode/assets/dart-frog.woff
Binary file not shown.
30 changes: 30 additions & 0 deletions extensions/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,36 @@
}
]
},
"icons": {
"dart-frog": {
"description": "Dart Frog logo",
"default": {
"fontPath": "./assets/dart-frog.woff",
"fontCharacter": "\\e900"
}
},
"dart-frog-start": {
"description": "Dart Frog logo with a start sign",
"default": {
"fontPath": "./assets/dart-frog.woff",
"fontCharacter": "\\e901"
}
},
"dart-frog-stop": {
"description": "Dart Frog logo with a stop sign",
"default": {
"fontPath": "./assets/dart-frog.woff",
"fontCharacter": "\\e902"
}
},
"dart-frog-globe": {
"description": "Dart Frog logo with a globe sign",
"default": {
"fontPath": "./assets/dart-frog.woff",
"fontCharacter": "\\e903"
}
}
},
"configuration": {
"properties": {
"dart-frog.enableCodeLens": {
Expand Down
9 changes: 8 additions & 1 deletion extensions/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import {
DebugOnRequestCodeLensProvider,
RunOnRequestCodeLensProvider,
} from "./code-lens";
import {
OpenApplicationStatusBarItem,
StartStopApplicationStatusBarItem,
} from "./status-bar";
import {
create,
debugDevServer,
Expand Down Expand Up @@ -73,8 +77,11 @@ export function activate(
vscode.commands.registerCommand(
"dart-frog.start-debug-dev-server",
startDebugDevServer
)
),
new StartStopApplicationStatusBarItem(),
new OpenApplicationStatusBarItem()
);

return context;
}

Expand Down
51 changes: 51 additions & 0 deletions extensions/vscode/src/status-bar/dart-frog-status-bar-item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {
Disposable,
StatusBarAlignment,
StatusBarItem,
window,
workspace,
} from "vscode";
import { resolveDartFrogProjectPathFromWorkspace } from "../utils";

/**
* Wraps a status bar item so that is only visible when the current workspace
* is a Dart Frog project.
*
* Should be used as a base class for other status bar items.
*
* @see {@link StatusBarItem}, for more information on status bar items.
*/
export abstract class DartFrogStatusBarItem implements Disposable {
public readonly statusBarItem: StatusBarItem;

private onDidChangeWorkspaceFoldersDisposable: Disposable;
private onDidChangeActiveTextEditorDisposable: Disposable;

constructor(alignment: StatusBarAlignment, priority: number) {
this.statusBarItem = window.createStatusBarItem(alignment, priority);

this.onDidChangeWorkspaceFoldersDisposable =
workspace.onDidChangeWorkspaceFolders(this.onChangeSetup.bind(this));
this.onDidChangeActiveTextEditorDisposable =
window.onDidChangeActiveTextEditor(this.onChangeSetup.bind(this));

this.onChangeSetup();
}

public abstract update(): any;

private onChangeSetup(): void {
const isDartFrogProject = resolveDartFrogProjectPathFromWorkspace();
if (isDartFrogProject) {
this.update();
} else {
this.statusBarItem.hide();
}
}

public dispose(): void {
this.onDidChangeWorkspaceFoldersDisposable.dispose();
this.onDidChangeActiveTextEditorDisposable.dispose();
this.statusBarItem.dispose();
}
}
3 changes: 3 additions & 0 deletions extensions/vscode/src/status-bar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./dart-frog-status-bar-item";
export * from "./open-application-status-bar-item";
export * from "./start-stop-application-status-bar-item";
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Command, StatusBarAlignment, Uri } from "vscode";
import {
DartFrogApplicationRegistryEventEmitterTypes,
DartFrogDaemon,
} from "../daemon";
import { DartFrogStatusBarItem } from "./dart-frog-status-bar-item";

export class OpenApplicationStatusBarItem extends DartFrogStatusBarItem {
private updateFunction: () => void;

constructor() {
super(StatusBarAlignment.Right, 10);

this.updateFunction = this.update.bind(this);

const daemon = DartFrogDaemon.instance;
daemon.applicationRegistry.on(
DartFrogApplicationRegistryEventEmitterTypes.add,
this.updateFunction
);
daemon.applicationRegistry.on(
DartFrogApplicationRegistryEventEmitterTypes.remove,
this.updateFunction
);
}

public update(): void {
const daemon = DartFrogDaemon.instance;
const applications = daemon.applicationRegistry.all();
if (applications.length === 0) {
this.statusBarItem.hide();
return;
}

const application = applications[0];
this.statusBarItem.text = `$(dart-frog-globe) localhost:${application.port}`;
this.statusBarItem.tooltip = "Open application in browser";
const openCommand: Command = {
title: "Open application in browser",
command: "vscode.open",
arguments: [Uri.parse(application.address!)],
};
this.statusBarItem.command = openCommand;
this.statusBarItem.show();
}

public dispose(): void {
const daemon = DartFrogDaemon.instance;
daemon.applicationRegistry.off(
DartFrogApplicationRegistryEventEmitterTypes.add,
this.updateFunction
);
daemon.applicationRegistry.off(
DartFrogApplicationRegistryEventEmitterTypes.remove,
this.updateFunction
);
super.dispose();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {
DartFrogApplicationRegistryEventEmitterTypes,
DartFrogDaemon,
} from "../daemon";
import { DartFrogStatusBarItem } from "./dart-frog-status-bar-item";
import { StatusBarAlignment } from "vscode";

export class StartStopApplicationStatusBarItem extends DartFrogStatusBarItem {
private updateFunction: () => void;

constructor() {
super(StatusBarAlignment.Left, 10);

this.updateFunction = this.update.bind(this);

const daemon = DartFrogDaemon.instance;
daemon.applicationRegistry.on(
DartFrogApplicationRegistryEventEmitterTypes.add,
this.updateFunction
);
daemon.applicationRegistry.on(
DartFrogApplicationRegistryEventEmitterTypes.remove,
this.updateFunction
);
}

public update(): void {
const daemon = DartFrogDaemon.instance;
const applications = daemon.applicationRegistry.all();

if (applications.length === 0) {
this.statusBarItem.text = "$(dart-frog-start) Start Server";
this.statusBarItem.tooltip = "Start development server";
this.statusBarItem.command = "dart-frog.start-debug-dev-server";
} else {
this.statusBarItem.text = "$(dart-frog-stop) Stop Server";
this.statusBarItem.tooltip = "Stop development server";
this.statusBarItem.command = "dart-frog.stop-dev-server";
}

this.statusBarItem.show();
}

dispose() {
const daemon = DartFrogDaemon.instance;
daemon.applicationRegistry.off(
DartFrogApplicationRegistryEventEmitterTypes.add,
this.updateFunction
);
daemon.applicationRegistry.off(
DartFrogApplicationRegistryEventEmitterTypes.remove,
this.updateFunction
);
super.dispose();
}
}