open folder

rdesktop^2
bunsenstraat 1 year ago
parent 274a3c7cbd
commit b8ed5556cb
  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;
}
// get system home dir
const homeDir = app.getPath('userData')
export let mainWindow: BrowserWindow;
export const createWindow = async (): Promise<void> => {
// Create the browser window.
@ -27,7 +30,7 @@ export const createWindow = async (): Promise<void> => {
// and load the index.html of the app.
mainWindow.loadURL(
process.env.NODE_ENV === 'production' || isPackaged? `file://${__dirname}/remix-ide/index.html` :
'http://localhost:8080')
'http://localhost:8080?opendir=' + homeDir)
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 {
const client = this.clients.find(c => c.webContentsId === webContentsId)
if (client) {
client.setWorkingDir()
client.openFolder()
}
}
@ -36,7 +36,7 @@ const clientProfile: Profile = {
name: 'fs',
displayName: '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 {
@ -145,9 +145,9 @@ class FSPluginClient extends ElectronBasePluginClient {
if (this.watcher) this.watcher.close()
}
async setWorkingDir(): Promise<void> {
async openFolder(): Promise<void> {
const dirs = dialog.showOpenDialogSync(this.window, {
properties: ['openDirectory']
properties: ['openDirectory', 'createDirectory', "showHiddenFiles"]
})
if (dirs && dirs.length > 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 {
if (path) {
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,
url: string,
address: string
opendir: string,
}
const basicWorkspaceInit = async (workspaces: { name: string; isGitRepo: boolean; }[], workspaceProvider) => {
@ -120,7 +121,10 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
} else if (isElectron()) {
console.log('isElectron initWorkspace')
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 })
dispatch(setCurrentWorkspace({ name: 'electron', isGitRepo: false }))

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

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

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

@ -109,8 +109,7 @@ export function Workspace () {
setCurrentWorkspace(global.fs.browser.currentWorkspace)
global.dispatchFetchWorkspaceDirectory(ROOT_PATH)
}
else
{
else {
setCurrentWorkspace(NO_WORKSPACE)
}
@ -487,6 +486,10 @@ export function Workspace () {
global.dispatchPublishToGist(path, type)
}
const openFolderElectron = async () => {
global.dispatchOpenElectronFolder()
}
const editModeOn = (path: string, type: string, isNew = false) => {
if (global.fs.readonly) return global.toast('Cannot write/modify file system in read only mode.')
@ -787,6 +790,9 @@ export function Workspace () {
</div>
</header>
</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'>
{(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>}
@ -844,6 +850,7 @@ export function Workspace () {
/>
</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) &&
<div className='h-100 filesystemexplorer remixui_treeview'>
@ -901,6 +908,7 @@ export function Workspace () {
</div>
</div>
</div>
</div>
{
selectedWorkspace &&

Loading…
Cancel
Save