Feature: Implement read write access checking on Project Directory and report any issues in home page (#5676)
* chore: skeleton to detect read write directories and if we have access to notify user * chore: adding buttont to easily change project directory * chore: cleaning up home page error bar layout and button * fix: adding clearer comments * fix: ugly console debugging but I need to save off progress * fix: removing project dir check on empty string * fix: debug progress to save off listProjects once. Still bugged... * fix: more hard coded debugging to get project loading optimizted * fix: yarp, we got another one bois * fix: cleaning up code * fix: massive bug comment to warn devs about chokidar bugs * fix: returning error instead of throwing * fix: cleaning up PR * fix: fixed loading the projects when the project directory changes * fix: remove testing code * fix: only skip directories if you can access the project directory since we don't need to view them * fix: unit tests, turning off noisey localhost vitest garbage * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * fix: deleted testing state --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com> Co-authored-by: Pierre Jacquier <pierre@zoo.dev>
This commit is contained in:
@ -98,14 +98,40 @@ const rename = (prev: string, next: string) => fs.rename(prev, next)
|
||||
const writeFile = (path: string, data: string | Uint8Array) =>
|
||||
fs.writeFile(path, data, 'utf-8')
|
||||
const readdir = (path: string) => fs.readdir(path, 'utf-8')
|
||||
const stat = (path: string) =>
|
||||
fs.stat(path).catch((e) => Promise.reject(e.code))
|
||||
const stat = (path: string) => {
|
||||
return fs.stat(path).catch((e) => Promise.reject(e.code))
|
||||
}
|
||||
|
||||
// Electron has behavior where it doesn't clone the prototype chain over.
|
||||
// So we need to call stat.isDirectory on this side.
|
||||
const statIsDirectory = (path: string) =>
|
||||
stat(path).then((res) => res.isDirectory())
|
||||
const getPath = async (name: string) => ipcRenderer.invoke('app.getPath', name)
|
||||
|
||||
const canReadWriteDirectory = async (
|
||||
path: string
|
||||
): Promise<{ value: boolean; error: unknown } | Error> => {
|
||||
const isDirectory = await statIsDirectory(path)
|
||||
if (!isDirectory) {
|
||||
return new Error('path is not a directory. Do not send a file path.')
|
||||
}
|
||||
|
||||
// bitwise OR to check read and write permissions
|
||||
try {
|
||||
const canReadWrite = await fs.access(
|
||||
path,
|
||||
fs.constants.R_OK | fs.constants.W_OK
|
||||
)
|
||||
// This function returns undefined. If it cannot access the path it will throw an error
|
||||
return canReadWrite === undefined
|
||||
? { value: true, error: undefined }
|
||||
: { value: false, error: undefined }
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
return { value: false, error: e }
|
||||
}
|
||||
}
|
||||
|
||||
const exposeProcessEnvs = (varNames: Array<string>) => {
|
||||
const envs: Record<string, string> = {}
|
||||
varNames.forEach((varName) => {
|
||||
@ -211,4 +237,5 @@ contextBridge.exposeInMainWorld('electron', {
|
||||
appCheckForUpdates,
|
||||
getArgvParsed,
|
||||
resizeWindow,
|
||||
canReadWriteDirectory,
|
||||
})
|
||||
|
Reference in New Issue
Block a user