|
|
@ -5,14 +5,20 @@ import * as vscode from 'vscode';
|
|
|
|
import { deleteConfig, loadConfigsRaw, updateConfig } from './config';
|
|
|
|
import { deleteConfig, loadConfigsRaw, updateConfig } from './config';
|
|
|
|
import { getLocations } from './fileSystemConfig';
|
|
|
|
import { getLocations } from './fileSystemConfig';
|
|
|
|
import { toPromise } from './toPromise';
|
|
|
|
import { toPromise } from './toPromise';
|
|
|
|
import { Message } from './webviewMessages';
|
|
|
|
import { Message, Navigation } from './webviewMessages';
|
|
|
|
|
|
|
|
|
|
|
|
let webviewPanel: vscode.WebviewPanel | undefined;
|
|
|
|
let webviewPanel: vscode.WebviewPanel | undefined;
|
|
|
|
|
|
|
|
let pendingNavigation: Navigation | undefined;
|
|
|
|
|
|
|
|
|
|
|
|
// Since the Extension Development Host runs with debugger, we can use this to detect if we're debugging
|
|
|
|
// Since the Extension Development Host runs with debugger, we can use this to detect if we're debugging
|
|
|
|
const DEBUG: number | undefined = process.execArgv.find(a => a.includes('--inspect')) ? 3000 : undefined;
|
|
|
|
const DEBUG: number | undefined = process.execArgv.find(a => a.includes('--inspect')) ? 3000 : undefined;
|
|
|
|
if (DEBUG) console.warn('[vscode-sshfs] Detected we are running in debug mode');
|
|
|
|
if (DEBUG) console.warn('[vscode-sshfs] Detected we are running in debug mode');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getExtensionPath(): string | undefined {
|
|
|
|
|
|
|
|
const ext = vscode.extensions.getExtension('Kelvin.vscode-sshfs');
|
|
|
|
|
|
|
|
return ext && ext.extensionPath;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function getDebugContent(): Promise<string | false> {
|
|
|
|
async function getDebugContent(): Promise<string | false> {
|
|
|
|
if (!DEBUG) return false;
|
|
|
|
if (!DEBUG) return false;
|
|
|
|
const URL = `http://localhost:${DEBUG}/`;
|
|
|
|
const URL = `http://localhost:${DEBUG}/`;
|
|
|
@ -25,13 +31,15 @@ async function getDebugContent(): Promise<string | false> {
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export async function open(extensionPath: string) {
|
|
|
|
export async function open() {
|
|
|
|
if (!webviewPanel) {
|
|
|
|
if (!webviewPanel) {
|
|
|
|
webviewPanel = vscode.window.createWebviewPanel('sshfs-settings', 'SSH-FS Settings', vscode.ViewColumn.One, { enableFindWidget: true, enableScripts: true });
|
|
|
|
webviewPanel = vscode.window.createWebviewPanel('sshfs-settings', 'SSH-FS Settings', vscode.ViewColumn.One, { enableFindWidget: true, enableScripts: true });
|
|
|
|
webviewPanel.onDidDispose(() => webviewPanel = undefined);
|
|
|
|
webviewPanel.onDidDispose(() => webviewPanel = undefined);
|
|
|
|
webviewPanel.webview.onDidReceiveMessage(handleMessage);
|
|
|
|
webviewPanel.webview.onDidReceiveMessage(handleMessage);
|
|
|
|
let content = await getDebugContent().catch((e: Error) => (vscode.window.showErrorMessage(e.message), null));
|
|
|
|
let content = await getDebugContent().catch((e: Error) => (vscode.window.showErrorMessage(e.message), null));
|
|
|
|
if (!content) {
|
|
|
|
if (!content) {
|
|
|
|
|
|
|
|
const extensionPath = getExtensionPath();
|
|
|
|
|
|
|
|
if (!extensionPath) throw new Error('Could not get extensionPath');
|
|
|
|
// If we got here, we're either not in debug mode, or something went wrong (and an error message is shown)
|
|
|
|
// If we got here, we're either not in debug mode, or something went wrong (and an error message is shown)
|
|
|
|
content = fs.readFileSync(path.resolve(extensionPath, 'webview/build/index.html')).toString();
|
|
|
|
content = fs.readFileSync(path.resolve(extensionPath, 'webview/build/index.html')).toString();
|
|
|
|
// Built index.html has e.g. `href="/static/js/stuff.js"`, need to make it use vscode-resource: and point to the built static directory
|
|
|
|
// Built index.html has e.g. `href="/static/js/stuff.js"`, need to make it use vscode-resource: and point to the built static directory
|
|
|
@ -42,13 +50,27 @@ export async function open(extensionPath: string) {
|
|
|
|
webviewPanel.reveal();
|
|
|
|
webviewPanel.reveal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function postMessage(message: Message) {
|
|
|
|
export async function navigate(navigation: Navigation) {
|
|
|
|
|
|
|
|
pendingNavigation = navigation;
|
|
|
|
|
|
|
|
postMessage({ navigation, type: 'navigate' });
|
|
|
|
|
|
|
|
return open();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function postMessage<T extends Message>(message: T) {
|
|
|
|
if (!webviewPanel) return;
|
|
|
|
if (!webviewPanel) return;
|
|
|
|
webviewPanel.webview.postMessage(message);
|
|
|
|
webviewPanel.webview.postMessage(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function handleMessage(message: Message): Promise<any> {
|
|
|
|
async function handleMessage(message: Message): Promise<any> {
|
|
|
|
console.log('Got message:', message);
|
|
|
|
console.log('Got message:', message);
|
|
|
|
|
|
|
|
if (message.type === 'navigated') pendingNavigation = undefined;
|
|
|
|
|
|
|
|
if (pendingNavigation) {
|
|
|
|
|
|
|
|
postMessage({
|
|
|
|
|
|
|
|
type: 'navigate',
|
|
|
|
|
|
|
|
navigation: pendingNavigation,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
pendingNavigation = undefined;
|
|
|
|
|
|
|
|
}
|
|
|
|
switch (message.type) {
|
|
|
|
switch (message.type) {
|
|
|
|
case 'requestData': {
|
|
|
|
case 'requestData': {
|
|
|
|
const configs = await loadConfigsRaw();
|
|
|
|
const configs = await loadConfigsRaw();
|
|
|
|