Skip to content
Open
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
109 changes: 109 additions & 0 deletions src/gui/src/UI/UIItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ import truncate_filename from '../helpers/truncate_filename.js';
import launch_app from "../helpers/launch_app.js"
import open_item from "../helpers/open_item.js"

/**
* Checks if a file path represents an image file based on its extension
* @param {string} filePath - The file path to check
* @returns {boolean} True if the file is an image, false otherwise
*/
function isImageFile(filePath) {
if (!filePath) return false;

const imageExtensions = [
'.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp',
'.svg', '.ico', '.tif', '.tiff', '.heic', '.heif'
];

const lowerPath = filePath.toLowerCase();
return imageExtensions.some(ext => lowerPath.endsWith(ext));
}

function UIItem(options){
const matching_appendto_count = $(options.appendTo).length;
if(matching_appendto_count > 1){
Expand Down Expand Up @@ -1184,6 +1201,98 @@ function UIItem(options){
});
}
// -------------------------------------------
// Set as Desktop Background
// -------------------------------------------
if(!is_trash && !is_trashed && !options.is_dir && isImageFile(options.path)){
menu_items.push({
html: i18n('set_as_desktop_background'),
onClick: async function(){
try {
// Sign the file to get a URL that works in CSS background-image
// (doesn't require auth headers)
const sign_res = await $.ajax({
url: window.api_origin + "/sign",
type: 'POST',
data: JSON.stringify({
items: [{
path: options.path,
action: 'read'
}]
}),
async: true,
contentType: "application/json",
headers: {
"Authorization": "Bearer "+window.auth_token
},
statusCode: {
401: function () {
window.logout();
},
},
});

const read_url = sign_res.signatures[0].read_url;

// Preload image before setting as background to avoid gray flash
await new Promise((resolve, reject) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really necessary? why do we need to wrap the logic below into a promise? — img operation seem to be sync

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The promise wrapper is necessary because we need to wait for the asynchronous image download to complete before setting the background. Here's why:

  1. new Image() and img.src = read_url are synchronous operations (they just create the object and set the property)
  2. The actual image download happens asynchronously in the browser
  3. The onload callback fires when that async download completes
  4. The Promise wrapper lets us await that async event

Without this, we'd set the background before the image finishes downloading, causing a gray flash while the browser loads it. By preloading, the image is cached and ready, so the background change is instant.

const img = new Image();
img.onload = () => resolve();
img.onerror = () => reject(new Error('Failed to load image'));
img.src = read_url;
});

// Add smooth fade transition
$('body').css('transition', 'opacity 0.4s ease-in-out');

// Fade out
$('body').css('opacity', '0.7');

// Wait for fade out
await new Promise(resolve => setTimeout(resolve, 200));

// Set desktop background locally (image is now cached)
window.set_desktop_background({
url: read_url,
fit: 'cover'
});

// Fade in
$('body').css('opacity', '1');

// Persist to server
await $.ajax({
url: window.api_origin + "/set-desktop-bg",
type: 'POST',
data: JSON.stringify({
url: read_url,
fit: 'cover',
color: null,
}),
async: true,
contentType: "application/json",
headers: {
"Authorization": "Bearer "+window.auth_token
},
statusCode: {
401: function () {
window.logout();
},
},
});

// Update user object
if(window.user){
window.user.desktop_bg_url = read_url;
window.user.desktop_bg_fit = 'cover';
window.user.desktop_bg_color = null;
}
} catch (err) {
console.error('Failed to set desktop background:', err);
}
}
});
}
// -------------------------------------------
// Zip
// -------------------------------------------
if(!is_trash && !is_trashed && !$(el_item).attr('data-path').endsWith('.zip')){
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/ar.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ const ar = {
session_saved: "شكرًا لإنشاء حساب. تم حفظ هذه الجلسة.",
settings: "الإعدادات",
set_new_password: "تعيين كلمة مرور جديدة",
set_as_desktop_background: 'تعيين كخلفية لسطح المكتب',
share: "مشاركة",
share_to: "مشاركة إلى",
share_with: "مشاركة مع:",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/bn.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ const bn = {
session_saved: "অ্যাকাউন্ট তৈরি করার জন্য ধন্যবাদ। এই সেশনটি সংরক্ষিত হয়েছে।",
settings: "সেটিংস",
set_new_password: "নতুন পাসওয়ার্ড সেট করুন",
set_as_desktop_background: 'ডেস্কটপ ব্যাকগ্রাউন্ড হিসাবে সেট করুন',
share: "শেয়ার করুন",
share_to: "শেয়ার করুন প্রতি",
share_with: "সঙ্গে ভাগাভাগি করুন:",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/br.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ const br = {
"session_saved": "Obrigado por criar uma conta. Esta sessão foi salva.",
"settings": "Configurações",
"set_new_password": "Definir Nova Senha",
"set_as_desktop_background": "Definir como plano de fundo da área de trabalho",
"share": "Compartilhar",
"share_to": "Compartilhar para",
"share_with": "Compartilhar com:",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/da.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ const da = {
session_saved: 'Tak fordi du oprettede en konto. Denne session er blevet gemt.',
settings: 'Indstillinger',
set_new_password: 'Indstil ny adgangskode',
set_as_desktop_background: 'Indstil som skrivebordsbaggrund',
share: 'Del',
share_to: 'Del til',
share_with: 'Del med:',
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ const de = {
session_saved: "Vielen Dank, dass Sie ein Konto erstellt haben. Diese Sitzung wurde gespeichert.",
settings: "Einstellungen",
set_new_password: "Neues Passwort festlegen",
set_as_desktop_background: 'Als Desktop-Hintergrund festlegen',
share: "Teilen",
share_to: "Teilen mit",
share_with: "Teilen mit:",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ const emoji = {
send_password_recovery_email: "📧🔑🔄",
session_saved: "👤💾🔄",
set_new_password: "🔑🆕",
set_as_desktop_background: "🖼️🖥️",
share_to: "🔁➡️",
show_all_windows: "🔄🆓🖼️🖼️",
show_hidden: '👁️🔄',
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ const en = {
session_saved: "Thank you for creating an account. This session has been saved.",
settings: "Settings",
set_new_password: "Set New Password",
set_as_desktop_background: 'Set as Desktop Background',
share: "Share",
share_to: "Share to",
share_with: "Share with:",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ const es = {
'Enviar la contraseña al correo de recuperación',
session_saved: 'Gracias por crear una cuenta. La sesión ha sido guardada.',
set_new_password: 'Establecer una nueva contraseña',
set_as_desktop_background: 'Establecer como fondo de escritorio',
settings: 'Opciones',
share: 'Compartir',
share_to: 'Compartir a',
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/fa.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const fa = {
send_password_recovery_email: "ارسال ایمیل بازیابی رمز عبور",
session_saved: "با تشکر از ایجاد حساب کاربری. این جلسه ذخیره شده است.",
set_new_password: "تنظیم رمز عبور جدید",
set_as_desktop_background: "تنظیم به عنوان پس‌زمینه دسکتاپ",
settings: "تنظیمات",
share_to: "اشتراک گذاری به",
show_all_windows: "نمایش همه پنجره ها",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/fi.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ const fi = {
session_saved: "Kiitos tilin luomisesta. Tämä istunto on tallennettu.",
settings: "Asetukset",
set_new_password: "Aseta uusi salasana",
set_as_desktop_background: 'Aseta työpöydän taustakuvaksi',
share: "Jaa",

share_to: "Jaa", // TODO: Grammatical ambiguity
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ const fr = {
session_saved: "Merci d'avoir créé un compte. Cette session a été sauvegardée.",
settings: "Paramètres",
set_new_password: "Definir un nouveau mot de passe",
set_as_desktop_background: 'Définir comme arrière-plan du bureau',
share: "Partager",
share_to: "Partager à",
share_with: "Partager avec",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/he.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ const en = {
session_saved: "תודה שיצרת חשבון. הפעלה זו נשמרה",
settings: "הגדרות",
set_new_password: "הגדרת סיסמה חדשה",
set_as_desktop_background: 'הגדר כרקע שולחן העבודה',
share: "שיתוף",
share_to: "שתף אל",
share_with: "שתף עם:",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/hi.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ const hi = {
session_saved: "खाता बनाने के लिए धन्यवाद. यह सत्र सहेजा गया है",
settings: "समायोजन",
set_new_password: "नया पासवर्ड सेट करें",
set_as_desktop_background: 'डेस्कटॉप पृष्ठभूमि के रूप में सेट करें',
share: "आदान-प्रदान",
share_to: "साझा",
share_with: "के साथ साझा करें",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/hu.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ const hu = {
session_saved: "Köszönjük, hogy létrehoztál egy fiókot. Ez a munkamenet mentésre került.",
settings: "Beállítások",
set_new_password: "Új jelszó beállítása",
set_as_desktop_background: 'Beállítás asztali háttérképként',
share: "Megosztás",
share_to: "Megosztás ide:",
share_with: "Megosztás valakivel:",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/hy.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ const hy = {
session_saved: "Շնորհակալություն հաշիվ ստեղծելու համար: Այս սեսիան պահպանվել է:",
settings: "Կարգավորումներ",
set_new_password: "Սահմանել նոր գաղտնաբառ",
set_as_desktop_background: 'Սահմանել որպես աշխատասեղանի ֆոն',
share: "Տարածել",
share_to: "Տարածել դեպի",
share_with: "Տարածել հետ՝",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ const id = {
session_saved: "Terima kasih telah membuat akun. Sesi ini telah disimpan.",
settings: "Pengaturan",
set_new_password: "Tetapkan Kata Sandi Baru",
set_as_desktop_background: 'Tetapkan sebagai latar belakang desktop',
share: "Bagikan",
share_to: "Bagikan ke",
share_with: "Bagikan dengan:",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/ig.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ const ig = {
session_saved: "Daalụ maka ịmepụta akaụntụ. Achekwala nnọkọ a.",
settings: "Ntọala",
set_new_password: "Tinye paswọọdụ ọhụrụ",
set_as_desktop_background: 'Tinye dị ka okirikiri desktọọpụ',
share: "ike",
share_to: "ike nye",
share_with: "ji ike nye:",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/it.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ const it = {
"Grazie per aver creato un account. La sessione è stata salvata",
settings: "Impostazioni",
set_new_password: "Imposta una nuova Password",
set_as_desktop_background: 'Imposta come sfondo del desktop',
share: "Condividi",
share_to: "Condividi con",
share_with: "Condividi con",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/ja.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ const ja = {
session_saved: "アカウントを作成していただきありがとうございます。このセッションは保存されました。",
settings: "設定",
set_new_password: "新しいパスワードを設定",
set_as_desktop_background: 'デスクトップの背景として設定',
share: "共有",
share_to: "共有先",
share_with: "共有相手:",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/ko.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ const ko = {
session_saved: "계정을 생성해 주셔서 감사합니다. 이 세션이 저장되었습니다.", // Improvement suggestion: "계정을 만들어주셔서 감사합니다. 현재 세션이 저장되었습니다."
settings: "설정",
set_new_password: "새 비밀번호 설정",
set_as_desktop_background: '바탕 화면 배경으로 설정',
share: "공유",
share_to: "공유처",
share_with: "공유 대상",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/ku.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ const ku = {
session_saved: "سوپاس بۆ دروستکردنی هەژمار. ئەم دانیشتنە پاشەکەوتکرا.",
settings: "ڕێکخستنەکان",
set_new_password: "وشەی تێپەڕی نوێ دانان",
set_as_desktop_background: 'دانان وەک پاشبنەی دێسکتۆپ',
share: "هاوبەشکردن",
share_to: "هاوبەشکردن بۆ",
share_with: "هاوبەشکردن بە:",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/nb.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ const nb = {
send_password_recovery_email: "Send e-post for gjenoppretting av passord",
session_saved: "Takk for at du opprettet en konto. Denne økten er lagret.",
set_new_password: "Angi nytt passord",
set_as_desktop_background: "Angi som skrivebordsbakgrunn",
share_to: "Del",
show_all_windows: "Vis alle vinduer",
show_hidden: "Vis skjulte",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/nl.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ const nl = {
session_saved: 'Bedankt voor het aanmaken van een account. Deze sessie is opgeslagen.',
settings: 'Instellingen',
set_new_password: 'Nieuw wachtwoord instellen',
set_as_desktop_background: 'Instellen als bureaubladachtergrond',
share: 'Delen',
share_to: 'Delen met',
share_with: 'Delen met:',
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/nn.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ const nn = {
send_password_recovery_email: "Send e-post for gjenoppretting av passord",
session_saved: "Takk for at du oppretta ein konto. Denne økta er lagra.",
set_new_password: "Set nytt passord",
set_as_desktop_background: "Set som skrivebordsbakgrunn",
share_to: "Del",
show_all_windows: "Vis alle vindauge",
show_hidden: "Vis skjulte",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/pl.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ const pl = {
session_saved: "Dziękujemy za stworzenie konta. Ta sesja została zapisana. ",
settings: "Ustawienia",
set_new_password: "Ustaw nowe hasło.",
set_as_desktop_background: 'Ustaw jako tło pulpitu',
share: "Udostępnij",
share_to: "Udostępnij do",
share_with: "Udostępnij dla:",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/pt.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ const pt = {
session_saved: "Obrigado por criares uma conta. Esta sessão foi gravada.",
settings: "Definições",
set_new_password: "Definir nova Password",
set_as_desktop_background: 'Definir como fundo do ambiente de trabalho',
share: "Partilhar",
share_to: "Partilhar com",
share_with: " Partilhar com:",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/ro.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ const ro = {
session_saved: "Vă mulțumim pentru crearea unui cont. Această sesiune a fost salvată.",
settings: "Setări",
set_new_password: "Setează o parolă Nouă",
set_as_desktop_background: 'Setează ca fundal al desktop-ului',
share: "Distribuie",
share_to: "Distribuie către",
share_with: "Distribuie cu",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ const ru = {
'Благодарим вас за создание учетной записи. Этот сеанс сохранен.',
settings: 'Настройки',
set_new_password: 'Установить новый пароль',
set_as_desktop_background: 'Установить как фон рабочего стола',
share: 'Поделиться',
share_to: 'Поделиться',
share_with: 'Поделиться с: ',
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/sv.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ const sv = {
session_saved: "Tack för att du skapade ett konto. Denna session är sparad.",
settings: "Inställningar",
set_new_password: "Ange nytt lösenord",
set_as_desktop_background: 'Ange som skrivbordsbakgrund',
share: "Dela",
share_to: "Dela till",
share_with: "Dela med:",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/ta.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ const ta = {
session_saved: "கணக்கை உருவாக்கியதற்கு நன்றி. இந்த அமர்வு சேமிக்கப்பட்டது.",
settings: "அமைப்புகள்",
set_new_password: "புதிய கடவுச்சொல்லை அமை",
set_as_desktop_background: 'டெஸ்க்டாப் பின்னணியாக அமை',
share: "பகிர்",
share_to: "பகிரவும்",
share_with: "இவர்களுடன் பகிரவும்:",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/th.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ const th = {
session_saved: "ขอบคุณสำหรับการสร้างบัญชี เซสชันนี้ได้รับการบันทึกแล้ว",
settings: "Settings",
set_new_password: "ตั้งรหัสผ่านใหม่",
set_as_desktop_background: 'ตั้งเป็นพื้นหลังเดสก์ท็อป',
share: "แชร์",
share_to: "แชร์ไปยัง",
share_with: "แชร์ไปให้:",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/tr.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ const tr = {
session_saved: "Hesap oluşturduğunuz için teşekkür ederiz. Oturumunuz kaydedildi.",
settings: "Ayarlar",
set_new_password: "Yeni Parola Belirle",
set_as_desktop_background: 'Masaüstü arka planı olarak ayarla',
share: "Paylaş",
share_to: "Şuna paylaş",
share_with: "Şununla paylaş",
Expand Down
1 change: 1 addition & 0 deletions src/gui/src/i18n/translations/ua.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ const ua = {
session_saved: "Дякуємо вам за створення облікового запису. Цей сеанс збережено.",
settings: "Налаштування",
set_new_password: "Встановити Новий Пароль",
set_as_desktop_background: 'Встановити як фон робочого столу',
share: "Поділитися",
share_to: "Поділитися з",
share_with: "Поділитися з",
Expand Down
Loading