rdesktop^2
filip mertens 1 year ago
parent 336d191c20
commit 038c63e362
  1. 1
      apps/1test/package.json
  2. 6
      apps/1test/src/electron/fsPlugin.ts
  3. 93
      apps/1test/src/index.ts
  4. 82
      apps/1test/yarn.lock
  5. 14
      apps/remix-ide/src/app/files/dgitProvider.js
  6. 92
      apps/remix-ide/src/app/plugins/fsPlugin.ts
  7. 4
      apps/remix-ide/src/app/tabs/theme-module.js
  8. 105
      apps/remixdesktop/src/fsPlugin.ts
  9. 32
      yarn.lock

@ -44,6 +44,7 @@
"chokidar": "^3.5.3",
"electron-squirrel-startup": "^1.0.0",
"fix-path": "^4.0.0",
"isomorphic-git": "^1.24.0",
"node-pty": "0.10.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",

@ -83,6 +83,12 @@ class FSPluginClient extends ElectronBasePluginClient {
}
}
async lstat(path: string): Promise<any> {
const lstat = await fs.lstat(this.fixPath(path))
return lstat
}
async exists(path: string): Promise<boolean> {
return fs.access(this.fixPath(path)).then(() => true).catch(() => false)
}

@ -24,8 +24,8 @@ export const createWindow = (): void => {
height: 800,
width: 1024,
webPreferences: {
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
additionalArguments: [`--window-id=${id}`],
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
additionalArguments: [`--window-id=${id}`],
},
});
@ -44,7 +44,7 @@ export const createWindow = (): void => {
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);
//app.on('ready', createWindow);
// when a window is closed event
app.on('web-contents-created', (event, contents) => {
@ -93,6 +93,91 @@ const commandKeys: Record<string, string> = {
const menu = [shellMenu(commandKeys, execCommand)]
Menu.setApplicationMenu(Menu.buildFromTemplate(menu))
import fs from 'fs/promises'
import { readlink } from 'fs';
//const menu = Menu.buildFromTemplate(shellMenu([], undefined))
//Menu.setApplicationMenu(menu)
const myFS = {
promises: {
readdir: async (path: string, options: any): Promise<string[]> => {
// call node fs.readdir
//console.log('myFS.readdir', path, options)
const file = await fs.readdir(path, {
encoding: 'utf8',
})
//console.log('myFS.readdir', file)
return file
},
readFile: async (path: string, options: any): Promise<string>=> {
//console.log('myFS.readFile', path, options)
const file = await (fs as any).readFile(path, options)
//console.log('myFS.readFile', file)
return file
},
async writeFile(path: string, content: string): Promise<void> {
return fs.writeFile(path, content, 'utf8')
},
async mkdir(path: string): Promise<void> {
return fs.mkdir(path)
},
async rmdir(path: string): Promise<void> {
return fs.rmdir(path)
},
async unlink(path: string): Promise<void> {
return fs.unlink(path)
},
async rename(oldPath: string, newPath: string): Promise<void> {
return fs.rename(oldPath, newPath)
},
async stat(path: string): Promise<any> {
//console.log('myFS.stat', path)
const stat = await fs.stat(path)
//console.log('myFS.stat', stat)
return stat
},
async lstat(path: string): Promise<any> {
const lstat = await fs.lstat(path)
//console.log('myFS.stat', path, lstat)
return lstat
},
readlink: async (path: string): Promise<string> => {
return fs.readlink(path)
},
symlink: async (target: string, path: string): Promise<void> => {
return fs.symlink(target, path)
}
}
}
console.log('myFS', myFS)
async function checkGit() {
const git = require('isomorphic-git');
const files = await git.statusMatrix({ fs: myFS, dir: '/Volumes/bunsen/code/rmproject2/remix-project' });
console.log('GIT', files)
}
setInterval(() => {
const startTime = Date.now()
checkGit()
.then(() => {
console.log('checkGit', Date.now() - startTime)
})
}, 3000)

@ -1237,6 +1237,11 @@ astral-regex@^2.0.0:
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-2.0.0.tgz#483143c567aeed4785759c0865786dc77d7d2e31"
integrity sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==
async-lock@^1.1.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/async-lock/-/async-lock-1.4.0.tgz#c8b6630eff68fbbdd8a5b6eb763dac3bfbb8bf02"
integrity sha512-coglx5yIWuetakm3/1dsX9hxCNox22h7+V80RQOu2XUUMidtArxKoZoOtHUPuR84SycKTXzgGzAUR5hJxujyJQ==
at-least-node@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2"
@ -1521,6 +1526,11 @@ clean-css@^5.2.2:
dependencies:
source-map "~0.6.0"
clean-git-ref@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/clean-git-ref/-/clean-git-ref-2.0.1.tgz#dcc0ca093b90e527e67adb5a5e55b1af6816dcd9"
integrity sha512-bLSptAy2P0s6hU4PzuIMKmMJJSE6gLXGH1cntDu7bWJUksvuM+7ReOK61mozULErYvP6a15rnYl0zFDef+pyPw==
clean-stack@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b"
@ -1726,6 +1736,11 @@ cosmiconfig@^7.0.1:
path-type "^4.0.0"
yaml "^1.10.0"
crc-32@^1.2.0:
version "1.2.2"
resolved "https://registry.yarnpkg.com/crc-32/-/crc-32-1.2.2.tgz#3cad35a934b8bf71f25ca524b6da51fb7eace2ff"
integrity sha512-ROmzCKrTnOwybPcJApAA6WBWij23HVfGVNKqqrZpuyZOHqK2CwHSvpGuyt/UNNvaIjEd8X5IFGp4Mh+Ie1IHJQ==
create-require@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333"
@ -1915,6 +1930,11 @@ detect-node@^2.0.4:
resolved "https://registry.yarnpkg.com/detect-node/-/detect-node-2.1.0.tgz#c9c70775a49c3d03bc2c06d9a73be550f978f8b1"
integrity sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g==
diff3@0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/diff3/-/diff3-0.0.3.tgz#d4e5c3a4cdf4e5fe1211ab42e693fcb4321580fc"
integrity sha512-iSq8ngPOt0K53A6eVr4d5Kn6GNrM2nQZtC740pzIriHtn4pOQ2lyzEXQMBeVcWERN0ye7fhBsk9PbLLQOnUx/g==
diff@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
@ -3252,7 +3272,7 @@ ieee754@^1.1.13:
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352"
integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==
ignore@^5.2.0:
ignore@^5.1.4, ignore@^5.2.0:
version "5.2.4"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.4.tgz#a291c0c6178ff1b960befe47fcdec301674a6324"
integrity sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==
@ -3547,6 +3567,23 @@ isobject@^3.0.1:
resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"
integrity sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg==
isomorphic-git@^1.24.0:
version "1.24.0"
resolved "https://registry.yarnpkg.com/isomorphic-git/-/isomorphic-git-1.24.0.tgz#d3c7487ba67724d63dec0158572cb33767298f4d"
integrity sha512-4wV95pUr9kGTRZWB9a266bHfD3QAZzWWLIPxlTou4tgOaz4WKmaMOMKKHywudzigsU8h7YwbXyBLE4OEaK8F9Q==
dependencies:
async-lock "^1.1.0"
clean-git-ref "^2.0.1"
crc-32 "^1.2.0"
diff3 "0.0.3"
ignore "^5.1.4"
minimisted "^2.0.0"
pako "^1.0.10"
pify "^4.0.1"
readable-stream "^3.4.0"
sha.js "^2.4.9"
simple-get "^4.0.1"
jest-worker@^27.4.5:
version "27.5.1"
resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-27.5.1.tgz#8d146f0900e8973b106b6f73cc1e9a8cb86f8db0"
@ -3949,11 +3986,18 @@ minimatch@^5.0.1:
dependencies:
brace-expansion "^2.0.1"
minimist@^1.2.0, minimist@^1.2.6:
minimist@^1.2.0, minimist@^1.2.5, minimist@^1.2.6:
version "1.2.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c"
integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==
minimisted@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/minimisted/-/minimisted-2.0.1.tgz#d059fb905beecf0774bc3b308468699709805cb1"
integrity sha512-1oPjfuLQa2caorJUM8HV8lGgWCc0qqAO1MNv/k05G4qslmsndV/5WdNZrqCiyqiz3wohia2Ij2B7w2Dr7/IyrA==
dependencies:
minimist "^1.2.5"
minipass-collect@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/minipass-collect/-/minipass-collect-1.0.2.tgz#22b813bf745dc6edba2576b940022ad6edc8c617"
@ -4403,6 +4447,11 @@ p-try@^2.0.0:
resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6"
integrity sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==
pako@^1.0.10:
version "1.0.11"
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"
integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==
param-case@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/param-case/-/param-case-3.0.4.tgz#7d17fe4aa12bde34d4a77d91acfb6219caad01c5"
@ -4527,6 +4576,11 @@ pify@^2.0.0:
resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c"
integrity sha512-udgsAY+fTnvv7kI7aaxbqwWNb0AHiB0qBO89PZKPkoTmGOgdbrHDKD+0B2X4uTfJ/FT1R09r9gTsjUjNJotuog==
pify@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/pify/-/pify-4.0.1.tgz#4b2cd25c50d598735c50292224fd8c6df41e3231"
integrity sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==
pkg-dir@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-4.2.0.tgz#f099133df7ede422e81d1d8448270eeb3e4261f3"
@ -4936,7 +4990,7 @@ safe-buffer@5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
safe-buffer@5.2.1, safe-buffer@>=5.1.0, safe-buffer@^5.1.0, safe-buffer@~5.2.0:
safe-buffer@5.2.1, safe-buffer@>=5.1.0, safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@~5.2.0:
version "5.2.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==
@ -5086,6 +5140,14 @@ setprototypeof@1.2.0:
resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.2.0.tgz#66c9a24a73f9fc28cbe66b09fed3d33dcaf1b424"
integrity sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==
sha.js@^2.4.9:
version "2.4.11"
resolved "https://registry.yarnpkg.com/sha.js/-/sha.js-2.4.11.tgz#37a5cf0b81ecbc6943de109ba2960d1b26584ae7"
integrity sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==
dependencies:
inherits "^2.0.1"
safe-buffer "^5.0.1"
shallow-clone@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/shallow-clone/-/shallow-clone-3.0.1.tgz#8f2981ad92531f55035b01fb230769a40e02efa3"
@ -5152,6 +5214,20 @@ signal-exit@^3.0.0, signal-exit@^3.0.2, signal-exit@^3.0.3, signal-exit@^3.0.7:
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9"
integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==
simple-concat@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/simple-concat/-/simple-concat-1.0.1.tgz#f46976082ba35c2263f1c8ab5edfe26c41c9552f"
integrity sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==
simple-get@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/simple-get/-/simple-get-4.0.1.tgz#4a39db549287c979d352112fa03fd99fd6bc3543"
integrity sha512-brv7p5WgH0jmQJr1ZDDfKDOSeWWg+OVypG99A/5vYGPqJ6pxiaHLy8nxtFjBA7oMa01ebA9gfh1uMCFqOuXxvA==
dependencies:
decompress-response "^6.0.0"
once "^1.3.1"
simple-concat "^1.0.0"
slash@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634"

@ -48,7 +48,19 @@ class DGitProvider extends Plugin {
this.ipfsSources = [this.remixIPFS, this.globalIPFSConfig, this.ipfsconfig]
}
async onActivation () {
}
async getGitConfig () {
if(isElectron()){
return {
fs: window.remixFileSystem,
dir: '/'
}
}
const workspace = await this.call('filePanel', 'getCurrentWorkspace')
if (!workspace) return
@ -82,10 +94,12 @@ class DGitProvider extends Plugin {
}
async status (cmd) {
console.log('status')
const status = await git.statusMatrix({
...await this.getGitConfig(),
...cmd
})
console.log('STATUS', status)
return status
}

@ -27,7 +27,7 @@ export class fsPlugin extends ElectronPlugin {
name: 'fs',
description: 'fs',
})
this.methods = ['readdir', 'readFile', 'writeFile', 'mkdir', 'rmdir', 'unlink', 'rename', 'stat', 'exists', 'setWorkingDir']
this.methods = ['readdir', 'readFile', 'writeFile', 'mkdir', 'rmdir', 'unlink', 'rename', 'stat', 'lstat', 'exists', 'setWorkingDir']
// List of commands all filesystems are expected to provide. `rm` is not
// included since it may not exist and must be handled as a special case
@ -72,36 +72,52 @@ export class fsPlugin extends ElectronPlugin {
return await this.call('fs', 'mkdir', path)
},
readFile: async (path: string, options) => {
console.log('readFile', path, options)
path = fixPath(path)
const file = await this.call('fs', 'readFile', path)
console.log('readFile', path, file)
return file
try {
console.log('readFile', path, options)
path = fixPath(path)
const file = await this.call('fs', 'readFile', path, options)
console.log('readFile', path, file)
return file
} catch (e) {
console.log('readFile error', e)
return undefined
}
}
,
rename: async (from: string, to: string) => {
return await this.call('fs', 'rename', from, to)
},
writeFile: async (path: string, content: string) => {
writeFile: async (path: string, content: string, options: any) => {
path = fixPath(path)
return await this.call('fs', 'writeFile', path, content)
return await this.call('fs', 'writeFile', path, content, options)
}
,
stat: async (path: string) => {
path = fixPath(path)
const stat = await this.call('fs', 'stat', path)
stat.isDirectory = () => stat.isDirectoryValue
stat.isFile = () => !stat.isDirectoryValue
//console.log('stat', path, stat)
return stat
try {
path = fixPath(path)
const stat = await this.call('fs', 'stat', path)
if(!stat) return undefined
stat.isDirectory = () => stat.isDirectoryValue
stat.isFile = () => !stat.isDirectoryValue
//console.log('stat', path, stat)
return stat
} catch (e) {
console.log('stat error', e)
return undefined
}
},
lstat: async (path: string) => {
path = fixPath(path)
const stat = await this.call('fs', 'lstat', path)
stat.isDirectory = () => stat.isDirectoryValue
stat.isFile = () => !stat.isDirectoryValue
//console.log('stat', path, stat)
return stat
try {
path = fixPath(path)
const stat = await this.call('fs', 'lstat', path)
if(!stat) return undefined
stat.isDirectory = () => stat.isDirectoryValue
stat.isFile = () => !stat.isDirectoryValue
return stat
} catch (e) {
console.log('lstat error', e)
return undefined
}
},
readlink: async (path: string) => {
path = fixPath(path)
@ -112,7 +128,7 @@ export class fsPlugin extends ElectronPlugin {
return await this.call('fs', 'symlink', target, path)
}
@ -131,39 +147,7 @@ export class fsPlugin extends ElectronPlugin {
async onActivation() {
console.log('fsPluginClient onload', this.fs);
(window as any).remixFileSystem = this.fs;
/*(window as any).remixFileSystemCallback = {
readdir: (filepath, opts, cb) => {
console.log('readdir', filepath, opts)
const [resolve, reject] = wrapCallback(opts, cb);
(window as any).remixFileSystem.fs.readdir(filepath, opts).then(resolve).catch(reject);
},
readFile: (filepath, opts, cb) => {
console.log('readFile', filepath, opts)
const [resolve, reject] = wrapCallback(opts, cb);
(window as any).remixFileSystem.fs.readFile(filepath, opts).then(resolve).catch(reject)
},
writeFile: (filepath, content, opts, cb) => {
const [resolve, reject] = wrapCallback(opts, cb);
(window as any).remixFileSystem.fs.writeFile(filepath, content, opts).then(resolve).catch(reject)
},
mkdir: (filepath, opts, cb) => {
const [resolve, reject] = wrapCallback(opts, cb);
(window as any).remixFileSystem.fs.mkdir(filepath, opts).then(resolve).catch(reject)
},
rmdir: (filepath, opts, cb) => {
const [resolve, reject] = wrapCallback(opts, cb);
(window as any).remixFileSystem.fs.rmdir(filepath, opts).then(resolve).catch(reject)
},
unlink: (filepath, opts, cb) => {
const [resolve, reject] = wrapCallback(opts, cb);
(window as any).remixFileSystem.fs.unlink(filepath, opts).then(resolve).catch(reject)
},
stat: (filepath, opts, cb) => {
const [resolve, reject] = wrapCallback(opts, cb);
(window as any).remixFileSystem.fs.stat(filepath, opts).then(resolve).catch(reject)
}
};
*/
this.on('fs', 'workingDirChanged', async (path: string) => {
console.log('change working dir', path)

@ -115,6 +115,10 @@ export class ThemeModule extends Plugin {
document.documentElement.style.setProperty('--theme', nextTheme.quality)
if (themeName) this.active = themeName
// TODO: Only keep `this.emit` (issue#2210)
console.log('themeChanged', nextTheme)
if(isElectron()) {
nextTheme.url = nextTheme.url = 'https://remix.ethereum.org/' + nextTheme.url.replace(/\\/g, '/').replace(/\/\//g, '/').replace(/\/$/g, '')
}
this.emit('themeChanged', nextTheme)
this.events.emit('themeChanged', nextTheme)
}

@ -36,7 +36,7 @@ const clientProfile: Profile = {
name: 'fs',
displayName: 'fs',
description: 'fs',
methods: ['readdir', 'readFile', 'writeFile', 'mkdir', 'rmdir', 'unlink', 'rename', 'stat', 'exists', 'currentPath', 'watch', 'closeWatch', 'setWorkingDir']
methods: ['readdir', 'readFile', 'writeFile', 'mkdir', 'rmdir', 'unlink', 'rename', 'stat', 'lstat', 'exists', 'currentPath', 'watch', 'closeWatch', 'setWorkingDir']
}
class FSPluginClient extends ElectronBasePluginClient {
@ -54,16 +54,26 @@ class FSPluginClient extends ElectronBasePluginClient {
async readdir(path: string): Promise<string[]> {
// call node fs.readdir
console.log('readdir', path)
const files = fs.readdir(this.fixPath(path))
if (!path) return []
const files = fs.readdir(this.fixPath(path))
return files
}
async readFile(path: string, options: any ): Promise<string> {
return fs.readFile(this.fixPath(path), 'utf8')
async readFile(path: string, options: any): Promise<string | undefined> {
console.log('readFile', path, options)
// hacky fix for TS error
if (!path) return undefined
try {
return (fs as any).readFile(this.fixPath(path), options)
} catch (e) {
console.log('readFile error', e)
return undefined
}
}
async writeFile(path: string, content: string): Promise<void> {
return fs.writeFile(this.fixPath(path), content, 'utf8')
async writeFile(path: string, content: string, options: any): Promise<void> {
console.log('writeFile', path, content, options)
return (fs as any).writeFile(this.fixPath(path), content, options)
}
async mkdir(path: string): Promise<void> {
@ -83,49 +93,63 @@ class FSPluginClient extends ElectronBasePluginClient {
}
async stat(path: string): Promise<any> {
const stat = await fs.stat(this.fixPath(path))
//console.log('stat', path, stat)
const isDirectory = stat.isDirectory()
return {
...stat,
isDirectoryValue: isDirectory
try {
const stat = await fs.stat(this.fixPath(path))
//console.log('stat', path, stat)
const isDirectory = stat.isDirectory()
return {
...stat,
isDirectoryValue: isDirectory
}
} catch (e) {
console.log('stat error', e)
return undefined
}
}
async lstat(path: string): Promise<any> {
const lstat = await fs.lstat(this.fixPath(path))
return lstat
try {
const stat = await fs.lstat(this.fixPath(path))
const isDirectory = stat.isDirectory()
return {
...stat,
isDirectoryValue: isDirectory
}
} catch (e) {
console.log('lstat error', e)
return undefined
}
}
async exists(path: string): Promise<boolean> {
return fs.access(this.fixPath(path)).then(() => true).catch(() => false)
}
async exists(path: string): Promise < boolean > {
return fs.access(this.fixPath(path)).then(() => true).catch(() => false)
}
async currentPath(): Promise<string> {
return process.cwd()
}
async currentPath(): Promise < string > {
return process.cwd()
}
async watch(path: string): Promise<void> {
if (this.watcher) this.watcher.close()
async watch(path: string): Promise < void> {
if(this.watcher) this.watcher.close()
this.watcher =
chokidar.watch(this.fixPath(path)).on('change', (path, stats) => {
console.log('change', path, stats)
this.emit('change', path, stats)
})
}
chokidar.watch(this.fixPath(path)).on('change', (path, stats) => {
console.log('change', path, stats)
this.emit('change', path, stats)
})
}
async closeWatch(): Promise<void> {
console.log('closing Watcher', this.webContentsId)
if (this.watcher) this.watcher.close()
}
async closeWatch(): Promise < void> {
console.log('closing Watcher', this.webContentsId)
if(this.watcher) this.watcher.close()
}
async setWorkingDir(): Promise<void> {
const dirs = dialog.showOpenDialogSync(this.window, {
properties: ['openDirectory']
})
if (dirs && dirs.length > 0) {
async setWorkingDir(): Promise < void> {
const dirs = dialog.showOpenDialogSync(this.window, {
properties: ['openDirectory']
})
if(dirs && dirs.length > 0) {
this.workingDir = dirs[0]
this.emit('workingDirChanged', dirs[0])
}
@ -133,11 +157,12 @@ class FSPluginClient extends ElectronBasePluginClient {
}
fixPath(path: string): string {
if (path.startsWith('/')) {
path = path.slice(1)
if (path) {
if (path.startsWith('/')) {
path = path.slice(1)
}
}
if(!this.workingDir.endsWith('/')) this.workingDir = this.workingDir + '/'
if (!this.workingDir.endsWith('/')) this.workingDir = this.workingDir + '/'
path = this.workingDir + path
return path
}

@ -11939,13 +11939,6 @@ decompress-response@^3.2.0, decompress-response@^3.3.0:
dependencies:
mimic-response "^1.0.0"
decompress-response@^4.2.0:
version "4.2.1"
resolved "https://registry.yarnpkg.com/decompress-response/-/decompress-response-4.2.1.tgz#414023cc7a302da25ce2ec82d0d5238ccafd8986"
integrity sha512-jOSne2qbyE+/r8G1VU+G/82LBs2Fs4LAsTiLSHOCOMZQl2OKZ6i8i4IyHemTe+/yIXOtTcRQMzPcgyhoFlqPkw==
dependencies:
mimic-response "^2.0.0"
decompress-response@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/decompress-response/-/decompress-response-6.0.0.tgz#ca387612ddb7e104bd16d85aab00d5ecf09c66fc"
@ -17392,10 +17385,10 @@ isobject@^3.0.0, isobject@^3.0.1:
resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"
integrity sha1-TkMekrEalzFjaqH5yNHMvP2reN8=
isomorphic-git@^1.8.2:
version "1.10.1"
resolved "https://registry.yarnpkg.com/isomorphic-git/-/isomorphic-git-1.10.1.tgz#2f3a3d2d41baf6a88e046a21e0527bc13a21d663"
integrity sha512-abbPpKkykIVDJ92rtYoD4AOuT5/7PABHR2fDBrsm7H0r2ZT+MGpPL/FynrEJM6nTcFSieaIDxnHNGhfHO/v+bA==
isomorphic-git@^1.24.0:
version "1.24.0"
resolved "https://registry.yarnpkg.com/isomorphic-git/-/isomorphic-git-1.24.0.tgz#d3c7487ba67724d63dec0158572cb33767298f4d"
integrity sha512-4wV95pUr9kGTRZWB9a266bHfD3QAZzWWLIPxlTou4tgOaz4WKmaMOMKKHywudzigsU8h7YwbXyBLE4OEaK8F9Q==
dependencies:
async-lock "^1.1.0"
clean-git-ref "^2.0.1"
@ -17407,7 +17400,7 @@ isomorphic-git@^1.8.2:
pify "^4.0.1"
readable-stream "^3.4.0"
sha.js "^2.4.9"
simple-get "^3.0.2"
simple-get "^4.0.1"
isomorphic-textencoder@1.0.1:
version "1.0.1"
@ -20072,11 +20065,6 @@ mimic-response@^1.0.0, mimic-response@^1.0.1:
resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-1.0.1.tgz#4923538878eef42063cb8a3e3b0798781487ab1b"
integrity sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==
mimic-response@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-2.1.0.tgz#d13763d35f613d09ec37ebb30bac0469c0ee8f43"
integrity sha512-wXqjST+SLt7R009ySCglWBCFpjUygmCIfD790/kVbiGmUgfYGuB14PiTd5DwVxSV4NcYHjzMkoj5LjQZwTQLEA==
mimic-response@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-3.1.0.tgz#2d1d59af9c1b129815accc2c46a022a5ce1fa3c9"
@ -25729,12 +25717,12 @@ simple-get@^2.5.1, simple-get@^2.7.0:
once "^1.3.1"
simple-concat "^1.0.0"
simple-get@^3.0.2:
version "3.1.1"
resolved "https://registry.yarnpkg.com/simple-get/-/simple-get-3.1.1.tgz#cc7ba77cfbe761036fbfce3d021af25fc5584d55"
integrity sha512-CQ5LTKGfCpvE1K0n2us+kuMPbk/q0EKl82s4aheV9oXjFEz6W/Y7oQFVJuU6QG77hRT4Ghb5RURteF5vnWjupA==
simple-get@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/simple-get/-/simple-get-4.0.1.tgz#4a39db549287c979d352112fa03fd99fd6bc3543"
integrity sha512-brv7p5WgH0jmQJr1ZDDfKDOSeWWg+OVypG99A/5vYGPqJ6pxiaHLy8nxtFjBA7oMa01ebA9gfh1uMCFqOuXxvA==
dependencies:
decompress-response "^4.2.0"
decompress-response "^6.0.0"
once "^1.3.1"
simple-concat "^1.0.0"

Loading…
Cancel
Save