diff --git a/package.json b/package.json index 350669939..799aea9d0 100644 --- a/package.json +++ b/package.json @@ -1,125 +1,125 @@ { - "name": "ente", - "productName": "ente", - "version": "1.6.27", - "private": true, - "description": "Desktop client for ente.io", - "main": "app/main.js", - "build": { - "appId": "io.ente.bhari-frame", - "artifactName": "${productName}-${version}.${ext}", - "linux": { - "target": [ - "AppImage", - "deb", - "rpm", - "pacman", - "tar.gz" - ], - "icon": "./build/icon.icns", - "category": "Photography" + "name": "ente", + "productName": "ente", + "version": "1.6.28-alpha.1", + "private": true, + "description": "Desktop client for ente.io", + "main": "app/main.js", + "build": { + "appId": "io.ente.bhari-frame", + "artifactName": "${productName}-${version}.${ext}", + "linux": { + "target": [ + "AppImage", + "deb", + "rpm", + "pacman", + "tar.gz" + ], + "icon": "./build/icon.icns", + "category": "Photography" + }, + "mac": { + "target": { + "target": "default", + "arch": [ + "universal" + ] + }, + "category": "public.app-category.photography", + "hardenedRuntime": true + }, + "afterSign": "electron-builder-notarize", + "extraFiles": [ + { + "from": "build", + "to": "resources", + "filter": [ + "**/*" + ] + } + ], + "asarUnpack": [ + "node_modules/ffmpeg-static/bin/${os}/${arch}/ffmpeg", + "node_modules/ffmpeg-static/index.js", + "node_modules/ffmpeg-static/package.json" + ], + "files": [ + "app/**/*", + { + "from": "ui", + "to": "ui", + "filter": [ + "!**/*", + "out/**/*" + ] + } + ] }, - "mac": { - "target": { - "target": "default", - "arch": [ - "universal" - ] - }, - "category": "public.app-category.photography", - "hardenedRuntime": true + "scripts": { + "postinstall": "electron-builder install-app-deps", + "prebuild": "eslint \"src/**/*.{js,jsx,ts,tsx}\"", + "prepare": "husky install", + "lint": "eslint -c .eslintrc --ext .ts src", + "watch": "tsc -w", + "build-main": "yarn install && tsc", + "start-main": "yarn build-main && electron app/main.js", + "start-renderer": "cd ui && yarn install && yarn dev", + "start": "concurrently \"yarn start-main\" \"yarn start-renderer\"", + "build-renderer": "cd ui && yarn install && yarn build && cd ..", + "build": "yarn build-renderer && yarn build-main", + "test-release": "cross-env IS_TEST_RELEASE=true yarn build && electron-builder --config.compression=store" }, - "afterSign": "electron-builder-notarize", - "extraFiles": [ - { - "from": "build", - "to": "resources", - "filter": [ - "**/*" + "author": "ente ", + "devDependencies": { + "@sentry/cli": "^1.68.0", + "@types/auto-launch": "^5.0.2", + "@types/ffmpeg-static": "^3.0.1", + "@types/get-folder-size": "^2.0.0", + "@types/node": "^16.18.3", + "@types/node-fetch": "^2.6.2", + "@types/promise-fs": "^2.1.1", + "@types/semver-compare": "^1.0.1", + "@typescript-eslint/eslint-plugin": "^5.28.0", + "@typescript-eslint/parser": "^5.28.0", + "concurrently": "^7.0.0", + "cross-env": "^7.0.3", + "electron": "^21.2.2", + "electron-builder": "^23.0.3", + "electron-builder-notarize": "^1.2.0", + "electron-download": "^4.1.1", + "eslint": "^7.23.0", + "eslint-config-google": "^0.14.0", + "eslint-config-prettier": "^8.5.0", + "husky": "^8.0.1", + "lint-staged": "^13.0.1", + "prettier": "2.5.1", + "typescript": "^4.2.3" + }, + "dependencies": { + "@sentry/electron": "^2.5.1", + "any-shell-escape": "^0.1.1", + "auto-launch": "^5.0.5", + "chokidar": "^3.5.3", + "electron-log": "^4.3.5", + "electron-reload": "^2.0.0-alpha.1", + "electron-store": "^8.0.1", + "electron-updater": "^4.3.8", + "ffmpeg-static": "^5.1.0", + "get-folder-size": "^2.0.1", + "next-electron-server": "file:./thirdparty/next-electron-server", + "node-fetch": "^2.6.7", + "node-stream-zip": "^1.15.0", + "promise-fs": "^2.1.1", + "semver-compare": "^1.0.0" + }, + "standard": { + "parser": "babel-eslint" + }, + "lint-staged": { + "src/**/*.{js,jsx,ts,tsx}": [ + "eslint --fix", + "prettier --write --ignore-unknown" ] - } - ], - "asarUnpack": [ - "node_modules/ffmpeg-static/bin/${os}/${arch}/ffmpeg", - "node_modules/ffmpeg-static/index.js", - "node_modules/ffmpeg-static/package.json" - ], - "files": [ - "app/**/*", - { - "from": "ui", - "to": "ui", - "filter": [ - "!**/*", - "out/**/*" - ] - } - ] - }, - "scripts": { - "postinstall": "electron-builder install-app-deps", - "prebuild": "eslint \"src/**/*.{js,jsx,ts,tsx}\"", - "prepare": "husky install", - "lint": "eslint -c .eslintrc --ext .ts src", - "watch": "tsc -w", - "build-main": "yarn install && tsc", - "start-main": "yarn build-main && electron app/main.js", - "start-renderer": "cd ui && yarn install && yarn dev", - "start": "concurrently \"yarn start-main\" \"yarn start-renderer\"", - "build-renderer": "cd ui && yarn install && yarn build && cd ..", - "build": "yarn build-renderer && yarn build-main", - "test-release": "cross-env IS_TEST_RELEASE=true yarn build && electron-builder --config.compression=store" - }, - "author": "ente ", - "devDependencies": { - "@sentry/cli": "^1.68.0", - "@types/auto-launch": "^5.0.2", - "@types/ffmpeg-static": "^3.0.1", - "@types/get-folder-size": "^2.0.0", - "@types/node": "^16.18.3", - "@types/node-fetch": "^2.6.2", - "@types/promise-fs": "^2.1.1", - "@types/semver-compare": "^1.0.1", - "@typescript-eslint/eslint-plugin": "^5.28.0", - "@typescript-eslint/parser": "^5.28.0", - "concurrently": "^7.0.0", - "cross-env": "^7.0.3", - "electron": "^21.2.2", - "electron-builder": "^23.0.3", - "electron-builder-notarize": "^1.2.0", - "electron-download": "^4.1.1", - "eslint": "^7.23.0", - "eslint-config-google": "^0.14.0", - "eslint-config-prettier": "^8.5.0", - "husky": "^8.0.1", - "lint-staged": "^13.0.1", - "prettier": "2.5.1", - "typescript": "^4.2.3" - }, - "dependencies": { - "@sentry/electron": "^2.5.1", - "any-shell-escape": "^0.1.1", - "auto-launch": "^5.0.5", - "chokidar": "^3.5.3", - "electron-log": "^4.3.5", - "electron-reload": "^2.0.0-alpha.1", - "electron-store": "^8.0.1", - "electron-updater": "^4.3.8", - "ffmpeg-static": "^5.1.0", - "get-folder-size": "^2.0.1", - "next-electron-server": "file:./thirdparty/next-electron-server", - "node-fetch": "^2.6.7", - "node-stream-zip": "^1.15.0", - "promise-fs": "^2.1.1", - "semver-compare": "^1.0.0" - }, - "standard": { - "parser": "babel-eslint" - }, - "lint-staged": { - "src/**/*.{js,jsx,ts,tsx}": [ - "eslint --fix", - "prettier --write --ignore-unknown" - ] - } -} \ No newline at end of file + } +} diff --git a/src/api/export.ts b/src/api/export.ts index b5615a007..118a6c1a5 100644 --- a/src/api/export.ts +++ b/src/api/export.ts @@ -12,15 +12,6 @@ export const checkExistsAndCreateDir = async (dirPath: string) => { } }; -export const checkExistsAndRename = async ( - oldDirPath: string, - newDirPath: string -) => { - if (fs.existsSync(oldDirPath)) { - await fs.rename(oldDirPath, newDirPath); - } -}; - export const saveStreamToDisk = async ( filePath: string, fileStream: ReadableStream diff --git a/src/api/fs.ts b/src/api/fs.ts index d947c3b16..a5cbfc510 100644 --- a/src/api/fs.ts +++ b/src/api/fs.ts @@ -5,4 +5,4 @@ export async function getDirFiles(dirPath: string) { const electronFiles = await Promise.all(files.map(getElectronFile)); return electronFiles; } -export { isFolder } from '../services/fs'; +export { isFolder, moveFile, deleteFolder, rename } from '../services/fs'; diff --git a/src/preload.ts b/src/preload.ts index 13eec242c..e94534f9e 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -29,7 +29,6 @@ import { clearElectronStore } from './api/electronStore'; import { openDiskCache, deleteDiskCache } from './api/cache'; import { checkExistsAndCreateDir, - checkExistsAndRename, saveStreamToDisk, saveFileToDisk, getExportRecord, @@ -45,7 +44,13 @@ import { openDirectory, } from './api/common'; import { fixHotReloadNext12 } from './utils/preload'; -import { isFolder, getDirFiles } from './api/fs'; +import { + isFolder, + getDirFiles, + moveFile, + deleteFolder, + rename, +} from './api/fs'; import { convertHEIC, generateImageThumbnail } from './api/imageProcessor'; import { setupLogging } from './utils/logging'; import { @@ -63,7 +68,6 @@ const windowObject: any = window; windowObject['ElectronAPIs'] = { exists, checkExistsAndCreateDir, - checkExistsAndRename, saveStreamToDisk, saveFileToDisk, selectRootDirectory, @@ -105,4 +109,7 @@ windowObject['ElectronAPIs'] = { logRendererProcessMemoryUsage, registerForegroundEventListener, openDirectory, + moveFile, + deleteFolder, + rename, }; diff --git a/src/services/fs.ts b/src/services/fs.ts index b5ef8eb11..5f5e9906c 100644 --- a/src/services/fs.ts +++ b/src/services/fs.ts @@ -241,3 +241,40 @@ export async function readTextFile(filePath: string) { } return await fs.readFile(filePath, 'utf-8'); } + +export async function moveFile( + sourcePath: string, + destinationPath: string +): Promise { + if (!existsSync(sourcePath)) { + throw new Error('File does not exist'); + } + if (existsSync(destinationPath)) { + throw new Error('Destination file already exists'); + } + // check if destination folder exists + const destinationFolder = path.dirname(destinationPath); + if (!existsSync(destinationFolder)) { + await fs.mkdir(destinationFolder, { recursive: true }); + } + await fs.rename(sourcePath, destinationPath); +} + +export async function deleteFolder(folderPath: string): Promise { + if (!existsSync(folderPath)) { + return; + } + // check if folder is empty + const files = await fs.readdir(folderPath); + if (files.length > 0) { + throw new Error('Folder is not empty'); + } + await fs.rmdir(folderPath); +} + +export async function rename(oldPath: string, newPath: string) { + if (!existsSync(oldPath)) { + throw new Error('Path does not exist'); + } + await fs.rename(oldPath, newPath); +} diff --git a/src/utils/ipcComms.ts b/src/utils/ipcComms.ts index 2e9b4425a..de2326645 100644 --- a/src/utils/ipcComms.ts +++ b/src/utils/ipcComms.ts @@ -114,7 +114,7 @@ export default function setupIpcComs( }); ipcMain.handle('open-dir', (_, dirPath) => { - shell.openPath(dirPath); + shell.openPath(path.normalize(dirPath)); }); ipcMain.on('update-and-restart', () => { diff --git a/ui b/ui index 627cad22e..d0cd90f27 160000 --- a/ui +++ b/ui @@ -1 +1 @@ -Subproject commit 627cad22e2481258bec9dd6996ea55fe38512672 +Subproject commit d0cd90f2715fe3b9c2cd0ce3f422505deb4f5d5d