parent
274a3c7cbd
commit
b8ed5556cb
@ -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> { |
||||
|
||||
} |
||||
|
||||
} |
@ -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 |
||||
} |
Loading…
Reference in new issue