mac csc link
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
export default class BaseNotesAdapter {
|
||||
constructor(config = {}) {
|
||||
this.config = config
|
||||
}
|
||||
|
||||
async init() {
|
||||
throw new Error('init() not implemented')
|
||||
}
|
||||
|
||||
async getAll() {
|
||||
throw new Error('getAll() not implemented')
|
||||
}
|
||||
|
||||
async create(note) {
|
||||
throw new Error('create() not implemented')
|
||||
}
|
||||
|
||||
async update(note) {
|
||||
throw new Error('update() not implemented')
|
||||
}
|
||||
|
||||
async delete(id) {
|
||||
throw new Error('delete() not implemented')
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,34 @@ import fs from 'fs/promises'
|
||||
import path from 'path'
|
||||
import { app } from 'electron'
|
||||
|
||||
const USER_DATA_STRING = '__DEFAULT_USER_DATA__'
|
||||
|
||||
export default class PluginConfig {
|
||||
constructor(defaultPlugin) {
|
||||
this.defaultPlugin = defaultPlugin
|
||||
|
||||
this.configPath = path.join(app.getPath('userData'), 'config.json')
|
||||
}
|
||||
|
||||
// Helper to replace placeholders with dynamic values, recursively
|
||||
_resolveDefaults(config) {
|
||||
if (Array.isArray(config)) {
|
||||
return config.map((item) => this._resolveDefaults(item))
|
||||
} else if (config && typeof config === 'object') {
|
||||
const resolved = {}
|
||||
for (const [key, value] of Object.entries(config)) {
|
||||
resolved[key] = this._resolveDefaults(value)
|
||||
}
|
||||
return resolved
|
||||
} else if (
|
||||
typeof config === 'string' &&
|
||||
config.includes(USER_DATA_STRING)
|
||||
) {
|
||||
return config.replace(USER_DATA_STRING, app.getPath('userData'))
|
||||
} else {
|
||||
return config
|
||||
}
|
||||
}
|
||||
|
||||
async load() {
|
||||
let parsed
|
||||
|
||||
@@ -32,6 +53,9 @@ export default class PluginConfig {
|
||||
}
|
||||
|
||||
await this.write(parsed)
|
||||
} else {
|
||||
// Ensure any "__DEFAULT_USER_DATA__" values are resolved on load
|
||||
parsed.adapterConfig = this._resolveDefaults(parsed.adapterConfig)
|
||||
}
|
||||
|
||||
return parsed
|
||||
@@ -43,9 +67,15 @@ export default class PluginConfig {
|
||||
// Ensure directory exists
|
||||
await fs.mkdir(dir, { recursive: true })
|
||||
|
||||
// Resolve defaults before writing
|
||||
const resolvedConfig = {
|
||||
...configObject,
|
||||
adapterConfig: this._resolveDefaults(configObject.adapterConfig),
|
||||
}
|
||||
|
||||
await fs.writeFile(
|
||||
this.configPath,
|
||||
JSON.stringify(configObject, null, 2),
|
||||
JSON.stringify(resolvedConfig, null, 2),
|
||||
'utf8',
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user