rdesktop
filip mertens 1 year ago
parent 429e845785
commit 5728f3c7db
  1. 2
      apps/1test/src/electron/fsPlugin.ts
  2. 127
      apps/1test/src/index.ts
  3. 2
      apps/1test/src/remix/fsPlugin.ts
  4. 2
      apps/1test/src/remix/gitPlugin.ts
  5. 5
      apps/remix-ide/src/app.js
  6. 133
      apps/remix-ide/src/app/files/dgitProvider.js
  7. 4
      apps/remix-ide/src/app/files/fileManager.ts
  8. 31
      apps/remix-ide/src/app/plugins/fsPlugin.ts
  9. 19
      apps/remix-ide/src/app/plugins/isoGitPlugin.ts
  10. 11
      apps/remix-ide/src/app/tabs/theme-module.js
  11. 10
      apps/remixdesktop/src/engine.ts
  12. 22
      apps/remixdesktop/src/plugins/fsPlugin.ts
  13. 15
      apps/remixdesktop/src/plugins/gitPlugin.ts
  14. 241
      apps/remixdesktop/src/plugins/isoGitPlugin.ts
  15. 0
      apps/remixdesktop/src/plugins/xtermPlugin.ts
  16. 2
      apps/remixdesktop/src/preload.ts
  17. 1
      libs/remix-ui/workspace/src/lib/actions/index.ts

@ -35,7 +35,7 @@ const clientProfile: Profile = {
class FSPluginClient extends ElectronBasePluginClient { class FSPluginClient extends ElectronBasePluginClient {
watcher: chokidar.FSWatcher watcher: chokidar.FSWatcher
workingDir: string = '/Volumes/bunsen/code/rmproject2/remix-project/apps/remix-ide/contracts/' workingDir: string = '/Volumes/bunsen/code/empty/'
constructor(webContentsId: number, profile: Profile) { constructor(webContentsId: number, profile: Profile) {
super(webContentsId, profile) super(webContentsId, profile)

@ -94,7 +94,7 @@ const menu = [shellMenu(commandKeys, execCommand)]
Menu.setApplicationMenu(Menu.buildFromTemplate(menu)) Menu.setApplicationMenu(Menu.buildFromTemplate(menu))
import fs from 'fs/promises' import fs from 'fs/promises'
import { readlink } from 'fs'; import { readlink, stat } from 'fs';
//const menu = Menu.buildFromTemplate(shellMenu([], undefined)) //const menu = Menu.buildFromTemplate(shellMenu([], undefined))
//Menu.setApplicationMenu(menu) //Menu.setApplicationMenu(menu)
@ -164,14 +164,18 @@ const myFS = {
} }
console.log('myFS', myFS) console.log('myFS', myFS)
import git, { CommitObject, ReadCommitResult } from 'isomorphic-git'
async function checkGit() { async function checkGit() {
const git = require('isomorphic-git');
const files = await git.statusMatrix({ fs: myFS, dir: '/Volumes/bunsen/code/rmproject2/remix-project' });
const files = await git.statusMatrix({ fs: myFS, dir: '/Volumes/bunsen/code/rmproject2/remix-project', filepaths: ['apps/1test/src/index.ts'] });
console.log('GIT', files) console.log('GIT', files)
} }
//checkGit()
/*
setInterval(() => { setInterval(() => {
const startTime = Date.now() const startTime = Date.now()
@ -181,3 +185,118 @@ checkGit()
}) })
}, 3000) }, 3000)
*/
/*
git.add({ fs: myFS, dir: '/Volumes/bunsen/code/rmproject2/remix-project', filepath: 'test.txt' }).then(() => {
console.log('git add')
}).catch((e: any) => {
console.log('git add error', e)
})
git.log({ fs: myFS, dir: '/Volumes/bunsen/code/rmproject2/remix-project', depth:10 }).then((log: any) => {
console.log('git log', log)
})
*/
// run a shell command
import { exec } from 'child_process';
import { promisify } from 'util';
const execAsync = promisify(exec);
const statusTransFormMatrix = (status: string) => {
switch (status) {
case '??':
return [0, 2, 0]
case 'A ':
return [0, 2, 2]
case 'M ':
return [1, 2, 2]
case 'MM':
return [1, 2, 3]
case ' M':
return [1, 0, 1]
case ' D':
return [0, 2, 0]
case 'D ':
return [1, 0, 0]
case 'AM':
return [0, 2, 3]
default:
return [-1, -1, -1]
}
}
execAsync('git status --porcelain -uall', { cwd: '/Volumes/bunsen/code/rmproject2/remix-project' }).then(async (result: any) => {
//console.log('git status --porcelain -uall', result.stdout)
// parse the result.stdout
const lines = result.stdout.split('\n')
const files: any = []
const fileNames: any = []
//console.log('lines', lines)
lines.forEach((line: string) => {
// get the first two characters of the line
const status = line.slice(0, 2)
const file = line.split(' ').pop()
//console.log('line', line)
if (status && file) {
fileNames.push(file)
files.push([
file,
...statusTransFormMatrix(status)
])
}
}
)
// sort files by first column
files.sort((a: any, b: any) => {
if (a[0] < b[0]) {
return -1
}
if (a[0] > b[0]) {
return 1
}
return 0
})
//console.log('files', files, files.length)
const iso = await git.statusMatrix({ fs: myFS, dir: '/Volumes/bunsen/code/rmproject2/remix-project', filepaths: fileNames });
//console.log('GIT', iso, iso.length)
})
git.log({ fs: myFS, dir: '/Volumes/bunsen/code/rmproject2/remix-project', depth:3 }).then((log: ReadCommitResult[]) => {
log.forEach((commit: ReadCommitResult) => {
console.log('commit', commit.commit.parent)
})
})
// exec git log --pretty=format:"%h - %an, %ar : %s" -n 10
execAsync(`git log --pretty=format:'{ "oid":"%H", "message":"%s", "author":"%an", "email": "%ae", "timestamp":"%at", "tree": "%T", "committer": "%cn", "committer-email": "%ce", "committer-timestamp": "%ct", "parent": "%P" }' -n 3`, { cwd: '/Volumes/bunsen/code/rmproject2/remix-project' }).then(async (result: any) =>{
//console.log('git log', result.stdout)
const lines = result.stdout.split('\n')
const commits: ReadCommitResult[] = []
lines.forEach((line: string) => {
console.log('line', line)
const data = JSON.parse(line)
let commit:ReadCommitResult = {} as ReadCommitResult
commit.oid = data.oid
commit.commit = {} as CommitObject
commit.commit.message = data.message
commit.commit.tree = data.tree
commit.commit.committer = {} as any
commit.commit.committer.name = data.committer
commit.commit.committer.email = data['committer-email']
commit.commit.committer.timestamp = data['committer-timestamp']
commit.commit.author = {} as any
commit.commit.author.name = data.author
commit.commit.author.email = data.email
commit.commit.author.timestamp = data.timestamp
commit.commit.parent = [data.parent]
console.log('commit', commit)
commits.push(commit)
})
})

@ -1,6 +1,6 @@
import { ElectronPlugin } from './lib/electronPlugin'; import { ElectronPlugin } from './lib/electronPlugin';
let workingDir = '/Volumes/bunsen/code/rmproject2/remix-project/apps/remix-ide/contracts/' let workingDir = '/Volumes/bunsen/code/empty/'
const fixPath = (path: string) => { const fixPath = (path: string) => {
/* /*

@ -9,4 +9,6 @@ export class gitPlugin extends ElectronPlugin {
}) })
this.methods = ['log', 'status', 'add', 'commit', 'push', 'pull', 'clone', 'checkout', 'branch', 'merge', 'reset', 'revert', 'diff', 'stash', 'apply', 'cherryPick', 'rebase', 'tag', 'fetch', 'remote', 'config', 'show', 'init', 'help', 'version'] this.methods = ['log', 'status', 'add', 'commit', 'push', 'pull', 'clone', 'checkout', 'branch', 'merge', 'reset', 'revert', 'diff', 'stash', 'apply', 'cherryPick', 'rebase', 'tag', 'fetch', 'remote', 'config', 'show', 'init', 'help', 'version']
} }
} }

@ -46,6 +46,7 @@ import { CodeFormat } from './app/plugins/code-format'
import { SolidityUmlGen } from './app/plugins/solidity-umlgen' import { SolidityUmlGen } from './app/plugins/solidity-umlgen'
import { ContractFlattener } from './app/plugins/contractFlattener' import { ContractFlattener } from './app/plugins/contractFlattener'
import { fsPlugin } from './app/plugins/fsPlugin' import { fsPlugin } from './app/plugins/fsPlugin'
import { isoGitPlugin } from './app/plugins/isoGitPlugin'
const isElectron = require('is-electron') const isElectron = require('is-electron')
@ -318,6 +319,8 @@ class AppComponent {
if (isElectron()) { if (isElectron()) {
const FSPlugin = new fsPlugin() const FSPlugin = new fsPlugin()
this.engine.register([FSPlugin]) this.engine.register([FSPlugin])
const isoGit = new isoGitPlugin()
this.engine.register([isoGit])
} }
// LAYOUT & SYSTEM VIEWS // LAYOUT & SYSTEM VIEWS
@ -436,7 +439,7 @@ class AppComponent {
await this.appManager.activatePlugin(['solidity-script']) await this.appManager.activatePlugin(['solidity-script'])
if(isElectron()){ if(isElectron()){
await this.appManager.activatePlugin(['fs']) await this.appManager.activatePlugin(['fs', 'isogit'])
} }
this.appManager.on( this.appManager.on(

@ -49,7 +49,6 @@ class DGitProvider extends Plugin {
} }
async onActivation() { async onActivation() {
} }
async getGitConfig() { async getGitConfig() {
@ -86,6 +85,14 @@ class DGitProvider extends Plugin {
} }
async init(input) { async init(input) {
if(isElectron()) {
await this.call('isogit', 'init', {
defaultBranch: (input && input.branch) || 'main'
})
this.emit('init')
return
}
await git.init({ await git.init({
...await this.getGitConfig(), ...await this.getGitConfig(),
defaultBranch: (input && input.branch) || 'main' defaultBranch: (input && input.branch) || 'main'
@ -94,6 +101,13 @@ class DGitProvider extends Plugin {
} }
async status(cmd) { async status(cmd) {
if (isElectron()) {
const status = await this.call('isogit', 'status', cmd)
console.log('STATUS', status)
return status
}
console.log('status') console.log('status')
const status = await git.statusMatrix({ const status = await git.statusMatrix({
...await this.getGitConfig(), ...await this.getGitConfig(),
@ -104,25 +118,42 @@ class DGitProvider extends Plugin {
} }
async add(cmd) { async add(cmd) {
if (isElectron()) {
await this.call('isogit', 'add', cmd)
} else {
await git.add({ await git.add({
...await this.getGitConfig(), ...await this.getGitConfig(),
...cmd ...cmd
}) })
}
this.emit('add') this.emit('add')
} }
async rm(cmd) { async rm(cmd) {
if (isElectron()) {
await this.call('isogit', 'rm', cmd)
} else {
await git.remove({ await git.remove({
...await this.getGitConfig(), ...await this.getGitConfig(),
...cmd ...cmd
}) })
} this.emit('rm')
}
}
async checkout(cmd, refresh = true) { async checkout(cmd, refresh = true) {
if (isElectron()) {
await this.call('isogit', 'checkout', cmd)
} else {
await git.checkout({ await git.checkout({
...await this.getGitConfig(), ...await this.getGitConfig(),
...cmd ...cmd
}) })
}
if (refresh) { if (refresh) {
setTimeout(async () => { setTimeout(async () => {
await this.call('fileManager', 'refresh') await this.call('fileManager', 'refresh')
@ -132,14 +163,30 @@ class DGitProvider extends Plugin {
} }
async log(cmd) { async log(cmd) {
if (isElectron()) {
const status = await this.call('isogit', 'log', {
...cmd,
depth: 10
})
console.log('STATUS', status)
return status
}
const status = await git.log({ const status = await git.log({
...await this.getGitConfig(), ...await this.getGitConfig(),
...cmd ...cmd,
depth: 10
}) })
return status return status
} }
async remotes(config) { async remotes(config) {
if (isElectron()) {
return await this.call('isogit', 'remotes', config)
}
let remotes = [] let remotes = []
try { try {
remotes = await git.listRemotes({ ...config ? config : await this.getGitConfig() }) remotes = await git.listRemotes({ ...config ? config : await this.getGitConfig() })
@ -150,10 +197,16 @@ class DGitProvider extends Plugin {
} }
async branch(cmd, refresh = true) { async branch(cmd, refresh = true) {
const status = await git.branch({
let status
if (isElectron()) {
status = await this.call('isogit', 'branch', cmd)
} else {
status = await git.branch({
...await this.getGitConfig(), ...await this.getGitConfig(),
...cmd ...cmd
}) })
}
if (refresh) { if (refresh) {
setTimeout(async () => { setTimeout(async () => {
await this.call('fileManager', 'refresh') await this.call('fileManager', 'refresh')
@ -164,6 +217,15 @@ class DGitProvider extends Plugin {
} }
async currentbranch(config) { async currentbranch(config) {
console.log('currentbranch')
if (isElectron()) {
console.log('currentbranch electron')
return await this.call('isogit', 'currentbranch')
}
try { try {
const defaultConfig = await this.getGitConfig() const defaultConfig = await this.getGitConfig()
const cmd = config ? defaultConfig ? { ...defaultConfig, ...config } : config : defaultConfig const cmd = config ? defaultConfig ? { ...defaultConfig, ...config } : config : defaultConfig
@ -176,6 +238,11 @@ class DGitProvider extends Plugin {
} }
async branches(config) { async branches(config) {
if (isElectron()) {
return await this.call('isogit', 'branches', config)
}
try { try {
const defaultConfig = await this.getGitConfig() const defaultConfig = await this.getGitConfig()
const cmd = config ? defaultConfig ? { ...defaultConfig, ...config } : config : defaultConfig const cmd = config ? defaultConfig ? { ...defaultConfig, ...config } : config : defaultConfig
@ -194,6 +261,18 @@ class DGitProvider extends Plugin {
} }
async commit(cmd) { async commit(cmd) {
if (isElectron()) {
try {
await this.call('isogit', 'init')
const sha = await this.call('isogit', 'commit', cmd)
this.emit('commit')
return sha
} catch (e) {
throw new Error(e)
}
} else {
await this.init() await this.init()
try { try {
const sha = await git.commit({ const sha = await git.commit({
@ -206,8 +285,14 @@ class DGitProvider extends Plugin {
throw new Error(e) throw new Error(e)
} }
} }
}
async lsfiles(cmd) { async lsfiles(cmd) {
if (isElectron()) {
return await this.call('isogit', 'lsfiles', cmd)
}
const filesInStaging = await git.listFiles({ const filesInStaging = await git.listFiles({
...await this.getGitConfig(), ...await this.getGitConfig(),
...cmd ...cmd
@ -216,6 +301,11 @@ class DGitProvider extends Plugin {
} }
async resolveref(cmd) { async resolveref(cmd) {
if (isElectron()) {
return await this.call('isogit', 'resolveref', cmd)
}
const oid = await git.resolveRef({ const oid = await git.resolveRef({
...await this.getGitConfig(), ...await this.getGitConfig(),
...cmd ...cmd
@ -295,9 +385,16 @@ class DGitProvider extends Plugin {
email: input.email email: input.email
}, },
...await this.parseInput(input), ...await this.parseInput(input),
...await this.getGitConfig()
}
if (isElectron()) {
return await this.call('isogit', 'push', cmd)
} }
return await git.push(cmd)
return await git.push({
...await this.getGitConfig(),
...cmd
})
} }
async pull(input) { async pull(input) {
@ -310,9 +407,18 @@ class DGitProvider extends Plugin {
}, },
remote: input.remote, remote: input.remote,
...await this.parseInput(input), ...await this.parseInput(input),
...await this.getGitConfig()
}
let result
if (isElectron()) {
result = await this.call('isogit', 'pull', cmd)
}
else {
result = await git.pull({
...await this.getGitConfig(),
...cmd
})
} }
const result = await git.pull(cmd)
setTimeout(async () => { setTimeout(async () => {
await this.call('fileManager', 'refresh') await this.call('fileManager', 'refresh')
}, 1000) }, 1000)
@ -329,9 +435,16 @@ class DGitProvider extends Plugin {
}, },
remote: input.remote, remote: input.remote,
...await this.parseInput(input), ...await this.parseInput(input),
...await this.getGitConfig()
} }
const result = await git.fetch(cmd) let result
if (isElectron()) {
result = await this.call('isogit', 'fetch', cmd)
} else {
result = await git.fetch({
...await this.getGitConfig(),
...cmd
})
}
setTimeout(async () => { setTimeout(async () => {
await this.call('fileManager', 'refresh') await this.call('fileManager', 'refresh')
}, 1000) }, 1000)

@ -195,8 +195,8 @@ class FileManager extends Plugin {
path = this.normalize(path) path = this.normalize(path)
path = this.limitPluginScope(path) path = this.limitPluginScope(path)
path = this.getPathFromUrl(path).file path = this.getPathFromUrl(path).file
await this._handleExists(path, `Cannot open file ${path}`) //await this._handleExists(path, `Cannot open file ${path}`)
await this._handleIsFile(path, `Cannot open file ${path}`) //await this._handleIsFile(path, `Cannot open file ${path}`)
await this.openFile(path) await this.openFile(path)
} }

@ -1,6 +1,4 @@
import { ElectronPlugin } from '@remixproject/engine-electron'; import { ElectronPlugin } from '@remixproject/engine-electron';
import once from 'just-once';
let workingDir = null let workingDir = null
@ -8,15 +6,6 @@ const fixPath = (path: string) => {
return path return path
} }
function wrapCallback(opts, cb) {
if (typeof opts === "function") {
cb = opts;
}
cb = once(cb);
const resolve = (...args) => cb(null, ...args)
return [resolve, cb];
}
export class fsPlugin extends ElectronPlugin { export class fsPlugin extends ElectronPlugin {
public fs: any public fs: any
public fsSync: any public fsSync: any
@ -58,9 +47,9 @@ export class fsPlugin extends ElectronPlugin {
}, },
readdir: async (path: string) => { readdir: async (path: string) => {
path = fixPath(path) path = fixPath(path)
console.log('readdir', path) //console.log('readdir', path)
const files = await this.call('fs', 'readdir', path) const files = await this.call('fs', 'readdir', path)
console.log('readdir', path, files) //console.log('readdir', path, files)
return files return files
}, },
unlink: async (path: string) => { unlink: async (path: string) => {
@ -73,13 +62,13 @@ export class fsPlugin extends ElectronPlugin {
}, },
readFile: async (path: string, options) => { readFile: async (path: string, options) => {
try { try {
console.log('readFile', path, options) //console.log('readFile', path, options)
path = fixPath(path) path = fixPath(path)
const file = await this.call('fs', 'readFile', path, options) const file = await this.call('fs', 'readFile', path, options)
console.log('readFile', path, file) //console.log('readFile', path, file)
return file return file
} catch (e) { } catch (e) {
console.log('readFile error', e) //console.log('readFile error', e)
return undefined return undefined
} }
} }
@ -99,10 +88,10 @@ export class fsPlugin extends ElectronPlugin {
if(!stat) return undefined if(!stat) return undefined
stat.isDirectory = () => stat.isDirectoryValue stat.isDirectory = () => stat.isDirectoryValue
stat.isFile = () => !stat.isDirectoryValue stat.isFile = () => !stat.isDirectoryValue
//console.log('stat', path, stat) ////console.log('stat', path, stat)
return stat return stat
} catch (e) { } catch (e) {
console.log('stat error', e) //console.log('stat error', e)
return undefined return undefined
} }
}, },
@ -115,7 +104,7 @@ export class fsPlugin extends ElectronPlugin {
stat.isFile = () => !stat.isDirectoryValue stat.isFile = () => !stat.isDirectoryValue
return stat return stat
} catch (e) { } catch (e) {
console.log('lstat error', e) //console.log('lstat error', e)
return undefined return undefined
} }
}, },
@ -145,12 +134,12 @@ export class fsPlugin extends ElectronPlugin {
async onActivation() { async onActivation() {
console.log('fsPluginClient onload', this.fs); //console.log('fsPluginClient onload', this.fs);
(window as any).remixFileSystem = this.fs; (window as any).remixFileSystem = this.fs;
this.on('fs', 'workingDirChanged', async (path: string) => { this.on('fs', 'workingDirChanged', async (path: string) => {
console.log('change working dir', path) //console.log('change working dir', path)
workingDir = path workingDir = path
await this.call('fileManager', 'refresh') await this.call('fileManager', 'refresh')
}) })

@ -0,0 +1,19 @@
import { ElectronPlugin } from '@remixproject/engine-electron';
export class isoGitPlugin extends ElectronPlugin {
constructor() {
super({
displayName: 'isogit',
name: 'isogit',
description: 'isogit',
})
this.methods = []
}
onActivation(): void {
}
}

@ -59,6 +59,10 @@ export class ThemeModule extends Plugin {
* @return {{ name: string, quality: string, url: string }} - The active theme * @return {{ name: string, quality: string, url: string }} - The active theme
*/ */
currentTheme() { currentTheme() {
if (isElectron()) {
const theme = 'https://remix.ethereum.org/' + this.themes[this.active].url.replace(/\\/g, '/').replace(/\/\//g, '/').replace(/\/$/g, '')
return { ...this.themes[this.active], url: theme }
}
return this.themes[this.active] return this.themes[this.active]
} }
@ -119,11 +123,14 @@ export class ThemeModule extends Plugin {
// TODO: Only keep `this.emit` (issue#2210) // TODO: Only keep `this.emit` (issue#2210)
console.log('themeChanged', nextTheme) console.log('themeChanged', nextTheme)
if (isElectron()) { if (isElectron()) {
nextTheme.url = nextTheme.url = 'https://remix.ethereum.org/' + nextTheme.url.replace(/\\/g, '/').replace(/\/\//g, '/').replace(/\/$/g, '') const theme = 'https://remix.ethereum.org/' + nextTheme.url.replace(/\\/g, '/').replace(/\/\//g, '/').replace(/\/$/g, '')
} this.emit('themeChanged', { ...nextTheme, url: theme })
this.events.emit('themeChanged', { ...nextTheme, url: theme })
} else {
this.emit('themeChanged', nextTheme) this.emit('themeChanged', nextTheme)
this.events.emit('themeChanged', nextTheme) this.events.emit('themeChanged', nextTheme)
} }
}
/** /**
* fixes the invertion for images since this should be adjusted when we switch between dark/light qualified themes * fixes the invertion for images since this should be adjusted when we switch between dark/light qualified themes

@ -1,19 +1,23 @@
import { Engine, PluginManager } from '@remixproject/engine'; import { Engine, PluginManager } from '@remixproject/engine';
import { ipcMain } from 'electron'; import { ipcMain } from 'electron';
import { FSPlugin } from './fsPlugin'; import { FSPlugin } from './plugins/fsPlugin';
import { GitPlugin } from './gitPlugin'; import { GitPlugin } from './plugins/gitPlugin';
import { app } from 'electron'; import { app } from 'electron';
import { XtermPlugin } from './xtermPlugin'; import { XtermPlugin } from './plugins/xtermPlugin';
import git from 'isomorphic-git'
import { IsoGitPlugin } from './plugins/isoGitPlugin';
const engine = new Engine() const engine = new Engine()
const appManager = new PluginManager() const appManager = new PluginManager()
const fsPlugin = new FSPlugin() const fsPlugin = new FSPlugin()
const gitPlugin = new GitPlugin() const gitPlugin = new GitPlugin()
const xtermPlugin = new XtermPlugin() const xtermPlugin = new XtermPlugin()
const isoGitPlugin = new IsoGitPlugin()
engine.register(appManager) engine.register(appManager)
engine.register(fsPlugin) engine.register(fsPlugin)
engine.register(gitPlugin) engine.register(gitPlugin)
engine.register(xtermPlugin) engine.register(xtermPlugin)
engine.register(isoGitPlugin)
appManager.activatePlugin('fs') appManager.activatePlugin('fs')

@ -41,38 +41,38 @@ const clientProfile: Profile = {
class FSPluginClient extends ElectronBasePluginClient { class FSPluginClient extends ElectronBasePluginClient {
watcher: chokidar.FSWatcher watcher: chokidar.FSWatcher
workingDir: string = '/Volumes/bunsen/code/rmproject2/remix-project/apps/remix-ide/contracts/' workingDir: string = '/Volumes/bunsen/code/empty/'
constructor(webContentsId: number, profile: Profile) { constructor(webContentsId: number, profile: Profile) {
super(webContentsId, profile) super(webContentsId, profile)
this.onload(() => { this.onload(() => {
console.log('fsPluginClient onload') //console.log('fsPluginClient onload')
}) })
} }
async readdir(path: string): Promise<string[]> { async readdir(path: string): Promise<string[]> {
// call node fs.readdir // call node fs.readdir
console.log('readdir', path) //console.log('readdir', path)
if (!path) return [] if (!path) return []
const files = fs.readdir(this.fixPath(path)) const files = fs.readdir(this.fixPath(path))
return files return files
} }
async readFile(path: string, options: any): Promise<string | undefined> { async readFile(path: string, options: any): Promise<string | undefined> {
console.log('readFile', path, options) //console.log('readFile', path, options)
// hacky fix for TS error // hacky fix for TS error
if (!path) return undefined if (!path) return undefined
try { try {
return (fs as any).readFile(this.fixPath(path), options) return (fs as any).readFile(this.fixPath(path), options)
} catch (e) { } catch (e) {
console.log('readFile error', e) //console.log('readFile error', e)
return undefined return undefined
} }
} }
async writeFile(path: string, content: string, options: any): Promise<void> { async writeFile(path: string, content: string, options: any): Promise<void> {
console.log('writeFile', path, content, options) //console.log('writeFile', path, content, options)
return (fs as any).writeFile(this.fixPath(path), content, options) return (fs as any).writeFile(this.fixPath(path), content, options)
} }
@ -95,14 +95,14 @@ class FSPluginClient extends ElectronBasePluginClient {
async stat(path: string): Promise<any> { async stat(path: string): Promise<any> {
try { try {
const stat = await fs.stat(this.fixPath(path)) const stat = await fs.stat(this.fixPath(path))
//console.log('stat', path, stat) ////console.log('stat', path, stat)
const isDirectory = stat.isDirectory() const isDirectory = stat.isDirectory()
return { return {
...stat, ...stat,
isDirectoryValue: isDirectory isDirectoryValue: isDirectory
} }
} catch (e) { } catch (e) {
console.log('stat error', e) //console.log('stat error', e)
return undefined return undefined
} }
} }
@ -116,7 +116,7 @@ class FSPluginClient extends ElectronBasePluginClient {
isDirectoryValue: isDirectory isDirectoryValue: isDirectory
} }
} catch (e) { } catch (e) {
console.log('lstat error', e) //console.log('lstat error', e)
return undefined return undefined
} }
} }
@ -135,13 +135,13 @@ class FSPluginClient extends ElectronBasePluginClient {
if (this.watcher) this.watcher.close() if (this.watcher) this.watcher.close()
this.watcher = this.watcher =
chokidar.watch(this.fixPath(path)).on('change', (path, stats) => { chokidar.watch(this.fixPath(path)).on('change', (path, stats) => {
console.log('change', path, stats) //console.log('change', path, stats)
this.emit('change', path, stats) this.emit('change', path, stats)
}) })
} }
async closeWatch(): Promise<void> { async closeWatch(): Promise<void> {
console.log('closing Watcher', this.webContentsId) //console.log('closing Watcher', this.webContentsId)
if (this.watcher) this.watcher.close() if (this.watcher) this.watcher.close()
} }

@ -1,6 +1,5 @@
import { PluginClient } from "@remixproject/plugin"; import { PluginClient } from "@remixproject/plugin";
import { Profile } from "@remixproject/plugin-utils"; import { Profile } from "@remixproject/plugin-utils";
import { spawn } from "child_process";
import { ElectronBasePlugin, ElectronBasePluginClient } from "@remixproject/plugin-electron" import { ElectronBasePlugin, ElectronBasePluginClient } from "@remixproject/plugin-electron"
const profile: Profile = { const profile: Profile = {
@ -33,20 +32,8 @@ class GitPluginClient extends ElectronBasePluginClient {
}) })
} }
async log(path: string): Promise<string> { async log(cmd: any): Promise<any> {
const log = spawn('git', ['log'], {
cwd: path,
env: {
NODE_ENV: 'production',
PATH: process.env.PATH,
},
})
return new Promise((resolve, reject) => {
log.stdout.on('data', (data) => {
resolve(data.toString())
})
})
} }

@ -0,0 +1,241 @@
import { PluginClient } from "@remixproject/plugin";
import { Profile } from "@remixproject/plugin-utils";
import { ElectronBasePlugin, ElectronBasePluginClient } from "@remixproject/plugin-electron"
import fs from 'fs/promises'
import git from 'isomorphic-git'
const profile: Profile = {
name: 'isogit',
displayName: 'isogit',
description: 'isogit plugin',
}
export class IsoGitPlugin extends ElectronBasePlugin {
client: PluginClient
constructor() {
super(profile, clientProfile, IsoGitPluginClient)
}
}
const clientProfile: Profile = {
name: 'isogit',
displayName: 'isogit',
description: 'isogit plugin',
methods: ['init', 'localStorageUsed', 'addremote', 'delremote', 'remotes', 'fetch', 'clone', 'export', 'import', 'status', 'log', 'commit', 'add', 'remove', 'rm', 'lsfiles', 'readblob', 'resolveref', 'branches', 'branch', 'checkout', 'currentbranch', 'push', 'pin', 'pull', 'pinList', 'unPin', 'setIpfsConfig', 'zip', 'setItem', 'getItem']
}
class IsoGitPluginClient extends ElectronBasePluginClient {
workingDir: string = '/Volumes/bunsen/code/empty/'
constructor(webContentsId: number, profile: Profile) {
super(webContentsId, profile)
this.onload(() => {
console.log('IsoGit client onload')
this.on('fs' as any, 'workingDirChanged', async (path: string) => {
console.log('workingDirChanged', path)
this.workingDir = path
await this.status({
})
})
})
}
async getGitConfig () {
return {
fs,
dir: this.workingDir,
}
}
async status (cmd: any) {
console.log('status')
const status = await git.statusMatrix({
...await this.getGitConfig(),
...cmd
})
console.log('STATUS', status, await this.getGitConfig())
return status
}
async log (cmd: any) {
console.log('log')
const log = await git.log({
...await this.getGitConfig(),
...cmd
})
console.log('LOG', log)
return log
}
async add (cmd: any) {
console.log('add')
const add = await git.add({
...await this.getGitConfig(),
...cmd
})
console.log('ADD', add)
return add
}
async rm(cmd: any) {
console.log('rm')
const rm = await git.remove({
...await this.getGitConfig(),
...cmd
})
console.log('RM', rm)
return rm
}
async commit (cmd: any) {
console.log('commit')
const commit = await git.commit({
...await this.getGitConfig(),
...cmd
})
console.log('COMMIT', commit)
return commit
}
async init (input: any) {
await git.init({
...await this.getGitConfig(),
defaultBranch: (input && input.branch) || 'main'
})
}
async branch (cmd: any) {
console.log('branch')
const branch = await git.branch({
...await this.getGitConfig(),
...cmd
})
console.log('BRANCH', branch)
return branch
}
async lsfiles (cmd: any) {
console.log('lsfiles')
const lsfiles = await git.listFiles({
...await this.getGitConfig(),
...cmd
})
console.log('LSFILES', lsfiles)
return lsfiles
}
async resolveref (cmd: any) {
console.log('resolveref')
const resolveref = await git.resolveRef({
...await this.getGitConfig(),
...cmd
})
console.log('RESOLVEREF', resolveref)
return resolveref
}
async readblob (cmd: any) {
console.log('readblob')
const readblob = await git.readBlob({
...await this.getGitConfig(),
...cmd
})
console.log('READBLOB', readblob)
return readblob
}
async checkout (cmd: any) {
console.log('checkout')
const checkout = await git.checkout({
...await this.getGitConfig(),
...cmd
})
console.log('CHECKOUT', checkout)
return checkout
}
async push (cmd: any) {
console.log('push')
const push = await git.push({
...await this.getGitConfig(),
...cmd
})
console.log('PUSH', push)
return push
}
async pull (cmd: any) {
console.log('pull')
const pull = await git.pull({
...await this.getGitConfig(),
...cmd
})
console.log('PULL', pull)
return pull
}
async fetch(cmd: any) {
console.log('fetch')
const fetch = await git.fetch({
...await this.getGitConfig(),
...cmd
})
console.log('FETCH', fetch)
return fetch
}
remotes = async () => {
let remotes = []
remotes = await git.listRemotes({...await this.getGitConfig() })
console.log('remotes', remotes)
return remotes
}
async currentbranch() {
try {
const defaultConfig = await this.getGitConfig()
const name = await git.currentBranch(defaultConfig)
console.log('currentbranch', name)
return name
} catch (e) {
return ''
}
}
async branches() {
try {
let cmd: any = {...await this.getGitConfig()}
const remotes = await this.remotes()
let branches = []
branches = (await git.listBranches(cmd)).map((branch) => { return { remote: undefined, name: branch } })
for (const remote of remotes) {
cmd = {
...cmd,
remote: remote.remote
}
const remotebranches = (await git.listBranches(cmd)).map((branch) => { return { remote: remote.remote, name: branch } })
branches = [...branches, ...remotebranches]
}
console.log('branches', branches)
return branches
} catch (e) {
return []
}
}
}

@ -6,7 +6,7 @@ console.log('preload.ts')
/* preload script needs statically defined API for each plugin */ /* preload script needs statically defined API for each plugin */
const exposedPLugins = ['fs', 'git', 'xterm'] const exposedPLugins = ['fs', 'git', 'xterm', 'isogit']
console.log('preload.ts', process) console.log('preload.ts', process)
let webContentsId: number | undefined let webContentsId: number | undefined

@ -125,6 +125,7 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
dispatch(setCurrentWorkspace({ name: 'electron', isGitRepo: false })) dispatch(setCurrentWorkspace({ name: 'electron', isGitRepo: false }))
listenOnProviderEvents(electrOnProvider)(dispatch) listenOnProviderEvents(electrOnProvider)(dispatch)
listenOnPluginEvents(plugin)
dispatch(setMode('browser')) dispatch(setMode('browser'))
dispatch(fsInitializationCompleted()) dispatch(fsInitializationCompleted())
plugin.emit('workspaceInitializationCompleted') plugin.emit('workspaceInitializationCompleted')

Loading…
Cancel
Save