mirror of
https://github.com/HeyPuter/puter.git
synced 2025-02-02 23:28:39 +08:00
Merge pull request #157 from SondreNjaastad/feature/user_selected_default_app
Synchronized user defined default apps for files
This commit is contained in:
commit
4981d1c490
@ -502,10 +502,18 @@ async function UIDesktop(options){
|
|||||||
|
|
||||||
// update local user preferences
|
// update local user preferences
|
||||||
const user_preferences = {
|
const user_preferences = {
|
||||||
show_hidden_files: (await puter.kv.get('user_preferences.show_hidden_files')) === 'true',
|
show_hidden_files: JSON.parse(await puter.kv.get('user_preferences.show_hidden_files')),
|
||||||
language: (await puter.kv.get('user_preferences.language'))
|
language: await puter.kv.get('user_preferences.language'),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 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);
|
update_user_preferences(user_preferences);
|
||||||
|
});
|
||||||
|
|
||||||
// Append to <body>
|
// Append to <body>
|
||||||
$('body').append(h);
|
$('body').append(h);
|
||||||
|
@ -983,6 +983,35 @@ function UIItem(options){
|
|||||||
html: suggested_app.title,
|
html: suggested_app.title,
|
||||||
icon: `<img src="${html_encode(suggested_app.icon ?? window.icons['app.svg'])}" style="width:16px; height: 16px; margin-bottom: -4px;">`,
|
icon: `<img src="${html_encode(suggested_app.icon ?? window.icons['app.svg'])}" style="width:16px; height: 16px; margin-bottom: -4px;">`,
|
||||||
onClick: async function(){
|
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({
|
launch_app({
|
||||||
name: suggested_app.name,
|
name: suggested_app.name,
|
||||||
file_path: $(el_item).attr('data-path'),
|
file_path: $(el_item).attr('data-path'),
|
||||||
|
@ -713,7 +713,7 @@ window.update_auth_data = (auth_token, user)=>{
|
|||||||
window.mutate_user_preferences = function(user_preferences_delta) {
|
window.mutate_user_preferences = function(user_preferences_delta) {
|
||||||
for (const [key, value] of Object.entries(user_preferences_delta)) {
|
for (const [key, value] of Object.entries(user_preferences_delta)) {
|
||||||
// Don't wait for set to be done for better efficiency
|
// 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
|
// There may be syncing issues across multiple devices
|
||||||
update_user_preferences({ ...window.user_preferences, ...user_preferences_delta });
|
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')){
|
else if(fsentry.name.toLowerCase().endsWith('.psd')){
|
||||||
return {image: window.icons['file-psd.svg'], type: 'icon'};
|
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
|
// *.xlsx
|
||||||
else if(fsentry.name.toLowerCase().endsWith('.xlsx')){
|
else if(fsentry.name.toLowerCase().endsWith('.xlsx')){
|
||||||
return {image: window.icons['file-xlsx.svg'], type: 'icon'};
|
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 is_shortcut = $(el_item).attr('data-is_shortcut') === '1';
|
||||||
const shortcut_to_path = $(el_item).attr('data-shortcut_to_path');
|
const shortcut_to_path = $(el_item).attr('data-shortcut_to_path');
|
||||||
const associated_app_name = $(el_item).attr('data-associated_app_name');
|
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?
|
// 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?
|
// Is there an app associated with this item?
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
else if(associated_app_name !== ''){
|
else if(associated_app_name !== ''){
|
||||||
|
@ -36,6 +36,7 @@ const en = {
|
|||||||
change_username: "Change Username",
|
change_username: "Change Username",
|
||||||
close_all_windows: "Close All Windows",
|
close_all_windows: "Close All Windows",
|
||||||
close_all_windows_and_log_out: 'Close Windows and Log Out',
|
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',
|
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_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?',
|
confirm_delete_multiple_items: 'Are you sure you want to permanently delete these items?',
|
||||||
|
@ -35,6 +35,7 @@ const nb = {
|
|||||||
change_username: "Endre brukernavn",
|
change_username: "Endre brukernavn",
|
||||||
close_all_windows: "Lukk alle vinduer",
|
close_all_windows: "Lukk alle vinduer",
|
||||||
close_all_windows_and_log_out: 'Lukk alle vinduer og logg ut',
|
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",
|
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_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?',
|
confirm_delete_multiple_items: 'Er du sikker på at du vil slette disse elementene permanent?',
|
||||||
|
Loading…
Reference in New Issue
Block a user