mirror of
https://github.com/HeyPuter/puter.git
synced 2026-01-06 21:20:27 -06:00
dev: add save file by moving from appdata
This commit is contained in:
@@ -1326,6 +1326,38 @@ const ipc_listener = async (event, handled) => {
|
||||
if ( written ) return true;
|
||||
$(el_filedialog_window).find('.window-disable-mask, .busy-indicator').hide();
|
||||
};
|
||||
|
||||
const handle_move_save = async ({ source_path, target_path, el_filedialog_window }) => {
|
||||
// source path must be in appdata directory
|
||||
const stat_info = await puter.fs.stat(source_path);
|
||||
if ( ! stat_info.appdata_app ) {
|
||||
await puter.ui.alert(`the app ${app_uuid} attempted to ` +
|
||||
`move data owned by the user illegaly`);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( stat_info.appdata_app !== app_uuid ) {
|
||||
await puter.ui.alert(`the app ${app_uuid} attempted to ` +
|
||||
`move data owned by ${stat_info.appdata_app}`);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('supposedly we\'re writing this file now');
|
||||
|
||||
const written = await window.handle_same_name_exists({
|
||||
action: async ({ overwrite }) => {
|
||||
if ( overwrite ) {
|
||||
await puter.fs.delete(target_path);
|
||||
}
|
||||
console.log('performing move operation', {source_path, target_path});
|
||||
await puter.fs.move(source_path, target_path);
|
||||
},
|
||||
parent_uuid: $(el_filedialog_window).attr('data-element_uuid'),
|
||||
});
|
||||
|
||||
if ( written ) return true;
|
||||
$(el_filedialog_window).find('.window-disable-mask, .busy-indicator').hide();
|
||||
};
|
||||
|
||||
await UIWindow({
|
||||
path: '/' + window.user.username + '/Desktop',
|
||||
@@ -1348,6 +1380,11 @@ const ipc_listener = async (event, handled) => {
|
||||
|
||||
if (event.data.url){
|
||||
done = await handle_url_save({ target_path });
|
||||
} else if ( event.data.source_path ) {
|
||||
done = await handle_move_save({
|
||||
source_path: event.data.source_path,
|
||||
target_path,
|
||||
});
|
||||
} else {
|
||||
done = await handle_data_save({ target_path, el_filedialog_window });
|
||||
}
|
||||
|
||||
@@ -2781,6 +2781,7 @@ window.handle_same_name_exists = async ({
|
||||
}) => {
|
||||
try {
|
||||
await action({ overwrite: false });
|
||||
return true;
|
||||
} catch ( err ) {
|
||||
if ( err.code !== 'item_with_same_name_exists' ) {
|
||||
console.error(err);
|
||||
|
||||
@@ -713,17 +713,22 @@ class UI extends EventListener {
|
||||
})
|
||||
}
|
||||
|
||||
showSaveFilePicker = function(content, suggestedName){
|
||||
showSaveFilePicker = function(content, suggestedName, type){
|
||||
return new Promise((resolve) => {
|
||||
const msg_id = this.#messageID++;
|
||||
const url = (Object.prototype.toString.call(content) === '[object URL]' ? content : undefined);
|
||||
if ( ! type && Object.prototype.toString.call(content) === '[object URL]' ) {
|
||||
type = 'url';
|
||||
}
|
||||
const url = type === 'url' ? content.toString() : undefined;
|
||||
const source_path = type === 'move' ? content : undefined;
|
||||
|
||||
if(this.env === 'app'){
|
||||
this.messageTarget?.postMessage({
|
||||
msg: "showSaveFilePicker",
|
||||
appInstanceID: this.appInstanceID,
|
||||
content: url ? undefined : content,
|
||||
url: url ? url.toString() : undefined,
|
||||
url,
|
||||
source_path,
|
||||
suggestedName: suggestedName ?? '',
|
||||
env: this.env,
|
||||
uuid: msg_id
|
||||
|
||||
Reference in New Issue
Block a user