add gist support

gistdesktop
filip mertens 8 months ago
parent 0d49c573db
commit 70fd55e59a
  1. 6
      apps/remix-ide/src/app/plugins/remix-templates.ts
  2. 6
      apps/remixdesktop/src/plugins/templates.ts
  3. 26
      libs/remix-core-plugin/src/lib/gist-handler.ts
  4. 1
      libs/remix-ui/workspace/src/lib/actions/index.ts
  5. 1
      libs/remix-ui/workspace/src/lib/actions/workspace.ts

@ -5,7 +5,7 @@ const profile = {
name: 'remix-templates', name: 'remix-templates',
displayName: 'remix-templates', displayName: 'remix-templates',
description: 'Remix Templates plugin', description: 'Remix Templates plugin',
methods: ['getTemplate', 'loadTemplateInNewWindow'], methods: ['getTemplate', 'loadTemplateInNewWindow', 'loadFilesInNewWindow'],
} }
export class TemplatesPlugin extends Plugin { export class TemplatesPlugin extends Plugin {
@ -26,5 +26,9 @@ export class TemplatesPlugin extends Plugin {
const files = await this.getTemplate(template, opts) const files = await this.getTemplate(template, opts)
this.call('electronTemplates', 'loadTemplateInNewWindow', files) this.call('electronTemplates', 'loadTemplateInNewWindow', files)
} }
async loadFilesInNewWindow (files: any) {
this.call('electronTemplates', 'loadTemplateInNewWindow', files)
}
} }

@ -53,9 +53,15 @@ class TemplatesPluginClient extends ElectronBasePluginClient {
if (!folder.endsWith('/')) folder += '/' if (!folder.endsWith('/')) folder += '/'
await fs.mkdir(path.dirname(folder + file), { recursive: true }) await fs.mkdir(path.dirname(folder + file), { recursive: true })
if (typeof files[file] !== 'string' && files[file].content) {
await fs.writeFile(folder + files[file].filename, files[file].content, {
encoding: 'utf8',
})
} else {
await fs.writeFile(folder + file, files[file], { await fs.writeFile(folder + file, files[file], {
encoding: 'utf8' encoding: 'utf8'
}) })
}
} catch (error) { } catch (error) {
console.error(error) console.error(error)
} }

@ -115,23 +115,26 @@ export class GistHandler extends Plugin {
} }
const gistIdWorkspace = 'gist ' + gistId const gistIdWorkspace = 'gist ' + gistId
const workspaces = await this.call('filePanel', 'getWorkspaces') //const workspaces = await this.call('filePanel', 'getWorkspaces')
const found = workspaces.find((workspace) => workspace.name === gistIdWorkspace) //const found = workspaces.find((workspace) => workspace.name === gistIdWorkspace)
if (found) { //if (found) {
await this.call('notification', 'alert', { // await this.call('notification', 'alert', {
id: 'gistAlert', // id: 'gistAlert',
message: `workspace "${gistIdWorkspace}" already exists`, // message: `workspace "${gistIdWorkspace}" already exists`,
}) // })
return // return
} // }
await this.call('filePanel', 'createWorkspace', 'gist ' + gistId, '', true) //await this.call('filePanel', 'createWorkspace', 'gist ' + gistId, '', true)
await this.call('filePanel', 'switchToWorkspace', { name: 'gist ' + gistId, isLocalHost: false }) //await this.call('filePanel', 'switchToWorkspace', { name: 'gist ' + gistId, isLocalHost: false })
const obj: StringByString = {} const obj: StringByString = {}
Object.keys(data.files).forEach((element) => { Object.keys(data.files).forEach((element) => {
const path = element.replace(/\.\.\./g, '/') const path = element.replace(/\.\.\./g, '/')
obj['/' + path] = data.files[element] obj['/' + path] = data.files[element]
}) })
console.log(obj)
await this.call('remix-templates', 'loadFilesInNewWindow', obj)
/*
this.call('fileManager', 'setBatchFiles', obj, isElectron()? 'electron':'workspace', true, async (errorSavingFiles: any) => { this.call('fileManager', 'setBatchFiles', obj, isElectron()? 'electron':'workspace', true, async (errorSavingFiles: any) => {
if (errorSavingFiles) { if (errorSavingFiles) {
const modalContent = { const modalContent = {
@ -143,6 +146,7 @@ export class GistHandler extends Plugin {
this.call('notification', 'alert', modalContent) this.call('notification', 'alert', modalContent)
} }
}) })
*/
}) })
} }
} }

@ -185,6 +185,7 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
if (params.opendir) { if (params.opendir) {
params.opendir = decodeURIComponent(params.opendir) params.opendir = decodeURIComponent(params.opendir)
plugin.call('notification', 'toast', `opening ${params.opendir}...`) plugin.call('notification', 'toast', `opening ${params.opendir}...`)
console.log('opening', params.opendir)
await plugin.call('fs', 'setWorkingDir', params.opendir) await plugin.call('fs', 'setWorkingDir', params.opendir)
} }
const currentPath = await plugin.call('fs', 'getWorkingDir') const currentPath = await plugin.call('fs', 'getWorkingDir')

@ -134,6 +134,7 @@ export const createWorkspace = async (
isGitRepo: boolean = false, isGitRepo: boolean = false,
createCommit: boolean = true createCommit: boolean = true
) => { ) => {
console.log('createWorkspace', workspaceName, workspaceTemplateName, opts, isEmpty, isGitRepo, createCommit)
if (plugin.registry.get('platform').api.isDesktop()) { if (plugin.registry.get('platform').api.isDesktop()) {
if (workspaceTemplateName) { if (workspaceTemplateName) {
await plugin.call('remix-templates', 'loadTemplateInNewWindow', workspaceTemplateName, opts) await plugin.call('remix-templates', 'loadTemplateInNewWindow', workspaceTemplateName, opts)

Loading…
Cancel
Save