$(window).on('xpboot', () => { xp.applications.add('uac_app', () => { var win = new Window({ width: 522, height: 462, title: 'User Accounts', canResize: false, }); win.content(`

Pick a task...

Change an account

Create a new account

or pick an account to change

`); function changeAccount(acct) { win.el.find('.outercontent').css('background-color', '#fff'); var acctname = acct.name === xp.profile.name ? 'your' : acct.name + '\'s'; var canDelete = ''; if (acct.name !== xp.profile.name) { canDelete = `

`; } win.el.find('.content').html(`

What do you want to change about ${acctname}
account?

Change ${acct.name === xp.profile.name ? 'my' : 'the'} name

Change ${acct.name === xp.profile.name ? 'my' : 'the'} picture

${canDelete}
${acct.name}
Computer administrator
 
 
`); win.el.find('.change_name').on('click', () => changeName(acct)); win.el.find('.change_picture').on('click', () => changePicture(acct)); win.el.find('.delete_account').on('click', () => deleteAccount(acct)); } function deleteAccount(acct) { win.el.find('.outercontent').css('background-color', '#fff'); var acctname = acct.name + '\'s'; win.el.find('.content').html(`

Do you want to keep ${acctname} files?

Before you delete ${acctname} account, Windows can automatically save the contents of ${acctname}
My Documents to a folder called ${acct.name} on your desktop. However, Windows
cannot save ${acctname} e-mail messages, Internet favorites, and other settings.


`); win.el.find('.keep').on('click', () => { xp.filesystem.moveDir('/Documents and Settings/' + acct.name + '/My Documents', '/Documents and Settings/' + xp.profile.name + '/My Documents/' + acct.name, () => { xp.filesystem.deleteDir('/Documents and Settings/' + acct.name, () => { win.close(); }); }); }); win.el.find('.delete').on('click', () => { xp.filesystem.deleteDir('/Documents and Settings/' + acct.name, () => { win.close(); }); }); win.el.find('.cancel').on('click', () => changeAccount(acct)); } function changeName(acct) { win.el.find('.outercontent').css('background-color', '#fff'); var acctname = acct.name === xp.profile.name ? 'your' : acct.name + '\'s'; win.el.find('.content').html(`

Provide a new name for ${acctname} account

Type a new name for ${acct.name}:

This name will appear on the Welcome screen and on the Start menu.
Note: Changing ${acctname} name will require a reboot.


`); win.el.find('.change').on('click', () => { var oldProfile = xp.profile; xp.profile = acct; var newUsername = win.el.find('.username').val(); if (xp.profile.name !== newUsername) { xp.filesystem.moveDir(`/Documents and Settings/${xp.profile.name}`, `/Documents and Settings/${newUsername}`, () => {}); xp.profile.name = newUsername; } saveConfig(() => { xp.profile = oldProfile; xp.alert('Changes have been applied.
Click OK to reboot your computer.', () => { window.location.href = window.location.href; }); }); }); win.el.find('.cancel').on('click', () => changeAccount(acct)); } function changePicture(acct) { win.el.find('.outercontent').css('background-color', '#fff'); var acctname = acct.name === xp.profile.name ? 'your' : acct.name + '\'s'; win.el.find('.content').html(`

Pick a new picture for ${acctname} account

The picture you choose will appear on the Welcome screen.
Note: Changing your picture will require a reboot.


`); if (win.el.find(`.userimgopt[src="${acct.image}"]`).length > 0) win.el.find(`.userimgopt[src="${acct.image}"]`).addClass('selected'); else win.el.find('.images').append(``); win.el.find('.userimgopt').on('click', function() { win.el.find('.userimgopt').each(function() { $(this).removeClass('selected'); }); $(this).addClass('selected'); }); win.el.find('.browse').on('click', () => { xp.filesystem.openFileDialog((file) => { xp.filesystem.toURL(file, (url) => { win.el.find('.userimgopt').each(function() { $(this).removeClass('selected'); }); var el = $($.parseHTML(``)); win.el.find('.images').append(el); el.find('img').on('click', function() { win.el.find('.userimgopt').each(function() { $(this).removeClass('selected'); }); $(this).addClass('selected'); }); }); }); }); win.el.find('.change').on('click', () => { var oldProfile = xp.profile; xp.profile = acct; xp.profile.image = win.el.find('.userimgopt.selected').attr('src'); saveConfig(() => { xp.profile = oldProfile; xp.alert('Changes have been applied.
Click OK to reboot your computer.', () => { window.location.href = window.location.href; }); }); }); win.el.find('.cancel').on('click', () => changeAccount(acct)); } function listAccounts() { xp.filesystem.listDir('/Documents and Settings', (acct) => { acct = acct.split('/')[0]; xp.filesystem.readFile(`/Documents and Settings/${acct}/config.json`, (file) => { var config = JSON.parse(file); var el = $.parseHTML(`
${acct}
`); $(el).find('img').on('click', () => changeAccount(config.profile)); win.el.find('.accounts').append(el); }); }); } listAccounts(); win.el.find('.cp_option.new_acct').on('click', () => { newAccount(); }); win.el.find('.cp_option.change_acct').on('click', () => { win.el.find('.outercontent').css('background-color', '#fff'); win.el.find('.content').html(`

Pick an account to change

`); listAccounts(); }); function newAccount() { let win = new Window({ width: 594, height: 434, title: 'Create New Account', canResize: false, center: true }); win.content(`

Create User Account

Choose a user name and picture

Your user name and picture represent your user account. The account you create here is a computer
administrator account. It is recommended to close all open applications before continuing.


Type a user name (for example, John)
 



`); win.el.find('.username').on('keyup', function() { console.log($(this).val()); if ($(this).val() === '') { win.el.find('.next').attr('disabled', 'disabled'); } else { win.el.find('.next').removeAttr('disabled'); } }); win.el.find('.next').on('click', function() { if (win.el.find('.username').val() === '') { xp.alert('You need to type a username in order to continue!'); } else { xp.profile.image = win.el.find('.userimgopt.selected').attr('src'); xp.profile.name = win.el.find('.username').val(); var oldConfigFile = configFile; configFile = `/Documents and Settings/${xp.profile.name}/config.json`; xp.wallpaper.href = 'https://cdn.glitch.com/01d2e04f-e49d-4304-aa9e-55b9849b4cce%2FBliss.jpg?1519950052202'; win.content(`

Please wait while we create the user account.

`); setTimeout(() => { requiredDirectories = [ `/Documents and Settings`, `/Documents and Settings/${xp.profile.name}`, `/Documents and Settings/${xp.profile.name}/My Documents`, `/Documents and Settings/${xp.profile.name}/My Documents/My Pictures`, `/Documents and Settings/${xp.profile.name}/My Documents/My Videos`, `/Documents and Settings/${xp.profile.name}/My Documents/My Music` ]; var i = 0; function createDirs() { var dirToCreate = requiredDirectories[i]; if (dirToCreate !== undefined) { xp.filesystem.createDir(dirToCreate, (e) => { i ++; createDirs(); }); } else { saveConfig(() => { configFile = oldConfigFile; loadConfig(() => { win.close(); }); }); } } createDirs(); }, 2000); } }); win.el.find('.userimgopt').on('click', function() { win.el.find('.userimgopt').each(function() { $(this).removeClass('selected'); }); $(this).addClass('selected'); win.el.find('.userimg').attr('src', $(this).attr('src')); }); } }); });