#696 - Close the local server terminal on restart

This commit is contained in:
Elio Struyf
2023-10-26 09:14:59 +02:00
parent 7c2a59615f
commit 13f5446163
4 changed files with 65 additions and 42 deletions
+1
View File
@@ -17,6 +17,7 @@
- [#685](https://github.com/estruyf/vscode-front-matter/issues/685): Fix when using non-string values in the tag picker
- [#691](https://github.com/estruyf/vscode-front-matter/issues/691): Silent authentication retrieval for GitHub sponsors
- [#696](https://github.com/estruyf/vscode-front-matter/issues/696): Close the local server terminal on restart
## [9.3.0] - 2023-10-06 - [Release notes](https://beta.frontmatter.codes/updates/v9.3.0)
+4
View File
@@ -36,6 +36,7 @@ import {
Chatbot
} from './commands';
import { join } from 'path';
import { Terminal } from './services';
let pageUpdateDebouncer: { (fnc: any, time: number): void };
let editDebounce: { (fnc: any, time: number): void };
@@ -58,6 +59,9 @@ export async function activate(context: vscode.ExtensionContext) {
});
}
// Make sure the terminal windows are closed
Terminal.closeLocalServerTerminal();
if (!extension.checkIfExtensionCanRun()) {
return undefined;
}
+5 -41
View File
@@ -5,7 +5,7 @@ import { Folders } from '../../commands/Folders';
import { Command } from '../../panelWebView/Command';
import { CommandToCode } from '../../panelWebView/CommandToCode';
import { BaseListener } from './BaseListener';
import { authentication, commands, ThemeIcon, window } from 'vscode';
import { authentication, commands, window } from 'vscode';
import { ArticleHelper, ContentType, Extension, Logger, Settings } from '../../helpers';
import {
COMMAND_NAME,
@@ -23,12 +23,12 @@ import { encodeEmoji } from '../../utils';
import { PanelProvider } from '../../panelWebView/PanelProvider';
import { MessageHandlerData } from '@estruyf/vscode';
import { SponsorAi } from '../../services/SponsorAI';
import { Terminal } from '../../services';
const FILE_LIMIT = 10;
export class DataListener extends BaseListener {
private static lastMetadataUpdate: any = {};
private static readonly terminalName: string = 'Local server';
/**
* Process the messages for the dashboard views
@@ -509,27 +509,7 @@ export class DataListener extends BaseListener {
*/
private static openTerminalWithCommand(command: string) {
if (command) {
let localServerTerminal = DataListener.findServerTerminal();
if (localServerTerminal) {
localServerTerminal.dispose();
}
if (
!localServerTerminal ||
(localServerTerminal && localServerTerminal.state.isInteractedWith === true)
) {
localServerTerminal = window.createTerminal({
name: this.terminalName,
iconPath: new ThemeIcon('server-environment'),
message: `Starting local server`
});
}
if (localServerTerminal) {
localServerTerminal.sendText(command);
localServerTerminal.show(false);
}
Terminal.openLocalServerTerminal(command);
this.sendMsg(Command.serverStarted, true);
}
}
@@ -538,11 +518,7 @@ export class DataListener extends BaseListener {
* Stop the local server
*/
private static stopServer() {
const localServerTerminal = DataListener.findServerTerminal();
if (localServerTerminal) {
localServerTerminal.dispose();
}
Terminal.closeLocalServerTerminal();
this.sendMsg(Command.serverStarted, false);
}
@@ -554,22 +530,10 @@ export class DataListener extends BaseListener {
return;
}
const localServerTerminal = DataListener.findServerTerminal();
const localServerTerminal = Terminal.findLocalServerTerminal();
this.sendRequest(command, requestId, !!localServerTerminal);
}
/**
* Find the server terminal
* @returns
*/
private static findServerTerminal() {
let terminals = window.terminals;
if (terminals) {
const localServerTerminal = terminals.find((t) => t.name === DataListener.terminalName);
return localServerTerminal;
}
}
/**
* Update the placeholder
* @param field
+55 -1
View File
@@ -1,4 +1,4 @@
import { workspace } from 'vscode';
import { workspace, window, ThemeIcon } from 'vscode';
import * as os from 'os';
interface ShellSetting {
@@ -6,6 +6,8 @@ interface ShellSetting {
}
export class Terminal {
public static readonly terminalName: string = 'Local server';
/**
* Return the shell path for the current platform
*/
@@ -22,6 +24,58 @@ export class Terminal {
return shellPath;
}
/**
* Open a new local server terminal
*/
public static openLocalServerTerminal(command: string) {
let localServerTerminal = Terminal.findLocalServerTerminal();
if (localServerTerminal) {
localServerTerminal.dispose();
}
if (!command) {
return;
}
if (
!localServerTerminal ||
(localServerTerminal && localServerTerminal.state.isInteractedWith === true)
) {
localServerTerminal = window.createTerminal({
name: Terminal.terminalName,
iconPath: new ThemeIcon('server-environment'),
message: `Starting local server`
});
}
if (localServerTerminal) {
localServerTerminal.sendText(command);
localServerTerminal.show(false);
}
}
/**
* Close local server terminal
*/
public static closeLocalServerTerminal() {
const localServerTerminal = Terminal.findLocalServerTerminal();
if (localServerTerminal) {
localServerTerminal.dispose();
}
}
/**
* Find the server terminal
* @returns
*/
public static findLocalServerTerminal() {
let terminals = window.terminals;
if (terminals) {
const localServerTerminal = terminals.find((t) => t.name === Terminal.terminalName);
return localServerTerminal;
}
}
/**
* Retrieve the automation profile for the current platform
* @returns