forked from HeyPuter/puter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_username_in_gui.js
86 lines (80 loc) · 4.06 KB
/
update_username_in_gui.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* Copyright (C) 2024 Puter Technologies Inc.
*
* This file is part of Puter.
*
* Puter is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const update_username_in_gui = function(new_username){
// ------------------------------------------------------------
// Update all item/window/... paths, with the new username
// ------------------------------------------------------------
$(':not([data-path=""]),:not([data-item-path=""])').each((i, el)=>{
const $el = $(el);
const attr_path = $el.attr('data-path');
const attr_item_path = $el.attr('data-item-path');
const attr_shortcut_to_path = $el.attr('data-shortcut_to_path');
// data-path
if(attr_path && attr_path !== 'null' && attr_path !== 'undefined'){
// /[username]
if(attr_path === '/' + window.user.username)
$el.attr('data-path', '/' + new_username);
// /[username]/...
else if (attr_path.startsWith('/' + window.user.username + '/'))
$el.attr('data-path', attr_path.replace('/' + window.user.username + '/', '/' + new_username + '/'));
// .window-navbar-path-dirname
if($el.hasClass('window-navbar-path-dirname') && attr_path === '/' + window.user.username)
$el.text(new_username)
// .window-navbar-path-input value
else if($el.hasClass('window-navbar-path-input')){
// /[username]
if(attr_path === '/' + window.user.username)
$el.val('/' + new_username);
// /[username]/...
else if (attr_path.startsWith('/' + window.user.username + '/'))
$el.val(attr_path.replace('/' + window.user.username + '/', '/' + new_username + '/'));
}
}
// data-shortcut_to_path
if(attr_shortcut_to_path && attr_shortcut_to_path !== '' && attr_shortcut_to_path !== 'null' && attr_shortcut_to_path !== 'undefined'){
// home dir
if(attr_shortcut_to_path === '/' + window.user.username)
$el.attr('data-shortcut_to_path', '/' + new_username);
// every other paths
else if(attr_shortcut_to_path.startsWith('/' + window.user.username + '/'))
$el.attr('data-shortcut_to_path', attr_shortcut_to_path.replace('/' + window.user.username + '/', '/' + new_username + '/'));
}
// data-item-path
if(attr_item_path && attr_item_path !== 'null' && attr_item_path !== 'undefined'){
// /[username]
if(attr_item_path === '/' + window.user.username)
$el.attr('data-item-path', '/' + new_username);
// /[username]/...
else if (attr_item_path.startsWith('/' + window.user.username + '/'))
$el.attr('data-item-path', attr_item_path.replace('/' + window.user.username + '/', '/' + new_username + '/'));
}
})
// todo update all window paths
$('.window').each((i, el)=>{
})
window.desktop_path = '/' + new_username + '/Desktop';
window.trash_path = '/' + new_username + '/Trash';
window.appdata_path = '/' + new_username + '/AppData';
window.docs_path = '/' + new_username + '/Documents';
window.pictures_path = '/' + new_username + '/Pictures';
window.videos_path = '/' + new_username + '/Videos';
window.desktop_path = '/' + new_username + '/Desktop';
window.home_path = '/' + new_username;
}
export default update_username_in_gui;