The user can now choose to always use a given app (when double clicking the icon) after rightclicking and clicking "open with"

This commit is contained in:
Sondre Tungesvik Njåstad 2024-03-22 13:46:55 +01:00
parent 7496a2ac63
commit b31c5a672d
5 changed files with 48 additions and 4 deletions

View File

@ -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>
$('body').append(h);

View File

@ -975,6 +975,26 @@ function UIItem(options){
html: suggested_app.title,
icon: `<img src="${html_encode(suggested_app.icon ?? window.icons['app.svg'])}" style="width:16px; height: 16px; margin-bottom: -4px;">`,
onClick: async function(){
var extension = path.extname($(el_item).attr('data-path')).toLowerCase();
if(user_preferences[`default_apps${extension}`] !== suggested_app.name){
const alert_resp = await UIAlert({
message: `${i18n('change_allways_open_with')} ` + suggested_app.title + '?',
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'),

View File

@ -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 });
@ -2031,6 +2031,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 +2126,19 @@ window.open_item = async function(options){
}
}
//----------------------------------------------------------------
// Do the user have a preference for this file type?
//----------------------------------------------------------------
else if(user_preferences[`default_apps${path.extname(item_path).toLowerCase()}`]) {
console.log('launching default app')
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 !== ''){

View File

@ -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?',

View File

@ -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?',