Skip to content

Commit

Permalink
fix: update the UI of activity
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenngoclongdev authored Oct 3, 2024
1 parent 218eec8 commit a3a4372
Show file tree
Hide file tree
Showing 20 changed files with 403 additions and 471 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-vans-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"terminal-keeper": patch
---

update the UI of activity
55 changes: 29 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,15 @@
},
"viewsWelcome": [
{
"view": "terminalKeeperOverviewView",
"view": "terminalKeeperActivityView",
"contents": "Welcome to Terminal Keeper.\nLet's start by generating the configuration.\n[Generate Configuration](command:terminal-keeper.generate)\nTo learn more about how to manage the terminal session [read our docs!](https://github.com/nguyenngoclongdev/vs-terminal-keeper/)"
},
{
"view": "terminalKeeperSessionView",
"contents": "No sessions created yet."
}
],
"views": {
"terminalKeeperActivitybar": [
{
"id": "terminalKeeperOverviewView",
"name": "Overview"
},
{
"id": "terminalKeeperSessionView",
"name": "Sessions"
"id": "terminalKeeperActivityView",
"name": ""
}
]
},
Expand Down Expand Up @@ -138,14 +130,10 @@
"title": "Remove Terminal Session"
},
{
"command": "terminal-keeper.refresh",
"title": "Refresh",
"command": "terminal-keeper.refresh-activity",
"title": "Refresh Activity",
"icon": "$(refresh)"
},
{
"command": "terminal-keeper.refresh-command-activity",
"title": "Refresh Command"
},
{
"command": "terminal-keeper.active-session-activity",
"title": "Active Session",
Expand All @@ -155,40 +143,55 @@
"command": "terminal-keeper.active-terminal-activity",
"title": "Active Terminal",
"icon": "$(run)"
},
{
"command": "terminal-keeper.copy-command-activity",
"title": "Copy Commands"
}
],
"menus": {
"view/title": [
{
"command": "terminal-keeper.active",
"when": "view == terminalKeeperOverviewView",
"when": "view == terminalKeeperActivityView",
"group": "navigation@1"
},
{
"command": "terminal-keeper.active",
"when": "view == terminalKeeperActivityView"
},
{
"command": "terminal-keeper.open",
"when": "view == terminalKeeperOverviewView",
"group": "navigation@2"
"when": "view == terminalKeeperActivityView"
},
{
"command": "terminal-keeper.refresh",
"when": "view == terminalKeeperOverviewView",
"group": "navigation@3"
"command": "terminal-keeper.refresh-activity",
"when": "view == terminalKeeperActivityView"
},
{
"command": "terminal-keeper.remove",
"when": "view == terminalKeeperActivityView"
},
{
"command": "terminal-keeper.kill-all",
"when": "view == terminalKeeperOverviewView"
"when": "view == terminalKeeperActivityView"
}
],
"view/item/context": [
{
"command": "terminal-keeper.active-session-activity",
"when": "view == terminalKeeperSessionView && viewItem == session-context",
"when": "viewItem == session-context",
"group": "inline@1"
},
{
"command": "terminal-keeper.active-terminal-activity",
"when": "view == terminalKeeperSessionView && (viewItem == terminal-context || viewItem == terminal-array-context)",
"when": "viewItem == terminal-array-context || viewItem == terminal-context",
"group": "inline@1"
},
{
"command": "terminal-keeper.copy-command-activity",
"when": "viewItem == terminal-context",
"group": "terminal@1"
}
],
"explorer/context": [
Expand Down
21 changes: 12 additions & 9 deletions src/commands/activeAsync.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import { TerminalApi, ThemeService } from '@vscode-utility/terminal-browserify';
import { ProgressLocation, QuickPickItem, window } from 'vscode';
import { Configuration } from '../configuration/configuration';
import { constants } from '../utils/constants';
import { updateStatusBar } from '../utils/show-status-bar';
import { TerminalApi, ThemeService } from '@vscode-utility/terminal-browserify';
import { getSessionQuickPickItems, showErrorMessageWithDetail, showGenerateConfiguration } from '../utils/utils';
import {
getSessionQuickPickItems,
killAllTerminal,
showErrorMessageWithDetail,
showGenerateConfiguration
} from '../utils/utils';

export const activeAsync = async (workspacePath: string | undefined): Promise<void> => {
try {
// Read the config
const configInstance = Configuration.instance();
const isDefinedSessionFile = await configInstance.isDefinedSessionFile();
const isDefinedSessionFile = await Configuration.isDefinedSessionFile();
if (!isDefinedSessionFile) {
await showGenerateConfiguration();
return;
}

// Check the size of sessions
const config = await configInstance.load();
const config = await Configuration.load();
const { keepExistingTerminals = false, sessions, theme = 'default', noClear = false, active = '' } = config;
if (!sessions) {
window.showWarningMessage(constants.notExistAnySessions);
Expand Down Expand Up @@ -58,7 +62,7 @@ export const activeAsync = async (workspacePath: string | undefined): Promise<vo
}

// Kill previous terminal and create new terminal from session
const { createTerminal, focusTerminal, getCwdPath, killAllTerminalAsync } = TerminalApi.instance();
const { createTerminal, focusTerminal, getCwdPath } = TerminalApi.instance();
window.withProgress(
{
location: ProgressLocation.Window,
Expand All @@ -71,8 +75,7 @@ export const activeAsync = async (workspacePath: string | undefined): Promise<vo
progress.report({ message: 'Killing previous terminals...' });

// Kill all existing terminal in parallel
const isKillProcess = configInstance.getExperimentalConfig<boolean>('killProcess');
await killAllTerminalAsync(isKillProcess);
await killAllTerminal();
}

// Validate data need use async function
Expand Down Expand Up @@ -123,7 +126,7 @@ export const activeAsync = async (workspacePath: string | undefined): Promise<vo

// Save active terminal to configuration
progress.report({ message: 'Waiting for the terminal session to render completely...' });
await configInstance.save({ active: selectedSessionKey });
await Configuration.save({ active: selectedSessionKey });

// Return a value when the task completes
return 'Initialization of the terminal session completed!';
Expand Down
16 changes: 7 additions & 9 deletions src/commands/activeBySessionAsync.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import { TerminalApi, ThemeService } from '@vscode-utility/terminal-browserify';
import { ProgressLocation, window } from 'vscode';
import { Configuration } from '../configuration/configuration';
import { constants } from '../utils/constants';
import { updateStatusBar } from '../utils/show-status-bar';
import { TerminalApi, ThemeService } from '@vscode-utility/terminal-browserify';
import { showErrorMessageWithDetail, showGenerateConfiguration } from '../utils/utils';
import { killAllTerminal, showErrorMessageWithDetail, showGenerateConfiguration } from '../utils/utils';

export const activeBySessionAsync = async (
activeSession: string | undefined,
isSaveActiveSession?: boolean
): Promise<void> => {
try {
// Read the config
const configInstance = Configuration.instance();
const isDefinedSessionFile = await configInstance.isDefinedSessionFile();
const isDefinedSessionFile = await Configuration.isDefinedSessionFile();
if (!isDefinedSessionFile) {
await showGenerateConfiguration();
return;
}

// Check the size of sessions
const config = await configInstance.load();
const config = await Configuration.load();
const { keepExistingTerminals = false, sessions, theme = 'default', noClear = false } = config;
if (!sessions) {
window.showWarningMessage(constants.notExistAnySessions);
Expand All @@ -40,7 +39,7 @@ export const activeBySessionAsync = async (
}

// Kill previous terminal and create new terminal from session
const { createTerminal, focusTerminal, getCwdPath, killAllTerminalAsync } = TerminalApi.instance();
const { createTerminal, focusTerminal, getCwdPath } = TerminalApi.instance();
await window.withProgress(
{
location: ProgressLocation.Window,
Expand All @@ -53,8 +52,7 @@ export const activeBySessionAsync = async (
progress.report({ message: 'Killing previous terminals...' });

// Kill all existing terminal in parallel
const isKillProcess = configInstance.getExperimentalConfig<boolean>('killProcess');
await killAllTerminalAsync(isKillProcess);
await killAllTerminal();
}

// Validate data need use async function
Expand Down Expand Up @@ -103,7 +101,7 @@ export const activeBySessionAsync = async (
// Save active terminal to configuration
progress.report({ message: 'Waiting for the terminal session to render completely...' });
if (isSaveActiveSession) {
await configInstance.save({ active: activeSession });
await Configuration.save({ active: activeSession });
}

// Return a value when the task completes
Expand Down
3 changes: 1 addition & 2 deletions src/commands/activeByTerminalAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export const activeByTerminalAsync = async (

// Read the config
const { createTerminal, getCwdPath } = TerminalApi.instance();
const configInstance = Configuration.instance();
const config = await configInstance.load();
const config = await Configuration.load();
const { theme = 'default', noClear = false } = config;
const themeService = new ThemeService(theme);

Expand Down
9 changes: 4 additions & 5 deletions src/commands/generateAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,27 @@ export const generateAsync = async (): Promise<void> => {
}

// Write configuration file
const configInstance = Configuration.instance();
const isDefinedSessionFile = await configInstance.isDefinedSessionFile();
const isDefinedSessionFile = await Configuration.isDefinedSessionFile();
if (isDefinedSessionFile) {
window.showWarningMessage(constants.configurationFileAlreadyExist);
return;
}

// Generate configuration file
await configInstance.save(configurationTemplate);
await Configuration.save(configurationTemplate);

// Show message
window
.showInformationMessage(constants.generateConfigurationSuccess, constants.viewConfigurationButton)
.then((selection) => {
if (selection === constants.viewConfigurationButton) {
// Open the terminal session configuration
showTextDocument(configInstance.sessionFilePath);
showTextDocument(Configuration.sessionFilePath);
}
});

// Open the terminal session configuration
showTextDocument(configInstance.sessionFilePath);
showTextDocument(Configuration.sessionFilePath);
} catch (error) {
showErrorMessageWithDetail(constants.generateConfigurationFailed, error);
}
Expand Down
6 changes: 2 additions & 4 deletions src/commands/killAllAsync.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { ProgressLocation, window } from 'vscode';
import { constants } from '../utils/constants';
import { TerminalApi } from '@vscode-utility/terminal-browserify';
import { showErrorMessageWithDetail } from '../utils/utils';
import { killAllTerminal, showErrorMessageWithDetail } from '../utils/utils';

export const killAllAsync = async (): Promise<void> => {
try {
// Kill previous terminal and create new terminal from session
const { killAllTerminalAsync } = TerminalApi.instance();
window.withProgress(
{
location: ProgressLocation.Window,
Expand All @@ -18,7 +16,7 @@ export const killAllAsync = async (): Promise<void> => {
progress.report({ message: 'Kill all terminals...' });

// Kill all existing terminal in parallel
await killAllTerminalAsync(true);
await killAllTerminal();

// Return a value when the task completes
return 'Kill all of the terminal completed!';
Expand Down
7 changes: 3 additions & 4 deletions src/commands/migrateAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import { showErrorMessageWithDetail } from '../utils/utils';
export const migrateAsync = async (): Promise<void> => {
try {
// Write configuration file
const configInstance = Configuration.instance();
const isDefinedSessionFile = await configInstance.isDefinedSessionFile();
const isDefinedSessionFile = await Configuration.isDefinedSessionFile();
if (!isDefinedSessionFile) {
return;
}

// Get content file
const currentConfiguration = await configInstance.load();
const currentConfiguration = await Configuration.load();
if (!currentConfiguration) {
return;
}
Expand Down Expand Up @@ -59,7 +58,7 @@ export const migrateAsync = async (): Promise<void> => {
migrateConfiguration.$schema = latestSchema;

// Write new session configuration to file
await configInstance.save(migrateConfiguration);
await Configuration.save(migrateConfiguration);
} catch (error) {
showErrorMessageWithDetail(constants.migrateConfigurationFailed, error);
}
Expand Down
5 changes: 2 additions & 3 deletions src/commands/openAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ import {
export const openAsync = async (): Promise<void> => {
try {
// Write configuration file
const configInstance = Configuration.instance();
const isDefinedSessionFile = await configInstance.isDefinedSessionFile();
const isDefinedSessionFile = await Configuration.isDefinedSessionFile();
if (!isDefinedSessionFile) {
await showGenerateConfiguration();
return;
}

// Open the terminal session configuration
showTextDocument(configInstance.sessionFilePath);
showTextDocument(Configuration.sessionFilePath);
} catch (error) {
showErrorMessageWithDetail(constants.openConfigurationFailed, error);
}
Expand Down
9 changes: 4 additions & 5 deletions src/commands/removeAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import { getSessionQuickPickItems, showErrorMessageWithDetail, showTextDocument

export const removeAsync = async (): Promise<void> => {
try {
const configInstance = Configuration.instance();
const isDefinedSessionFile = await configInstance.isDefinedSessionFile();
const isDefinedSessionFile = await Configuration.isDefinedSessionFile();
if (!isDefinedSessionFile) {
window.showWarningMessage(constants.notExistConfiguration);
return;
}

const config = await configInstance.load();
const config = await Configuration.load();
if (!config) {
window.showWarningMessage(constants.notExistConfiguration);
return;
Expand Down Expand Up @@ -65,15 +64,15 @@ export const removeAsync = async (): Promise<void> => {
}

// Write new session configuration to file
await configInstance.save(newestConfiguration);
await Configuration.save(newestConfiguration);

// Show message
window
.showInformationMessage(constants.removeSessionSuccess, constants.viewConfigurationButton)
.then((selection) => {
if (selection === constants.viewConfigurationButton) {
// Open the terminal session configuration
showTextDocument(configInstance.sessionFilePath);
showTextDocument(Configuration.sessionFilePath);
}
});
} catch (error) {
Expand Down
Loading

0 comments on commit a3a4372

Please sign in to comment.