Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(settings): implement the ui part #1818

Merged
merged 6 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apps/desktop/electron.vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ export default defineConfig({
custom: FileSystemIconLoader('../../packages/ui/src/assets/icons'),
},
}),
{
name: 'element-plus-night-theme',
transform(code, id) {
if (id.endsWith('packages/ui/src/styles/index.scss')) {
const nightThemeCode = code.replace(/html\.dark/g, 'html.night')
return `${code}\n${nightThemeCode}`
}
return code
},
},
],
css: {
preprocessorOptions: {
Expand Down
17 changes: 16 additions & 1 deletion apps/web/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,25 @@ declare module 'vue' {
ConnectionsDetailsView: typeof import('./../../packages/ui/src/components/connections/DetailsView.vue')['default']
ConnectionsListView: typeof import('./../../packages/ui/src/components/connections/ListView.vue')['default']
ElAside: typeof import('element-plus/es')['ElAside']
ElAutocomplete: typeof import('element-plus/es')['ElAutocomplete']
ElButton: typeof import('element-plus/es')['ElButton']
ElCascaderPanel: typeof import('element-plus/es')['ElCascaderPanel']
ElCol: typeof import('element-plus/es')['ElCol']
ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
ElContainer: typeof import('element-plus/es')['ElContainer']
ElDivider: typeof import('element-plus/es')['ElDivider']
ElIconDelete: typeof import('@element-plus/icons-vue')['Delete']
ElIconPrinter: typeof import('@element-plus/icons-vue')['Printer']
ElIconUpload: typeof import('@element-plus/icons-vue')['Upload']
ElIconWarning: typeof import('@element-plus/icons-vue')['Warning']
ElInput: typeof import('element-plus/es')['ElInput']
ElInputNumber: typeof import('element-plus/es')['ElInputNumber']
ElMain: typeof import('element-plus/es')['ElMain']
Help: typeof import('./../../packages/ui/src/components/Help.vue')['default']
ElOption: typeof import('element-plus/es')['ElOption']
ElRow: typeof import('element-plus/es')['ElRow']
ElSelect: typeof import('element-plus/es')['ElSelect']
ElSwitch: typeof import('element-plus/es')['ElSwitch']
ElTooltip: typeof import('element-plus/es')['ElTooltip']
HelpView: typeof import('./../../packages/ui/src/components/HelpView.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
Expand Down
14 changes: 10 additions & 4 deletions apps/web/src/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import settingsSchema from './schemas/Settings.schema'

// import modules
import { disableWarnings, RxDBDevModePlugin } from 'rxdb/plugins/dev-mode'
import { wrappedKeyEncryptionCryptoJsStorage } from 'rxdb/plugins/encryption-crypto-js'
import { RxDBLeaderElectionPlugin } from 'rxdb/plugins/leader-election'
import { RxDBUpdatePlugin } from 'rxdb/plugins/update'
import { wrappedValidateAjvStorage } from 'rxdb/plugins/validate-ajv'
Expand All @@ -25,20 +26,25 @@ addRxPlugin(RxDBLeaderElectionPlugin)
addRxPlugin(RxDBUpdatePlugin)

export function useDatabase(): RxMqttxDatabase {
return inject<RxMqttxDatabase>(KEY_DATABASE) ?? window.db
return window.db ?? inject<RxMqttxDatabase>(KEY_DATABASE)
}

export async function createDatabase(): Promise<Plugin> {
// wrap the normal storage with the encryption plugin
const encryptedDexieStorage = wrappedKeyEncryptionCryptoJsStorage({
storage: getRxStorageDexie(),
})

const db = await createRxDatabase<RxMqttxCollections>({
name: 'mqttx',
storage: wrappedValidateAjvStorage({
storage: getRxStorageDexie(),
storage: encryptedDexieStorage,
}),
password: 'EBJ3cru8fun5gtw*tky',
eventReduce: true,
})

// write to window for debugging
;(window as any).db = db
window.db = db

// show leadership in title
db.waitForLeadership().then(() => {
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/database/schemas/Settings.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const settingsSchema: RxJsonSchema<RxSettingsDocumentType> = {
},
},
required: ['id'],
encrypted: ['openAIAPIKey'],
}

export default settingsSchema
10 changes: 10 additions & 0 deletions apps/web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ export default defineConfig({
custom: FileSystemIconLoader('../../packages/ui/src/assets/icons'),
},
}),
{
name: 'element-plus-night-theme',
transform(code, id) {
if (id.endsWith('packages/ui/src/styles/index.scss')) {
const nightThemeCode = code.replace(/html\.dark/g, 'html.night')
return `${code}\n${nightThemeCode}`
}
return code
},
},
],
resolve: {
alias: {
Expand Down
16 changes: 16 additions & 0 deletions packages/ui/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,23 @@ declare module 'vue' {
ConnectionsDetailsView: typeof import('./src/components/connections/DetailsView.vue')['default']
ConnectionsListView: typeof import('./src/components/connections/ListView.vue')['default']
ElAside: typeof import('element-plus/es')['ElAside']
ElAutocomplete: typeof import('element-plus/es')['ElAutocomplete']
ElButton: typeof import('element-plus/es')['ElButton']
ElCascaderPanel: typeof import('element-plus/es')['ElCascaderPanel']
ElCol: typeof import('element-plus/es')['ElCol']
ElDivider: typeof import('element-plus/es')['ElDivider']
ElIconDelete: typeof import('@element-plus/icons-vue')['Delete']
ElIconPrinter: typeof import('@element-plus/icons-vue')['Printer']
ElIconUpload: typeof import('@element-plus/icons-vue')['Upload']
ElIconWarning: typeof import('@element-plus/icons-vue')['Warning']
ElInput: typeof import('element-plus/es')['ElInput']
ElInputNumber: typeof import('element-plus/es')['ElInputNumber']
ElMain: typeof import('element-plus/es')['ElMain']
ElOption: typeof import('element-plus/es')['ElOption']
ElRow: typeof import('element-plus/es')['ElRow']
ElSelect: typeof import('element-plus/es')['ElSelect']
ElSwitch: typeof import('element-plus/es')['ElSwitch']
ElTooltip: typeof import('element-plus/es')['ElTooltip']
HelpView: typeof import('./src/components/HelpView.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
Expand Down
Loading
Loading