-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
409 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { hasStatusCode } from '../util'; | ||
|
||
/** | ||
* Check if a given server is running by checking if the `irisapi/irisapi.nocache.js` | ||
* file is accessible. | ||
* @param serverUrl | ||
*/ | ||
export async function isDheServerRunning(serverUrl: string): Promise<boolean> { | ||
try { | ||
return await hasStatusCode( | ||
new URL('irisapi/irisapi.nocache.js', serverUrl), | ||
200 | ||
); | ||
} catch { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import * as vscode from 'vscode'; | ||
import { ServerState, WorkerState } from '../common'; | ||
import { IWorkerManager } from './types'; | ||
|
||
/** | ||
* Base class for tree view data providers. | ||
*/ | ||
export abstract class TreeProvider<T> implements vscode.TreeDataProvider<T> { | ||
constructor(readonly workerManager: IWorkerManager) { | ||
workerManager.onDidUpdate(() => { | ||
this._onDidChangeTreeData.fire(); | ||
}); | ||
} | ||
|
||
private _onDidChangeTreeData = new vscode.EventEmitter< | ||
T | undefined | void | ||
>(); | ||
|
||
readonly onDidChangeTreeData = this._onDidChangeTreeData.event; | ||
|
||
abstract getTreeItem(element: T): vscode.TreeItem | Thenable<vscode.TreeItem>; | ||
|
||
abstract getChildren(element?: T | undefined): vscode.ProviderResult<T[]>; | ||
} | ||
|
||
type ServerGroupState = { label: string }; | ||
type ServerNode = ServerGroupState | ServerState; | ||
|
||
function isServerGroupState(node: ServerNode): node is ServerGroupState { | ||
return 'label' in node; | ||
} | ||
|
||
/** | ||
* Provider for the server tree view. | ||
*/ | ||
export class ServerTreeProvider extends TreeProvider<ServerNode> { | ||
getTreeItem( | ||
element: ServerNode | ||
): vscode.TreeItem | Thenable<vscode.TreeItem> { | ||
if (isServerGroupState(element)) { | ||
return { | ||
label: element.label, | ||
iconPath: new vscode.ThemeIcon('server'), | ||
collapsibleState: vscode.TreeItemCollapsibleState.Expanded, | ||
}; | ||
} | ||
|
||
return { | ||
label: new URL(element.url).host, | ||
iconPath: new vscode.ThemeIcon( | ||
element.isRunning === true ? 'circle-large-filled' : 'circle-slash' | ||
), | ||
}; | ||
} | ||
|
||
getChildren(elementOrRoot?: ServerNode): vscode.ProviderResult<ServerNode[]> { | ||
// Root node | ||
if (elementOrRoot == null) { | ||
return [{ label: 'Running' }, { label: 'Stopped' }]; | ||
} | ||
|
||
if (isServerGroupState(elementOrRoot)) { | ||
return this.workerManager | ||
.getServers() | ||
.filter(server => | ||
(elementOrRoot as ServerGroupState).label === 'Running' | ||
? server.isRunning | ||
: !server.isRunning | ||
); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Provider for the worker tree view. | ||
*/ | ||
export class WorkerTreeProvider extends TreeProvider<WorkerState> { | ||
getTreeItem( | ||
element: WorkerState | ||
): vscode.TreeItem | Thenable<vscode.TreeItem> { | ||
return { | ||
label: new URL(element.url).host, | ||
iconPath: new vscode.ThemeIcon('vm-connect'), | ||
}; | ||
} | ||
|
||
getChildren(): vscode.ProviderResult<WorkerState[]> { | ||
return this.workerManager.getWorkers(); | ||
} | ||
} |
Oops, something went wrong.