open folder

rdesktop
bunsenstraat 1 year ago committed by filip mertens
parent eaefe37861
commit b888c2b894
  1. 5
      apps/remixdesktop/src/main.ts
  2. 58
      apps/remixdesktop/src/plugins/configPlugin.ts
  3. 14
      apps/remixdesktop/src/plugins/fsPlugin.ts
  4. 37
      apps/remixdesktop/src/utils/config.ts
  5. 6
      libs/remix-ui/workspace/src/lib/actions/index.ts
  6. 4
      libs/remix-ui/workspace/src/lib/actions/workspace.ts
  7. 1
      libs/remix-ui/workspace/src/lib/contexts/index.ts
  8. 11
      libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx
  9. 12
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -13,6 +13,9 @@ if (
isPackaged = true; isPackaged = true;
} }
// get system home dir
const homeDir = app.getPath('userData')
export let mainWindow: BrowserWindow; export let mainWindow: BrowserWindow;
export const createWindow = async (): Promise<void> => { export const createWindow = async (): Promise<void> => {
// Create the browser window. // Create the browser window.
@ -27,7 +30,7 @@ export const createWindow = async (): Promise<void> => {
// and load the index.html of the app. // and load the index.html of the app.
mainWindow.loadURL( mainWindow.loadURL(
process.env.NODE_ENV === 'production' || isPackaged? `file://${__dirname}/remix-ide/index.html` : process.env.NODE_ENV === 'production' || isPackaged? `file://${__dirname}/remix-ide/index.html` :
'http://localhost:8080') 'http://localhost:8080?opendir=' + homeDir)
mainWindow.maximize(); mainWindow.maximize();

@ -0,0 +1,58 @@
import { ElectronBasePlugin, ElectronBasePluginClient } from "@remixproject/plugin-electron"
import { Profile } from "@remixproject/plugin-utils";
const profile: Profile = {
displayName: 'electronconfig',
name: 'electronconfig',
description: 'Electron Config'
}
export class ConfigPlugin extends ElectronBasePlugin {
clients: ConfigPluginClient[] = []
constructor() {
super(profile, clientProfile, ConfigPluginClient)
this.methods = [...super.methods, 'writeConfig', 'readConfig']
}
async writeConfig(webContentsId: any, data: any): Promise<void> {
const client = this.clients.find(c => c.webContentsId === webContentsId)
if (client) {
client.writeConfig(data)
}
}
async readConfig(webContentsId: any): Promise<any> {
const client = this.clients.find(c => c.webContentsId === webContentsId)
if (client) {
return client.readConfig()
}
}
}
const clientProfile: Profile = {
name: 'electronconfig',
displayName: 'electronconfig',
description: 'Electron Config',
methods: ['writeConfig', 'readConfig']
}
class ConfigPluginClient extends ElectronBasePluginClient {
constructor(webContentsId: number, profile: Profile) {
super(webContentsId, profile)
this.onload(() => {
//console.log('config client onload')
})
}
async writeConfig(data: any): Promise<void> {
}
async readConfig(): Promise<any> {
}
}

@ -26,7 +26,7 @@ export class FSPlugin extends ElectronBasePlugin {
openFolder(webContentsId: any): void { openFolder(webContentsId: any): void {
const client = this.clients.find(c => c.webContentsId === webContentsId) const client = this.clients.find(c => c.webContentsId === webContentsId)
if (client) { if (client) {
client.setWorkingDir() client.openFolder()
} }
} }
@ -36,7 +36,7 @@ const clientProfile: Profile = {
name: 'fs', name: 'fs',
displayName: 'fs', displayName: 'fs',
description: 'fs', description: 'fs',
methods: ['readdir', 'readFile', 'writeFile', 'mkdir', 'rmdir', 'unlink', 'rename', 'stat', 'lstat', 'exists', 'currentPath', 'watch', 'closeWatch', 'setWorkingDir'] methods: ['readdir', 'readFile', 'writeFile', 'mkdir', 'rmdir', 'unlink', 'rename', 'stat', 'lstat', 'exists', 'currentPath', 'watch', 'closeWatch', 'setWorkingDir', 'openFolder']
} }
class FSPluginClient extends ElectronBasePluginClient { class FSPluginClient extends ElectronBasePluginClient {
@ -145,9 +145,9 @@ class FSPluginClient extends ElectronBasePluginClient {
if (this.watcher) this.watcher.close() if (this.watcher) this.watcher.close()
} }
async setWorkingDir(): Promise<void> { async openFolder(): Promise<void> {
const dirs = dialog.showOpenDialogSync(this.window, { const dirs = dialog.showOpenDialogSync(this.window, {
properties: ['openDirectory'] properties: ['openDirectory', 'createDirectory', "showHiddenFiles"]
}) })
if (dirs && dirs.length > 0) { if (dirs && dirs.length > 0) {
this.workingDir = dirs[0] this.workingDir = dirs[0]
@ -156,6 +156,12 @@ class FSPluginClient extends ElectronBasePluginClient {
} }
async setWorkingDir(path: string): Promise<void> {
console.log('setWorkingDir', path)
this.workingDir = path
this.emit('workingDirChanged', path)
}
fixPath(path: string): string { fixPath(path: string): string {
if (path) { if (path) {
if (path.startsWith('/')) { if (path.startsWith('/')) {

@ -0,0 +1,37 @@
import fs from 'fs'
import os from 'os'
import path from 'path'
const cacheDir = path.join(os.homedir(), '.cache_remix_ide')
try {
if (!fs.existsSync(cacheDir)) {
fs.mkdirSync(cacheDir)
}
if(!fs.existsSync(cacheDir + '/remixdesktop.json')) {
fs.writeFileSync(cacheDir + '/remixdesktop.json', JSON.stringify({}))
}
} catch (e) {
}
export const writeConfig = (data: any) => {
const cache = readConfig()
try {
fs.writeFileSync(cacheDir + '/remixdesktop.json', JSON.stringify({ ...cache, ...data }))
} catch (e) {
console.error('Can\'t write config file', e)
}
}
export const readConfig = () => {
if (fs.existsSync(cacheDir + '/remixdesktop.json')) {
try {
// read the cache file
const cache = fs.readFileSync(cacheDir + '/remixdesktop.json')
const data = JSON.parse(cache.toString())
return data
} catch (e) {
console.error('Can\'t read config file', e)
}
}
return undefined
}

@ -23,6 +23,7 @@ export type UrlParametersType = {
code: string, code: string,
url: string, url: string,
address: string address: string
opendir: string,
} }
const basicWorkspaceInit = async (workspaces: { name: string; isGitRepo: boolean; }[], workspaceProvider) => { const basicWorkspaceInit = async (workspaces: { name: string; isGitRepo: boolean; }[], workspaceProvider) => {
@ -120,7 +121,10 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
} else if (isElectron()) { } else if (isElectron()) {
console.log('isElectron initWorkspace') console.log('isElectron initWorkspace')
plugin.call('notification', 'toast', `connecting to electron...`) plugin.call('notification', 'toast', `connecting to electron...`)
if(params.opendir){
plugin.call('notification', 'toast', `opening ${params.opendir}...`)
plugin.call('fs', 'setWorkingDir', params.opendir)
}
plugin.setWorkspace({ name: 'electron', isLocalhost: false }) plugin.setWorkspace({ name: 'electron', isLocalhost: false })
dispatch(setCurrentWorkspace({ name: 'electron', isGitRepo: false })) dispatch(setCurrentWorkspace({ name: 'electron', isGitRepo: false }))

@ -747,6 +747,10 @@ export const checkoutRemoteBranch = async (branch: string, remote: string) => {
} }
} }
export const openElectronFolder = async () => {
await plugin.call('fs', 'openFolder')
}
export const hasLocalChanges = async () => { export const hasLocalChanges = async () => {
const filesStatus = await plugin.call('dGitProvider', 'status') const filesStatus = await plugin.call('dGitProvider', 'status')
const uncommittedFiles = getUncommittedFiles(filesStatus) const uncommittedFiles = getUncommittedFiles(filesStatus)

@ -46,6 +46,7 @@ export const FileSystemContext = createContext<{
dispatchCreateTsSolGithubAction: () => Promise<void>, dispatchCreateTsSolGithubAction: () => Promise<void>,
dispatchCreateSlitherGithubAction: () => Promise<void> dispatchCreateSlitherGithubAction: () => Promise<void>
dispatchCreateHelperScripts: (script: string) => Promise<void> dispatchCreateHelperScripts: (script: string) => Promise<void>
dispatchOpenElectronFolder: () => Promise<void>
}>(null) }>(null)

@ -8,7 +8,7 @@ import { browserReducer, browserInitialState } from '../reducers/workspace'
import { initWorkspace, fetchDirectory, removeInputField, deleteWorkspace, deleteAllWorkspaces, clearPopUp, publishToGist, createNewFile, setFocusElement, createNewFolder, import { initWorkspace, fetchDirectory, removeInputField, deleteWorkspace, deleteAllWorkspaces, clearPopUp, publishToGist, createNewFile, setFocusElement, createNewFolder,
deletePath, renamePath, downloadPath, copyFile, copyFolder, runScript, emitContextMenuEvent, handleClickFile, handleExpandPath, addInputField, createWorkspace, deletePath, renamePath, downloadPath, copyFile, copyFolder, runScript, emitContextMenuEvent, handleClickFile, handleExpandPath, addInputField, createWorkspace,
fetchWorkspaceDirectory, renameWorkspace, switchToWorkspace, uploadFile, uploadFolder, handleDownloadWorkspace, handleDownloadFiles, restoreBackupZip, cloneRepository, moveFile, moveFolder, fetchWorkspaceDirectory, renameWorkspace, switchToWorkspace, uploadFile, uploadFolder, handleDownloadWorkspace, handleDownloadFiles, restoreBackupZip, cloneRepository, moveFile, moveFolder,
showAllBranches, switchBranch, createNewBranch, checkoutRemoteBranch, createSolidityGithubAction, createTsSolGithubAction, createSlitherGithubAction, createHelperScripts showAllBranches, switchBranch, createNewBranch, checkoutRemoteBranch, createSolidityGithubAction, createTsSolGithubAction, createSlitherGithubAction, createHelperScripts, openElectronFolder
} from '../actions' } from '../actions'
import { Modal, WorkspaceProps, WorkspaceTemplate } from '../types' import { Modal, WorkspaceProps, WorkspaceTemplate } from '../types'
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
@ -187,6 +187,12 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
await createHelperScripts(script) await createHelperScripts(script)
} }
const dispatchOpenElectronFolder = async () => {
console.log('open electron folder')
await openElectronFolder()
}
useEffect(() => { useEffect(() => {
dispatchInitWorkspace() dispatchInitWorkspace()
}, []) }, [])
@ -304,7 +310,8 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
dispatchCreateSolidityGithubAction, dispatchCreateSolidityGithubAction,
dispatchCreateTsSolGithubAction, dispatchCreateTsSolGithubAction,
dispatchCreateSlitherGithubAction, dispatchCreateSlitherGithubAction,
dispatchCreateHelperScripts dispatchCreateHelperScripts,
dispatchOpenElectronFolder
} }
return ( return (
<FileSystemContext.Provider value={value}> <FileSystemContext.Provider value={value}>

@ -111,8 +111,7 @@ export function Workspace () {
setCurrentWorkspace(global.fs.browser.currentWorkspace) setCurrentWorkspace(global.fs.browser.currentWorkspace)
global.dispatchFetchWorkspaceDirectory(ROOT_PATH) global.dispatchFetchWorkspaceDirectory(ROOT_PATH)
} }
else else {
{
setCurrentWorkspace(NO_WORKSPACE) setCurrentWorkspace(NO_WORKSPACE)
} }
@ -493,6 +492,10 @@ export function Workspace () {
global.dispatchPublishToGist(path, type) global.dispatchPublishToGist(path, type)
} }
const openFolderElectron = async () => {
global.dispatchOpenElectronFolder()
}
const editModeOn = (path: string, type: string, isNew = false) => { const editModeOn = (path: string, type: string, isNew = false) => {
if (global.fs.readonly) return global.toast('Cannot write/modify file system in read only mode.') if (global.fs.readonly) return global.toast('Cannot write/modify file system in read only mode.')
@ -793,6 +796,9 @@ export function Workspace () {
</div> </div>
</header> </header>
</div> </div>
{isElectron() && global.fs.browser.isSuccessfulDirectory ? null :
<div onClick={openFolderElectron} className='btn btn-primary'>Open Folder</div>
}
<div className='h-100 remixui_fileExplorerTree' onFocus={() => { toggleDropdown(false) }}> <div className='h-100 remixui_fileExplorerTree' onFocus={() => { toggleDropdown(false) }}>
<div className='h-100'> <div className='h-100'>
{(global.fs.browser.isRequestingWorkspace || global.fs.browser.isRequestingCloning) && <div className="text-center py-5"><i className="fas fa-spinner fa-pulse fa-2x"></i></div>} {(global.fs.browser.isRequestingWorkspace || global.fs.browser.isRequestingCloning) && <div className="text-center py-5"><i className="fas fa-spinner fa-pulse fa-2x"></i></div>}
@ -850,6 +856,7 @@ export function Workspace () {
/> />
</div> </div>
} }
{global.fs.localhost.isRequestingLocalhost && <div className="text-center py-5"><i className="fas fa-spinner fa-pulse fa-2x"></i></div>} {global.fs.localhost.isRequestingLocalhost && <div className="text-center py-5"><i className="fas fa-spinner fa-pulse fa-2x"></i></div>}
{(global.fs.mode === 'localhost' && global.fs.localhost.isSuccessfulLocalhost) && {(global.fs.mode === 'localhost' && global.fs.localhost.isSuccessfulLocalhost) &&
<div className='h-100 filesystemexplorer remixui_treeview'> <div className='h-100 filesystemexplorer remixui_treeview'>
@ -907,6 +914,7 @@ export function Workspace () {
</div> </div>
</div> </div>
</div> </div>
</div> </div>
{ {
selectedWorkspace && selectedWorkspace &&

Loading…
Cancel
Save