Skip to content

Commit

Permalink
feat: adding notification to bad files from WSL
Browse files Browse the repository at this point in the history
  • Loading branch information
ailtonloures committed Dec 13, 2024
1 parent 560cd9f commit d20d248
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ VSCode Bookmark
- by file's browser;
- WSL Integration (Windows);
- by drag and drop;
- projects (directories) only;
- projects (folders) only;
- Open bookmarks config to edit order and basename;

## Development
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.4.0",
"version": "1.4.1",
"author": "Ailton Loures",
"homepage": "https://github.com/ailtonloures/vscode-bookmark#readme",
"repository": {
Expand Down
7 changes: 7 additions & 0 deletions src/core/file-system.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { statSync } from 'node:fs';

function isFile(filePath) {
return statSync(filePath).isFile();
}

export { isFile };
27 changes: 22 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as Sentry from '@sentry/electron';
import { app, ipcMain } from 'electron';

import { isFile } from './core/file-system';
import { makeAppToInitOnASingleInstance } from './core/setup';
import { openIntoVsCode } from './core/vscode';
import { isFilePathFromWsl, wslBookmarkDataAdapter } from './core/wsl';
Expand Down Expand Up @@ -42,12 +43,17 @@ function createAppContext() {

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

if (!bookmarkData) {
event.reply('create-bookmark', 'ERROR');
return;
}

createBookmark(bookmarkData);
renderApp(context);

event.reply('create-bookmark', true);
event.reply('create-bookmark', 'OK');
});
}

Expand Down Expand Up @@ -142,9 +148,20 @@ function renderApp(context) {
tray.setContextMenu(contextMenu);
}

function getBookmarkDataFromFilePath(filePath) {
if (isWindows() && isFilePathFromWsl(filePath))
return wslBookmarkDataAdapter(filePath);
function getBookmarkDataFromFilePath(context, filePath) {
const { tray } = context;

if (isWindows() && isFilePathFromWsl(filePath)) {
if (!isFile(filePath)) return wslBookmarkDataAdapter(filePath);

tray.displayBalloon({
iconType: 'warning',
title: 'Unsupported WSL path',
content: 'You can only save folders from WSL',
});

return null;
}

return { filePath };
}
Expand Down
6 changes: 5 additions & 1 deletion ui/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,9 @@ body {
}

.success {
color: #2ab347;
color: #28a745;
}

.danger {
color: #dc3545;
}
11 changes: 8 additions & 3 deletions ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const globalState = {
initial: 'Drag and drop your files or projects here.',
drop: 'Drop...',
wait: 'Wait...',
success: 'Success!',
success: 'Done!',
wrong: 'Wrong!',
},
};
// Elements
Expand All @@ -36,11 +37,15 @@ function onDrop(event) {
ipc.toMain(ipcChannels.CREATE_BOOKMARK, filePath);
}

function onCreatedBookmark(success) {
if (success) {
function onCreatedBookmark(_, status) {
if (status === 'OK') {
setDropAreaDivText(
`<span class="success">${globalState.dropAreaDiv.success}</span>`
);
} else {
setDropAreaDivText(
`<span class="danger">${globalState.dropAreaDiv.wrong}</span>`
);
}

setTimeout(() => {
Expand Down

0 comments on commit d20d248

Please sign in to comment.