diff --git a/src/UI/UIDesktop.js b/src/UI/UIDesktop.js
index 936ba9b95b..18ad32510d 100644
--- a/src/UI/UIDesktop.js
+++ b/src/UI/UIDesktop.js
@@ -502,10 +502,18 @@ async function UIDesktop(options){
// update local user preferences
const user_preferences = {
- show_hidden_files: (await puter.kv.get('user_preferences.show_hidden_files')) === 'true',
- language: (await puter.kv.get('user_preferences.language'))
+ show_hidden_files: JSON.parse(await puter.kv.get('user_preferences.show_hidden_files')),
+ language: await puter.kv.get('user_preferences.language'),
};
- update_user_preferences(user_preferences);
+
+ // update default apps
+ puter.kv.list('user_preferences.default_apps.*').then(async (default_app_keys) => {
+ for(let key in default_app_keys){
+ user_preferences[default_app_keys[key].substring(17)] = await puter.kv.get(default_app_keys[key]);
+ }
+
+ update_user_preferences(user_preferences);
+ });
// Append to
$('body').append(h);
diff --git a/src/UI/UIItem.js b/src/UI/UIItem.js
index cef4bddcb4..0361e4e57b 100644
--- a/src/UI/UIItem.js
+++ b/src/UI/UIItem.js
@@ -983,6 +983,35 @@ function UIItem(options){
html: suggested_app.title,
icon: `
`,
onClick: async function(){
+ var extension = path.extname($(el_item).attr('data-path')).toLowerCase();
+ if(
+ user_preferences[`default_apps${extension}`] !== suggested_app.name
+ &&
+ (
+ (!user_preferences[`default_apps${extension}`] && index > 0)
+ ||
+ (user_preferences[`default_apps${extension}`])
+ )
+ ){
+ const alert_resp = await UIAlert({
+ message: `${i18n('change_allways_open_with')} ` + html_encode(suggested_app.title) + '?',
+ body_icon: suggested_app.icon,
+ buttons:[
+ {
+ label: i18n('yes'),
+ type: 'primary',
+ value: 'yes'
+ },
+ {
+ label: i18n('no')
+ },
+ ]
+ })
+ if((alert_resp) === 'yes'){
+ user_preferences['default_apps' + extension] = suggested_app.name;
+ window.mutate_user_preferences(user_preferences);
+ }
+ }
launch_app({
name: suggested_app.name,
file_path: $(el_item).attr('data-path'),
diff --git a/src/helpers.js b/src/helpers.js
index 8738632b9b..96b13a23ba 100644
--- a/src/helpers.js
+++ b/src/helpers.js
@@ -713,7 +713,7 @@ window.update_auth_data = (auth_token, user)=>{
window.mutate_user_preferences = function(user_preferences_delta) {
for (const [key, value] of Object.entries(user_preferences_delta)) {
// Don't wait for set to be done for better efficiency
- puter.kv.set(`user_preferences.${key}`, String(value));
+ puter.kv.set(`user_preferences.${key}`, value);
}
// There may be syncing issues across multiple devices
update_user_preferences({ ...window.user_preferences, ...user_preferences_delta });
@@ -989,6 +989,10 @@ window.item_icon = async (fsentry)=>{
else if(fsentry.name.toLowerCase().endsWith('.psd')){
return {image: window.icons['file-psd.svg'], type: 'icon'};
}
+ // *.py
+ else if(fsentry.name.toLowerCase().endsWith('.py')){
+ return {image: window.icons['file-py.svg'], type: 'icon'};
+ }
// *.xlsx
else if(fsentry.name.toLowerCase().endsWith('.xlsx')){
return {image: window.icons['file-xlsx.svg'], type: 'icon'};
@@ -2031,6 +2035,7 @@ window.open_item = async function(options){
const is_shortcut = $(el_item).attr('data-is_shortcut') === '1';
const shortcut_to_path = $(el_item).attr('data-shortcut_to_path');
const associated_app_name = $(el_item).attr('data-associated_app_name');
+ const file_uid = $(el_item).attr('data-uid')
//----------------------------------------------------------------
// Is this a shortcut whose source is perma-deleted?
//----------------------------------------------------------------
@@ -2125,6 +2130,18 @@ window.open_item = async function(options){
}
}
//----------------------------------------------------------------
+ // Does the user have a preference for this file type?
+ //----------------------------------------------------------------
+ else if(user_preferences[`default_apps${path.extname(item_path).toLowerCase()}`]) {
+ launch_app({
+ name: user_preferences[`default_apps${path.extname(item_path).toLowerCase()}`],
+ file_path: item_path,
+ window_title: path.basename(item_path),
+ maximized: options.maximized,
+ file_uid: file_uid,
+ });
+ }
+ //----------------------------------------------------------------
// Is there an app associated with this item?
//----------------------------------------------------------------
else if(associated_app_name !== ''){
diff --git a/src/i18n/translations/en.js b/src/i18n/translations/en.js
index 03541cb95e..706d765dc3 100644
--- a/src/i18n/translations/en.js
+++ b/src/i18n/translations/en.js
@@ -36,6 +36,7 @@ const en = {
change_username: "Change Username",
close_all_windows: "Close All Windows",
close_all_windows_and_log_out: 'Close Windows and Log Out',
+ change_allways_open_with: "Do you want to always open this type of file with",
color: 'Color',
confirm_account_for_free_referral_storage_c2a: 'Create an account and confirm your email address to receive 1 GB of free storage. Your friend will get 1 GB of free storage too.',
confirm_delete_multiple_items: 'Are you sure you want to permanently delete these items?',
diff --git a/src/i18n/translations/nb.js b/src/i18n/translations/nb.js
index ede9362bb3..b5e309ffdf 100644
--- a/src/i18n/translations/nb.js
+++ b/src/i18n/translations/nb.js
@@ -35,6 +35,7 @@ const nb = {
change_username: "Endre brukernavn",
close_all_windows: "Lukk alle vinduer",
close_all_windows_and_log_out: 'Lukk alle vinduer og logg ut',
+ change_allways_open_with: "Ønsker du å alltid åpne denne filtypen med",
color: "Farge",
confirm_account_for_free_referral_storage_c2a: "Opprett en konto og bekreft e-postadressen din for å motta 1 GB gratis lagringsplass. Din venn vil også få 1 GB gratis lagringsplass.",
confirm_delete_multiple_items: 'Er du sikker på at du vil slette disse elementene permanent?',