Skip to content
Draft
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
29 changes: 27 additions & 2 deletions src_assets/common/assets/web/apps.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ <h5 class="modal-title" id="appEditModalLabel">
:aria-label="$t('_common.close')"></button>
</div>
<div class="modal-body">
<!-- Error -->
<div v-if="editFormError" class="alert alert-danger py-2 small">{{ editFormError }}</div>
<!-- Application Name -->
<div class="mb-3">
<label for="appName" class="form-label">{{ $t('apps.app_name') }}</label>
Expand Down Expand Up @@ -309,7 +311,7 @@ <h5 class="modal-title" id="appEditModalLabel">
<input type="text" class="form-control monospace" id="appImagePath" aria-describedby="appImagePathHelp"
v-model="editForm['image-path']" />
<button class="btn btn-secondary" type="button"
@click="browseFor('file', 'file_browser.select_file', editForm['image-path'], v => editForm['image-path'] = v)">
@click="browseFor('file', 'file_browser.select_file', editForm['image-path'], v => editForm['image-path'] = v, ['.png'])">
<folder-open :size="18" class="icon"></folder-open>
</button>
<button class="btn btn-secondary" type="button" @click="showCoverFinder">
Expand Down Expand Up @@ -621,6 +623,7 @@ <h5 class="modal-title">{{ fileBrowserTitle || $t('file_browser.title') }}</h5>
return {
apps: [],
editForm: null,
editFormError: "",
detachedCmd: "",
coverSearching: false,
coverFinderBusy: false,
Expand All @@ -630,6 +633,7 @@ <h5 class="modal-title">{{ fileBrowserTitle || $t('file_browser.title') }}</h5>
fileBrowserType: "any",
fileBrowserTitle: "",
fileBrowserCallback: null,
fileBrowserAcceptedExtensions: null,
fileBrowserCurrentPath: "",
fileBrowserParentPath: "",
fileBrowserEntries: [],
Expand Down Expand Up @@ -741,6 +745,7 @@ <h5 class="modal-title">{{ fileBrowserTitle || $t('file_browser.title') }}</h5>
detached: [],
"image-path": ""
};
this.editFormError = "";
this.openEditModal();
},
editApp(id) {
Expand All @@ -764,6 +769,7 @@ <h5 class="modal-title">{{ fileBrowserTitle || $t('file_browser.title') }}</h5>
if (this.editForm["exit-timeout"] === undefined) {
this.editForm["exit-timeout"] = 5;
}
this.editFormError = "";
this.openEditModal();
},
showDeleteModal(id) {
Expand Down Expand Up @@ -907,10 +913,11 @@ <h5 class="modal-title">{{ fileBrowserTitle || $t('file_browser.title') }}</h5>
})
.finally(() => this.coverFinderBusy = false);
},
browseFor(type, titleKey, startPath, callback) {
browseFor(type, titleKey, startPath, callback, acceptedExtensions = null) {
this.fileBrowserType = type;
this.fileBrowserTitle = this.$t(titleKey);
this.fileBrowserCallback = callback;
this.fileBrowserAcceptedExtensions = acceptedExtensions;
this.fileBrowserSelectedPath = startPath || '';
this.fileBrowserTypedPath = startPath || '';
this.fileBrowserError = '';
Expand All @@ -924,6 +931,14 @@ <h5 class="modal-title">{{ fileBrowserTitle || $t('file_browser.title') }}</h5>
fileBrowserConfirm() {
const path = this.fileBrowserSelectedPath || this.fileBrowserTypedPath;
if (path) {
if (this.fileBrowserAcceptedExtensions && this.fileBrowserType !== 'directory') {
const lowerPath = path.toLowerCase();
const isValid = this.fileBrowserAcceptedExtensions.some(ext => lowerPath.endsWith(ext.toLowerCase()));
if (!isValid) {
this.fileBrowserError = this.$t('file_browser.error_invalid_extension', { extensions: this.fileBrowserAcceptedExtensions.join(', ') });
return;
}
}
if (this.fileBrowserCallback) {
this.fileBrowserCallback(path);
this.fileBrowserCallback = null;
Expand Down Expand Up @@ -984,7 +999,17 @@ <h5 class="modal-title">{{ fileBrowserTitle || $t('file_browser.title') }}</h5>
});
},
save() {
this.editFormError = "";
this.editForm["image-path"] = this.editForm["image-path"].toString().replace(/"/g, '');

const imagePath = this.editForm["image-path"];
if (imagePath && !imagePath.toLowerCase().endsWith('.png')) {
this.editFormError = this.$t('file_browser.error_invalid_extension', { extensions: '.png' });
const modalBody = this.$refs.editModal.querySelector('.modal-body');
if (modalBody) modalBody.scrollTop = 0;
return;
}

apiFetch("./api/apps", {
method: "POST",
headers: {
Expand Down
1 change: 1 addition & 0 deletions src_assets/common/assets/web/public/assets/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@
},
"file_browser": {
"empty": "No items to display",
"error_invalid_extension": "Selected file must have one of the following extensions: {extensions}",
"root": "Root",
"select": "Select",
"select_directory": "Select Directory",
Expand Down