Skip to content
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
9 changes: 8 additions & 1 deletion src/main/preload.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { contextBridge, ipcRenderer } from 'electron'
import { isDbExist, migrate, migrateFromSnippetsLab, move } from './services/db'
import {
isDbExist,
migrate,
migrateFromSnippetsLab,
move,
createDb
} from './services/db'
import { store } from './store'
import type { ElectronBridge } from '@shared/types/main'
import { track } from './services/analytics'
Expand All @@ -25,6 +31,7 @@ contextBridge.exposeInMainWorld('electron', {
}
},
db: {
create: () => createDb(),
migrate: path => migrate(path),
migrateFromSnippetsLab: path => migrateFromSnippetsLab(path),
move: (from, to) => move(from, to),
Expand Down
6 changes: 4 additions & 2 deletions src/main/services/i18n/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"button": {
"moveStorage": "Move Storage",
"openStorage": "Open Storage",
"newStorage": "New Storage",
"fromMassCodeV1": "From massCode v1.0",
"fromSnippetsLab": "From SnippetsLab",
"confirm": "Confirm",
"cancel": "Cancel",
"update": ["Go to GitHub", "OK"]
"update": ["Go to GitHub", "OK"],
"ok": "OK"
},
"newFolder": "New Folder",
"newSnippet": "New Snippet",
Expand Down Expand Up @@ -55,4 +57,4 @@
"updateAvailable": "Update Available",
"hide": "Hide",
"show": "Show"
}
}
5 changes: 3 additions & 2 deletions src/main/services/i18n/locales/en/dialog.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"migrateConfirm": [
"Are you sure you want to migrate from {{name}}?",
"During migrate, the current library will be overwritten."
]
}
],
"createDb": "Please select another folder"
}
3 changes: 2 additions & 1 deletion src/main/services/i18n/locales/en/special.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
"migrate": "DB successfully migrated."
},
"error": {
"folderContainDb": "Folder already contain \"db.json\".",
"folderNotContainDb": "Folder not contain \"db.json\"."
},
"unsponsored": "Unsponsored",
"supportMessage": "Hi, Anton here 👋<br><br>\nThanks for using massCode. If you find this app useful, please {{-tagStart}} donate {{-tagEnd}}. It will inspire me to continue development on the project.",
"snippetsShowcase": "Snippets Showcase"
}
}
6 changes: 4 additions & 2 deletions src/main/services/i18n/locales/ru/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
"button": {
"moveStorage": "Переместить",
"openStorage": "Открыть",
"newStorage": "Создать новое",
"fromMassCodeV1": "Из massCode v1.0",
"fromSnippetsLab": "Из SnippetsLab",
"confirm": "Подтвердить",
"cancel": "Отмена"
"cancel": "Отмена",
"ok": "Хорошо"
},
"newFolder": "Новая папка",
"newSnippet": "Новый сниппет",
Expand Down Expand Up @@ -54,4 +56,4 @@
"updateAvailable": "Доступно обновление",
"hide": "Hide",
"show": "Show"
}
}
5 changes: 3 additions & 2 deletions src/main/services/i18n/locales/ru/dialog.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"migrateConfirm": [
"Вы уверены что хотите мигрировать {{name}}?",
"Во время миграции, текущая библиотека буде перезаписана."
]
}
],
"createDb": "Пожалуйста выберите другую папку"
}
3 changes: 2 additions & 1 deletion src/main/services/i18n/locales/ru/special.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
"migrate": "БД успешно перенесена."
},
"error": {
"folderContainDb": "Папка уже содержит \"db.json\".",
"folderNotContainDb": "Папка не содержит \"db.json\"."
},
"unsponsored": "Неспонсируемое",
"supportMessage": "Привет, это Антон 👋<br><br>\nСпасибо что используете massCode. Если приложение оказалось для вас полезным, пожалуйста {{-tagStart}} поддержите проект {{-tagEnd}}. Это вдохновит меня для продолжение работы над проектом.",
"snippetsShowcase": "Коллекция сниппетов"
}
}
42 changes: 35 additions & 7 deletions src/renderer/components/preferences/StoragePreferences.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
<AppFormItem :label="i18n.t('preferences:storage.label')">
<AppInput
v-model="storagePath"
style="width: 100%"
readonly
/>
<AppButton @click="onClickMove">
{{ i18n.t('button.moveStorage') }}
</AppButton>
<AppButton @click="onClickOpen">
{{ i18n.t('button.openStorage') }}
</AppButton>
<template #actions>
<AppButton @click="onClickMove">
{{ i18n.t('button.moveStorage') }}
</AppButton>
<AppButton @click="onClickOpen">
{{ i18n.t('button.openStorage') }}
</AppButton>
<AppButton @click="onClickNew">
{{ i18n.t('button.newStorage') }}
</AppButton>
</template>
<template #desc>
{{ i18n.t('special:description.storage') }}
</template>
Expand Down Expand Up @@ -45,7 +51,11 @@
import { ipc, store, db, track, i18n } from '@/electron'
import { useFolderStore } from '@/store/folders'
import { useSnippetStore } from '@/store/snippets'
import type { MessageBoxRequest, DialogRequest } from '@shared/types/main'
import type {
MessageBoxRequest,
DialogRequest,
ErrorBoxRequest
} from '@shared/types/main'
import { ref } from 'vue'

const snippetStore = useSnippetStore()
Expand Down Expand Up @@ -88,6 +98,24 @@ const onClickOpen = async () => {
}
}

const onClickNew = async () => {
const path = await ipc.invoke<any, string>('main:open-dialog', {})

const isExist = db.isExist(path)

if (!isExist) {
store.preferences.set('storagePath', path)
setStorageAndRestartApi(path, true)
db.create()
} else {
await ipc.invoke<MessageBoxRequest, boolean>('main:open-message-box', {
message: i18n.t('special:error.folderContainDb'),
detail: i18n.t('dialog:createDb'),
buttons: [i18n.t('button.ok')]
})
}
}

const onClickMigrate = async () => {
const state = await ipc.invoke<MessageBoxRequest, boolean>(
'main:open-message-box',
Expand Down
11 changes: 11 additions & 0 deletions src/renderer/components/ui/form/AppFormItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<div class="body">
<slot />
</div>
<div
v-if="$slots.actions"
class="actions"
>
<slot name="actions" />
</div>
<div
v-if="$slots.desc"
class="desc"
Expand Down Expand Up @@ -39,5 +45,10 @@ defineProps<Props>()
align-items: center;
gap: var(--spacing-sm);
}
.actions {
margin-top: var(--spacing-sm);
display: flex;
gap: var(--spacing-sm);
}
}
</style>
1 change: 1 addition & 0 deletions src/shared/types/main/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export interface ElectronBridge {
preferences: StoreProperties<PreferencesStore>
}
db: {
create: () => void
migrate: (path: string) => Promise<void>
migrateFromSnippetsLab: (path: string) => void
move: (from: string, to: string) => Promise<void>
Expand Down