Debug tool related stuff.

This commit is contained in:
flash 2024-06-24 23:33:25 +00:00
parent ec00a19d79
commit 60e7cc39fb
4 changed files with 112 additions and 43 deletions

View file

@ -112,7 +112,7 @@ const MamiArgs = (argName, input, builder) => {
return blueprint; return blueprint;
}); });
const inputIsNull = input === null; const inputIsNull = input === undefined || input === null;
if(inputIsNull) if(inputIsNull)
input = {}; input = {};

View file

@ -1,3 +1,17 @@
const MamiIsEventTarget = value => {
if(typeof value !== 'object' || value === null)
return false;
if(typeof value.scopeTo !== 'function'
|| typeof value.create !== 'function'
|| typeof value.watch !== 'function'
|| typeof value.unwatch !== 'function'
|| typeof value.dispatch !== 'function')
return false;
return true;
};
const MamiEventTargetScoped = function(eventTarget, prefix) { const MamiEventTargetScoped = function(eventTarget, prefix) {
if(typeof eventTarget !== 'object' || eventTarget === null) if(typeof eventTarget !== 'object' || eventTarget === null)
throw 'eventTarget must be a non-null object'; throw 'eventTarget must be a non-null object';

View file

@ -1,6 +1,7 @@
window.Umi = { UI: {} }; window.Umi = { UI: {} };
#include animate.js #include animate.js
#include args.js
#include awaitable.js #include awaitable.js
#include common.js #include common.js
#include compat.js #include compat.js
@ -11,6 +12,7 @@ window.Umi = { UI: {} };
#include mobile.js #include mobile.js
#include mszauth.js #include mszauth.js
#include txtrigs.js #include txtrigs.js
#include uniqstr.js
#include users.js #include users.js
#include utility.js #include utility.js
#include weeb.js #include weeb.js
@ -48,52 +50,63 @@ window.Umi = { UI: {} };
#include ui/markup.js #include ui/markup.js
#include ui/view.js #include ui/view.js
(async () => { const MamiInit = async args => {
const eventTarget = new MamiEventTargetWindow; args = MamiArgs('args', args, define => {
define('parent').default(document.body).constraint(value => value instanceof Element).done();
define('eventTarget').required().constraint(MamiIsEventTarget).done();
define('settingsPrefix').default('umi-').done();
});
const ctx = new MamiContext(eventTarget); const ctx = new MamiContext(args.eventTarget);
Object.defineProperty(window, 'mami', { enumerable: true, value: ctx });
ctx.views = new MamiViewsControl({ body: document.body }); // remove this later and replace with the one commented out way below
ctx.msgbox = new MamiMessageBoxControl({ parent: document.body }); if(!('mami' in window))
Object.defineProperty(window, 'mami', { enumerable: true, value: ctx });
ctx.views = new MamiViewsControl({ body: args.parent });
ctx.msgbox = new MamiMessageBoxControl({ parent: args.parent });
const loadingOverlay = new Umi.UI.LoadingOverlay('spinner', 'Loading...'); const loadingOverlay = new Umi.UI.LoadingOverlay('spinner', 'Loading...');
await ctx.views.push(loadingOverlay); await ctx.views.push(loadingOverlay);
loadingOverlay.setMessage('Loading environment...'); if(!('futami' in window)) {
try { loadingOverlay.setMessage('Loading environment...');
window.futami = await FutamiCommon.load(); try {
} catch(ex) { window.futami = await FutamiCommon.load();
console.error('Failed to load common settings.', ex); } catch(ex) {
loadingOverlay.setIcon('cross'); console.error('Failed to load common settings.', ex);
loadingOverlay.setHeader('Failed!'); loadingOverlay.setIcon('cross');
loadingOverlay.setMessage('Failed to load common settings.'); loadingOverlay.setHeader('Failed!');
return; loadingOverlay.setMessage('Failed to load common settings.');
return;
}
} }
loadingOverlay.setMessage('Fetching credentials...'); if(!MamiMisuzuAuth.hasInfo()) {
try { loadingOverlay.setMessage('Fetching credentials...');
const auth = await MamiMisuzuAuth.update(); try {
if(!auth.ok) const auth = await MamiMisuzuAuth.update();
throw 'Authentication failed.'; if(!auth.ok)
} catch(ex) { throw 'Authentication failed.';
console.error(ex); } catch(ex) {
location.assign(futami.get('login')); console.error(ex);
return; location.assign(futami.get('login'));
} return;
}
setInterval(() => { setInterval(() => {
MamiMisuzuAuth.update() MamiMisuzuAuth.update()
.then(auth => { .then(auth => {
if(!auth.ok) if(!auth.ok)
location.assign(futami.get('login')); location.assign(futami.get('login'));
}) })
}, 600000); }, 600000);
}
loadingOverlay.setMessage('Loading settings...'); loadingOverlay.setMessage('Loading settings...');
const settings = new MamiSettings('umi-', ctx.events.scopeTo('settings')); const settings = new MamiSettings(args.settingsPrefix, ctx.events.scopeTo('settings'));
ctx.settings = settings; ctx.settings = settings;
settings.define('style').default('dark').create(); settings.define('style').default('dark').create();
@ -284,7 +297,7 @@ window.Umi = { UI: {} };
settings.watch('style', ev => { if(!ev.detail.initial) Umi.UI.View.AccentReload(); }); settings.watch('style', ev => { if(!ev.detail.initial) Umi.UI.View.AccentReload(); });
settings.watch('compactView', ev => { if(!ev.detail.initial) Umi.UI.View.AccentReload(); }); settings.watch('compactView', ev => { if(!ev.detail.initial) Umi.UI.View.AccentReload(); });
settings.watch('preventOverflow', ev => document.body.classList.toggle('prevent-overflow', ev.detail.value)); settings.watch('preventOverflow', ev => args.parent.classList.toggle('prevent-overflow', ev.detail.value));
settings.watch('tmpDisableOldThemeSys', ev => { if(!ev.detail.initial) Umi.UI.View.AccentReload(); }); settings.watch('tmpDisableOldThemeSys', ev => { if(!ev.detail.initial) Umi.UI.View.AccentReload(); });
settings.watch('minecraft', ev => { settings.watch('minecraft', ev => {
@ -565,7 +578,7 @@ window.Umi = { UI: {} };
sbSettings.category(category => { sbSettings.category(category => {
category.header('Settings'); category.header('Settings');
category.button('Import settings', () => { category.button('Import settings', () => {
(new MamiSettingsBackup(settings)).importUpload(document.body); (new MamiSettingsBackup(settings)).importUpload(args.parent);
}, ['Your current settings will be replaced with the ones in the export.', 'Are you sure you want to continue?']); }, ['Your current settings will be replaced with the ones in the export.', 'Are you sure you want to continue?']);
category.button('Export settings', () => { category.button('Export settings', () => {
const user = Umi.User.getCurrentUser(); const user = Umi.User.getCurrentUser();
@ -573,7 +586,7 @@ window.Umi = { UI: {} };
if(user !== null) if(user !== null)
fileName = `${user.name}'s settings.mami`; fileName = `${user.name}'s settings.mami`;
(new MamiSettingsBackup(settings)).exportDownload(document.body, fileName); (new MamiSettingsBackup(settings)).exportDownload(args.parent, fileName);
}); });
category.button('Reset settings', () => { category.button('Reset settings', () => {
settings.clear(); settings.clear();
@ -729,7 +742,7 @@ window.Umi = { UI: {} };
}, },
}, },
}); });
document.body.appendChild(uploadForm); args.parent.appendChild(uploadForm);
Umi.UI.InputMenus.AddButton('upload', 'Upload', () => uploadForm.click(), 'markup'); Umi.UI.InputMenus.AddButton('upload', 'Upload', () => uploadForm.click(), 'markup');
@ -741,10 +754,10 @@ window.Umi = { UI: {} };
}); });
// figure out how to display a UI for this someday // figure out how to display a UI for this someday
//document.body.addEventListener('dragenter', ev => { console.info('dragenter', ev); }); //args.parent.addEventListener('dragenter', ev => { console.info('dragenter', ev); });
//document.body.addEventListener('dragleave', ev => { console.info('dragleave', ev); }); //args.parent.addEventListener('dragleave', ev => { console.info('dragleave', ev); });
document.body.addEventListener('dragover', ev => { ev.preventDefault(); }); args.parent.addEventListener('dragover', ev => { ev.preventDefault(); });
document.body.addEventListener('drop', ev => { args.parent.addEventListener('drop', ev => {
if(ev.dataTransfer === undefined || ev.dataTransfer === null || ev.dataTransfer.files.length < 1) if(ev.dataTransfer === undefined || ev.dataTransfer === null || ev.dataTransfer.files.length < 1)
return; return;
@ -897,7 +910,7 @@ window.Umi = { UI: {} };
initWorker(); initWorker();
}); });
window.addEventListener('visibilitychange', () => { document.addEventListener('visibilitychange', () => {
if(document.visibilityState === 'visible') { if(document.visibilityState === 'visible') {
protoWorker.ping().catch(ex => { protoWorker.ping().catch(ex => {
console.warn('worker died', ex); console.warn('worker died', ex);
@ -907,4 +920,45 @@ window.Umi = { UI: {} };
}); });
await initWorker(); await initWorker();
return ctx;
};
(() => {
const eventTarget = new MamiEventTargetWindow;
Object.defineProperty(window, 'mamiEventTarget', { enumerable: true, value: eventTarget });
MamiInit({
eventTarget: eventTarget,
}).then(mami => {
//Object.defineProperty(window, 'mami', { enumerable: true, value: mami });
});
})(); })();
const MamiDbgCreateFloatingInstance = async () => {
if(!FUTAMI_DEBUG)
return;
const prefix = MamiUniqueStr(8);
const parent = $e({
attrs: {
style: {
position: 'absolute',
bottom: '100px',
right: '100px',
zIndex: '9001',
width: '640px',
height: '480px',
background: '#0f0',
},
},
});
document.body.appendChild(parent);
return await MamiInit({
parent: parent,
settingsPrefix: `dbg:${prefix}:`,
eventTarget: mamiEventTarget.scopeTo(prefix),
});
};

View file

@ -7,6 +7,7 @@ const MamiMisuzuAuth = (() => {
let authToken = null; let authToken = null;
return { return {
hasInfo: () => userId !== null && authToken !== null,
getUserId: () => userId, getUserId: () => userId,
getAuthToken: () => authToken, getAuthToken: () => authToken,
getLine: () => `${authMethod} ${authToken}`, getLine: () => `${authMethod} ${authToken}`,