From 4bceac900c179e3d04a6600fb5e53e4051f87eec Mon Sep 17 00:00:00 2001 From: sefatanam Date: Tue, 16 Jul 2024 01:11:41 +0600 Subject: [PATCH 1/5] fix: no project found typo --- src/lib/views.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/views.ts b/src/lib/views.ts index daa761a..26e4194 100644 --- a/src/lib/views.ts +++ b/src/lib/views.ts @@ -24,7 +24,7 @@ export const getWebviewContent = (projects: RecentProject[], context: ExtensionC export const makeProjectCards = (projects: RecentProject[]): string => { if (projects.length <= 0) { - return `

No Project found

`; + return `

No Project found.

`; } const cardsHTML = projects.map(project => ` From c28a23f0fdfb37df22ef57cd1c2b034e2e452d67 Mon Sep 17 00:00:00 2001 From: sefatanam Date: Tue, 16 Jul 2024 01:12:20 +0600 Subject: [PATCH 2/5] feat: add singleton class to store window reference --- src/lib/state.ts | 19 +++++++++++++++++++ src/lib/store.ts | 16 ++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/lib/state.ts create mode 100644 src/lib/store.ts diff --git a/src/lib/state.ts b/src/lib/state.ts new file mode 100644 index 0000000..e0be4f5 --- /dev/null +++ b/src/lib/state.ts @@ -0,0 +1,19 @@ +import * as vscode from 'vscode'; +export class State { + #data: { [key: string]: any } = {}; + constructor() { + if (State.instance) { + vscode.window.showErrorMessage(`Pretty Home instance already running.`); + } + } + get data() { + return this.#data; + } + static instance: State; + static { + this.instance = new State(); + } + static getInstance() { + return this.instance; + } +} \ No newline at end of file diff --git a/src/lib/store.ts b/src/lib/store.ts new file mode 100644 index 0000000..48771fb --- /dev/null +++ b/src/lib/store.ts @@ -0,0 +1,16 @@ +import * as vscode from 'vscode'; +import { APP } from "./constant"; +import { State } from "./state"; + +export function setWebviewReference(webviewPanel: vscode.WebviewPanel, state: State) { + state.data[APP.WEB_VIEW_REF] = webviewPanel; +} + +export function getWebviewReference(state: State): boolean { + try { + const windowRef: vscode.WebviewPanel = state.data[APP.WEB_VIEW_REF]; + return windowRef.visible; + } catch (_) { + return false; + } +} \ No newline at end of file From 1fe9d75e8f640900f0a697b718e0729f12fa389d Mon Sep 17 00:00:00 2001 From: sefatanam Date: Tue, 16 Jul 2024 01:15:20 +0600 Subject: [PATCH 3/5] feat: open pretty home by default and add configuration --- src/extension.ts | 25 ++++++++++++++++++++++--- src/lib/command.ts | 41 ++++++++++++++++++++++++++++++++++++----- src/lib/constant.ts | 3 ++- src/lib/engine.ts | 19 +++++++++++++++++++ src/lib/index.ts | 2 ++ 5 files changed, 81 insertions(+), 9 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 152e163..31e6707 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,11 +1,30 @@ import * as vscode from "vscode"; -import { showPrettyHomeCommand } from "./lib"; - +import { getWebviewReference, openProjectInGithub, showPrettyHomeCommand, showPrettyHomeSettingsCommand } from "./lib"; +import { State } from "./lib/state"; +const state = State.getInstance(); // This method is called when your extension is activated // Your extension is activated the very first time the command is executed export async function activate(context: vscode.ExtensionContext) { - showPrettyHomeCommand(context); + + await showPrettyHomeCommand(context, state); + await showPrettyHomeSettingsCommand(context); + await openProjectInGithub(context,state); + + // Open the webview by default when VS Code starts and no folder/workspace is loaded + vscode.window.onDidChangeWindowState((e) => { + try { + if (getWebviewReference(state)) {return;} + const config = vscode.workspace.getConfiguration('prettyHome'); + const showOnStartup = config.get('showOnStartup', false); + const shouldOpenPrettyHome = e.active && !vscode.workspace.workspaceFolders && showOnStartup; + if (shouldOpenPrettyHome) { + vscode.commands.executeCommand('extension.prettyHome'); + } + } catch (err: any) { + vscode.window.showErrorMessage("Something went wront to load by default."); + } + }); } // This method is called when your extension is deactivated diff --git a/src/lib/command.ts b/src/lib/command.ts index 1af98a6..b5b9a26 100644 --- a/src/lib/command.ts +++ b/src/lib/command.ts @@ -1,19 +1,26 @@ import path from 'path'; import * as vscode from 'vscode'; import { APP, COMMAND } from "./constant"; -import { gerRecentProjects, openProject } from "./engine"; +import { gerRecentProjects, openProject, showSettingsDialog } from "./engine"; +import { State } from "./state"; +import { getWebviewReference, setWebviewReference } from "./store"; import { RecentProject } from "./types"; import { getWebviewContent, makeProjectCards } from "./views"; -export async function showPrettyHomeCommand(context: vscode.ExtensionContext) { +export async function showPrettyHomeCommand(context: vscode.ExtensionContext, state: State) { const disposable = vscode.commands.registerCommand( "extension.prettyHome", async () => { + if (getWebviewReference(state)) { + vscode.window.showInformationMessage(`You're already in Pretty Home✨`); + return; + } + const panelIconPath = { - light: vscode.Uri.file(path.join(context.extensionPath, 'src/assets', 'icon.png')), - dark: vscode.Uri.file(path.join(context.extensionPath, 'src/assets', 'icon.png')) + light: vscode.Uri.file(path.join(context.extensionPath, 'assets', 'icon.png')), + dark: vscode.Uri.file(path.join(context.extensionPath, 'assets', 'icon.png')) }; const webviewPanel = vscode.window.createWebviewPanel( @@ -22,6 +29,7 @@ export async function showPrettyHomeCommand(context: vscode.ExtensionContext) { vscode.ViewColumn.One, { enableScripts: true, + retainContextWhenHidden: true, } ); const projects = await gerRecentProjects(); @@ -48,8 +56,10 @@ export async function showPrettyHomeCommand(context: vscode.ExtensionContext) { undefined, context.subscriptions ); + setWebviewReference(webviewPanel, state); + webviewPanel.webview.html = getWebviewContent(projects, context, webviewPanel); - vscode.window.showInformationMessage('Pretty Home Initiate Successfully!'); + vscode.window.showInformationMessage('Pretty Home Initialized ✨'); } ); @@ -57,6 +67,27 @@ export async function showPrettyHomeCommand(context: vscode.ExtensionContext) { } +export async function showPrettyHomeSettingsCommand(context: vscode.ExtensionContext) { + const defaultSettingDisposable = vscode.commands.registerCommand( + "extension.prettyHomeSettings", + async () => { + await showSettingsDialog(context); + }); + + context.subscriptions.push(defaultSettingDisposable); +} + +export async function openProjectInGithub(context: vscode.ExtensionContext, state: State) { + const disposable = vscode.commands.registerCommand( + "extension.prettyHomeGiveStar", + async () => { + const repoUrl = 'https://github.com/sefatanam/vscode-pretty-home'; + + vscode.env.openExternal(vscode.Uri.parse(repoUrl)); + }); + context.subscriptions.push(disposable); +} + function filterProjects(projects: RecentProject[], name: string) { if (!name) { return projects; } diff --git a/src/lib/constant.ts b/src/lib/constant.ts index b2e283e..e46c9f4 100644 --- a/src/lib/constant.ts +++ b/src/lib/constant.ts @@ -1,6 +1,7 @@ export const APP = { WEB_VIEW_TYPE: 'pretty-home', - TITLE: 'Recent Projects | Pretty-Home' + TITLE: 'Recent Projects | Pretty-Home', + WEB_VIEW_REF:'webViewRef' }; export const COMMAND = { diff --git a/src/lib/engine.ts b/src/lib/engine.ts index 539ba9a..18ab989 100644 --- a/src/lib/engine.ts +++ b/src/lib/engine.ts @@ -33,3 +33,22 @@ export function openProject(path: string) { } } +/** + * Show the settings dialog with a checkbox + * @param {vscode.ExtensionContext} context + */ +export async function showSettingsDialog(context: vscode.ExtensionContext) { + const config = vscode.workspace.getConfiguration('prettyHome'); + const selectedOption = await vscode.window.showQuickPick( + ['Yes', 'No'], + { + placeHolder: 'Do you want to load Pretty Home by default on startup?', + ignoreFocusOut: true, + } + ); + + if (selectedOption === 'Yes' || selectedOption === 'No') { + const newValue = selectedOption === 'Yes'; + await config.update('showOnStartup', newValue, vscode.ConfigurationTarget.Global); + } +} \ No newline at end of file diff --git a/src/lib/index.ts b/src/lib/index.ts index 582871b..6a181ed 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -1,5 +1,7 @@ export * from './command'; export * from './constant'; export * from './engine'; +export * from './state'; +export * from './store'; export * from './types'; export * from './views'; From c25b5378ea3fd94263a8be4f55542fa202e4c181 Mon Sep 17 00:00:00 2001 From: sefatanam Date: Tue, 16 Jul 2024 01:15:43 +0600 Subject: [PATCH 4/5] fix: search project control color contrast --- css/style.css | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/css/style.css b/css/style.css index 6122b99..311d015 100644 --- a/css/style.css +++ b/css/style.css @@ -49,15 +49,15 @@ body > * { } .heading input[type="text"]{ - width: 32rem; + width: clamp(20%,32rem,100%) ; padding: .7rem; - border-radius: 0.5rem; - outline: none; - border: none; + border-radius: 6px; + outline: 1px solid var(--vscode-commandCenter-border); + border: 1px solid var(--vscode-commandCenter-border); font-size: var(--vscode-font-size); border: 1px solid var(--vscode-input-background); - background-color: var(--vscode-input-background); - color: var(--vscode-input-foreground); + background-color: var(--vscode-commandCenter-background); + color: var(--vscode-commandCenter-foreground); font-weight: bold; } @@ -92,11 +92,14 @@ body > * { font-size: calc(var(--vscode-editor-font-size) / 2); user-select: text; } + +.title .icon, .card .icon { --size: 1.2rem; height: var(--size); width: var(--size); color: var(--vscode-input-foreground); + cursor: pointer; } .card:hover { background: var(--vscode-textLink-background); From 24d97bdf8f15c697c3bfc2f590a140eff9eea04b Mon Sep 17 00:00:00 2001 From: sefatanam Date: Tue, 16 Jul 2024 01:16:08 +0600 Subject: [PATCH 5/5] fix: update command and version --- package.json | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index b3f1e6d..7266387 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "pretty-home", "displayName": "Pretty Home", "description": "Pretty Home is a VS Code extension designed to enhance the appearance of your recent projects view, making it more organized and visually appealing", - "version": "1.0.2", + "version": "1.1.0", "license": "MIT", "icon": "icon.png", "publisher": "sefatanam", @@ -17,15 +17,37 @@ "categories": [ "Other" ], - "activationEvents": [], + "activationEvents": ["onStartupFinished"], "main": "./dist/extension.js", "contributes": { "commands": [ { "command": "extension.prettyHome", - "title": "Pretty Home ✨" + "title": "Recent Projects ✨", + "category": "Pretty Home" + }, + { + "command": "extension.prettyHomeSettings", + "title": "Settings", + "category": "Pretty Home" + }, + { + "command": "extension.prettyHomeGiveStar", + "title": "Give star 🌟 in Github to support", + "category": "Pretty Home" + } + ], + "configuration": { + "type": "object", + "title": "Pretty Home Settings", + "properties": { + "prettyHome.showOnStartup": { + "type": "boolean", + "default": true, + "description": "Show Pretty Home on startup when no folder or workspace is loaded." + } } - ] + } }, "scripts": { "vscode:prepublish": "pnpm run package",