parent
f542fd8d1b
commit
1d36d50ab6
@ -0,0 +1,15 @@ |
||||
import { ElectronPlugin } from '@remixproject/engine-electron'; |
||||
|
||||
export class electronTemplates extends ElectronPlugin { |
||||
constructor() { |
||||
super({ |
||||
displayName: 'electronTemplates', |
||||
name: 'electronTemplates', |
||||
description: 'templates', |
||||
}) |
||||
} |
||||
|
||||
onActivation(): void { |
||||
|
||||
}
|
||||
} |
@ -0,0 +1,31 @@ |
||||
import { Plugin } from '@remixproject/engine' |
||||
import * as templateWithContent from '@remix-project/remix-ws-templates' |
||||
|
||||
const profile = { |
||||
name: 'remix-templates', |
||||
displayName: 'remix-templates', |
||||
description: 'Remix Templates plugin', |
||||
methods: ['getTemplate', 'loadTemplateInNewWindow'], |
||||
} |
||||
|
||||
export class TemplatesPlugin extends Plugin { |
||||
|
||||
constructor() { |
||||
super(profile) |
||||
} |
||||
|
||||
async getTemplate (template: string, opts?: any) { |
||||
const templateList = Object.keys(templateWithContent) |
||||
if (!templateList.includes(template)) return |
||||
// @ts-ignore
|
||||
const files = await templateWithContent[template](opts) |
||||
console.log('files for template ', files) |
||||
return files |
||||
} |
||||
// electron only method
|
||||
async loadTemplateInNewWindow (template: string, opts?: any) { |
||||
const files = await this.getTemplate(template, opts) |
||||
this.call('electronTemplates', 'loadTemplateInNewWindow', files) |
||||
} |
||||
} |
||||
|
@ -0,0 +1,20 @@ |
||||
import {BrowserWindow, MenuItemConstructorOptions} from 'electron'; |
||||
|
||||
export default ( |
||||
commandKeys: Record<string, string>, |
||||
execCommand: (command: string, focusedWindow?: BrowserWindow) => void |
||||
): MenuItemConstructorOptions => { |
||||
const isMac = process.platform === 'darwin'; |
||||
|
||||
return { |
||||
label: 'Git', |
||||
submenu: [ |
||||
{ |
||||
label: 'Clone Repository in New Window', |
||||
click(item, focusedWindow) { |
||||
execCommand('git:startclone', focusedWindow); |
||||
} |
||||
} |
||||
] |
||||
}; |
||||
}; |
@ -0,0 +1,75 @@ |
||||
import { PluginClient } from "@remixproject/plugin"; |
||||
import { Profile } from "@remixproject/plugin-utils"; |
||||
import { ElectronBasePlugin, ElectronBasePluginClient } from "@remixproject/plugin-electron" |
||||
import * as templateWithContent from '@remix-project/remix-ws-templates' |
||||
import fs from 'fs/promises' |
||||
import { createWindow } from "../main"; |
||||
import path from 'path' |
||||
|
||||
const profile: Profile = { |
||||
name: 'electronTemplates', |
||||
displayName: 'electronTemplates', |
||||
description: 'Templates plugin', |
||||
} |
||||
|
||||
export class TemplatesPlugin extends ElectronBasePlugin { |
||||
clients: TemplatesPluginClient[] = [] |
||||
constructor() { |
||||
super(profile, clientProfile, TemplatesPluginClient) |
||||
} |
||||
|
||||
openTemplate(webContentsId: any): void { |
||||
const client = this.clients.find(c => c.webContentsId === webContentsId) |
||||
if (client) { |
||||
client.openTemplate() |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
const clientProfile: Profile = { |
||||
name: 'electronTemplates', |
||||
displayName: 'electronTemplates', |
||||
description: 'Templates plugin', |
||||
methods: ['loadTemplateInNewWindow', 'openTemplate'], |
||||
} |
||||
|
||||
export type WorkspaceTemplate = 'gist-template' | 'code-template' | 'remixDefault' | 'blank' | 'ozerc20' | 'zeroxErc20' | 'ozerc721' |
||||
|
||||
class TemplatesPluginClient extends ElectronBasePluginClient { |
||||
|
||||
constructor(webContentsId: number, profile: Profile) { |
||||
super(webContentsId, profile) |
||||
this.onload(() => { |
||||
console.log('TemplatesPluginClient onload') |
||||
}) |
||||
} |
||||
|
||||
async loadTemplateInNewWindow (files: any) { |
||||
|
||||
let folder = await this.call('fs' as any, 'selectFolder') |
||||
if (!folder || folder === '') return |
||||
// @ts-ignore
|
||||
console.log('files for template ', files) |
||||
for (const file in files) { |
||||
try { |
||||
if(!folder.endsWith('/')) folder += '/' |
||||
console.log('writing file', folder + file) |
||||
await fs.mkdir(path.dirname(folder + file), { recursive: true}) |
||||
await fs.writeFile(folder + file, files[file], { |
||||
encoding: 'utf8' |
||||
}) |
||||
} catch (error) { |
||||
console.error(error) |
||||
} |
||||
} |
||||
createWindow(folder) |
||||
} |
||||
|
||||
async openTemplate(){ |
||||
this.call('filePanel' as any, 'loadTemplate') |
||||
} |
||||
|
||||
} |
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,34 @@ |
||||
/* eslint-disable @typescript-eslint/no-unused-vars */ |
||||
import React, { useState, useRef, useReducer } from 'react' |
||||
import { FormattedMessage } from 'react-intl' |
||||
import { ModalDialog } from '@remix-ui/modal-dialog' // eslint-disable-line
|
||||
import { Toaster } from '@remix-ui/toaster' // eslint-disable-line
|
||||
const _paq = window._paq = window._paq || [] // eslint-disable-line
|
||||
import { CustomTooltip } from '@remix-ui/helper'; |
||||
|
||||
interface HomeTabFileProps { |
||||
plugin: any |
||||
} |
||||
|
||||
export const HomeTabFileElectron = ({ plugin }: HomeTabFileProps) => { |
||||
|
||||
const loadTemplate = async () => { |
||||
plugin.call('filePanel', 'loadTemplate') |
||||
} |
||||
|
||||
const clone = async () => { |
||||
plugin.call('filePanel', 'clone') |
||||
} |
||||
|
||||
return ( |
||||
<div className="justify-content-start mt-1 p-2 d-flex flex-column" id="hTFileSection"> |
||||
<label style={{ fontSize: "1.2rem" }}><FormattedMessage id='home.files' /></label> |
||||
<label style={{ fontSize: "0.8rem" }} className="pt-2"><FormattedMessage id='home.loadFrom' /></label> |
||||
<div className="d-flex"> |
||||
|
||||
<button className="btn p-2 border mr-2" data-id="landingPageImportFromGistButton" onClick={async () => await loadTemplate()}>Project Template</button> |
||||
<button className="btn p-2 border mr-2" data-id="landingPageImportFromGistButton" onClick={async () => await clone()}>Clone a Git Repository</button> |
||||
</div> |
||||
</div> |
||||
) |
||||
} |
Loading…
Reference in new issue