Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ailtonloures committed Dec 7, 2024
2 parents 62176f3 + 9295bf0 commit 583ff51
Show file tree
Hide file tree
Showing 18 changed files with 92 additions and 31 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ VSCode Bookmark
![GitHub License](https://img.shields.io/github/license/ailtonloures/vscode-bookmark)
</h1>

<p>A utility to save your favorite projects and open them easily in vscode.</p>
<p>A utility to save your favorite projects and files to open them easily on Visual Studio Code.</p>

</div>

Expand All @@ -32,9 +32,12 @@ VSCode Bookmark

## Features

- Save projects path on Store;
- Open projects in VSCode;
- Logs and Monitoring with Sentry;
- Save projects and files to open in vscode;
- by drag and drop;
- by file's browser;
- WSL Integration (Windows);
- by drag and drop;
- projects (directories) only;

## Development

Expand Down
2 changes: 1 addition & 1 deletion forge.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { FuseV1Options, FuseVersion } = require('@electron/fuses');
const { FusesPlugin } = require('@electron-forge/plugin-fuses');
const { VitePlugin } = require('@electron-forge/plugin-vite');
const { FuseV1Options, FuseVersion } = require('@electron/fuses');

const {
name: projectName,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-bookmark",
"productName": "VSCode Bookmark",
"description": "A utility to save your favorite projects and open them easily in vscode.",
"version": "1.2.3",
"version": "1.3.0",
"author": "Ailton Loures",
"homepage": "https://github.com/ailtonloures/vscode-bookmark#readme",
"repository": {
Expand Down
1 change: 0 additions & 1 deletion src/core/index.js

This file was deleted.

9 changes: 9 additions & 0 deletions src/core/vscode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { spawn } from 'node:child_process';

function openIntoVsCode(path, extraArgs = []) {
const commandArgs = [...extraArgs, `"${path}"`];

spawn('code', commandArgs, { shell: true });
}

export { openIntoVsCode };
17 changes: 17 additions & 0 deletions src/core/wsl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function wslBookmarkDataAdapter(path) {
const sanitizedPath = String(path)
.replaceAll('\\', '/')
.replace('.localhost/', '+');
const filePath = `vscode-remote:${sanitizedPath}`;

return {
filePath,
wsl: true,
};
}

function isFilePathFromWsl(path) {
return String(path).startsWith('\\\\wsl');
}

export { wslBookmarkDataAdapter, isFilePathFromWsl };
23 changes: 11 additions & 12 deletions src/data/store/bookmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@ import store from './store';

const storeName = 'bookmarks';

function createBookmark(filePath) {
function createBookmark({ filePath, wsl = false }) {
const bookmarkList = getBookmarks();

store.set(storeName, [
{
path: filePath,
basename: basename(filePath),
id: new Date().getTime(),
},
...bookmarkList,
]);
const bookmarkData = {
path: filePath,
basename: basename(filePath),
id: new Date().getTime(),
wsl,
};

store.set(storeName, [bookmarkData, ...bookmarkList]);
}

function getBookmarks(limit = 10) {
const bookmarkList = store.get(storeName) || [];
return bookmarkList.slice(0, limit);
}

function deleteBookmark(id) {
function deleteBookmarkById(id) {
const bookmarkList = getBookmarks();

store.set(
Expand All @@ -31,4 +30,4 @@ function deleteBookmark(id) {
);
}

export { createBookmark, deleteBookmark, getBookmarks };
export { createBookmark, deleteBookmarkById, getBookmarks };
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions src/modules/utils/index.js → src/electron/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './dialog';
export * from './icon';
export * from './label';
export * from './vite';
export * from './platform';
File renamed without changes.
5 changes: 5 additions & 0 deletions src/electron/utils/platform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function isWindows() {
return process.platform === 'win32';
}

export { isWindows };
File renamed without changes.
File renamed without changes.
52 changes: 40 additions & 12 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { spawn } from 'node:child_process';

import * as Sentry from '@sentry/electron';
import { app, ipcMain } from 'electron';

import { makeAppToInitOnASingleInstance } from './core';
import { makeAppToInitOnASingleInstance } from './core/setup';
import { openIntoVsCode } from './core/vscode';
import { isFilePathFromWsl, wslBookmarkDataAdapter } from './core/wsl';
import {
createBookmark,
deleteBookmark,
deleteBookmarkById,
getBookmarks,
} from './data/store/bookmark';
import { createMenu, createTray, createWindow } from './modules';
import { openDialog } from './modules/utils';
import { createMenu, createTray, createWindow } from './electron';
import { isWindows, openDialog } from './electron/utils';

Sentry.init({
dsn: 'https://713782327975276ae010040b1db6ab8a@o4507887084503040.ingest.us.sentry.io/4507887098724352',
Expand Down Expand Up @@ -41,7 +41,9 @@ function createAppContext() {

function registerIpcMainEvents(context) {
ipcMain.on('create-bookmark', (event, filePath) => {
createBookmark(filePath);
const bookmarkData = getBookmarkDataFromFilePath(filePath);

createBookmark(bookmarkData);
renderApp(context);

event.reply('create-bookmark', true);
Expand Down Expand Up @@ -79,26 +81,30 @@ function renderApp(context) {

if (!filePaths) return;

createBookmark(filePaths.at(0));
const filePathData = getBookmarkDataFromFilePath(filePaths.at(0));

createBookmark(filePathData);
renderApp(context);
},
});

const separatorMenuItem = { type: 'separator' };

const bookmarkMenuItems = getBookmarks().map(({ basename, path, id }) => ({
label: basename,
const bookmarkMenuItems = getBookmarks().map((bookmarkData) => ({
label: getBasenameFromBookmarkData(bookmarkData),
submenu: [
{
label: 'Open',
click: () => {
spawn('code', [path], { shell: true });
openBookmarkIntoVsCode(bookmarkData);
},
},
{
label: 'Remove',
click: () => {
deleteBookmark(id);
const { id } = bookmarkData;

deleteBookmarkById(id);
renderApp(context);
},
},
Expand Down Expand Up @@ -126,3 +132,25 @@ function renderApp(context) {

tray.setContextMenu(contextMenu);
}

function getBookmarkDataFromFilePath(filePath) {
if (isWindows() && isFilePathFromWsl(filePath))
return wslBookmarkDataAdapter(filePath);

return { filePath };
}

function getBasenameFromBookmarkData(bookmarkData) {
if (bookmarkData.wsl) return `[WSL] ${bookmarkData.basename}`;

return bookmarkData.basename;
}

function openBookmarkIntoVsCode(bookmarkData) {
if (bookmarkData.wsl) {
openIntoVsCode(bookmarkData.path, ['--folder-uri']);
return;
}

openIntoVsCode(bookmarkData.path);
}

0 comments on commit 583ff51

Please sign in to comment.