Cleaned up compatibility declarations.

This commit is contained in:
flash 2024-01-22 13:12:14 +00:00
parent 7564765317
commit 1c797565b7
3 changed files with 25 additions and 22 deletions

View file

@ -1,26 +1,32 @@
#include server.js
// backwards compat for scripts
if(!Umi) window.Umi = {};
const MamiCompat = (current, path, handler) => {
if(typeof path !== 'string')
throw 'path must be a string';
if(typeof handler !== 'function')
throw 'handler must be a function';
if(!Umi.Server) Umi.Server = {};
if(!Umi.Server.sendMessage) Umi.Server.sendMessage = function() { console.log('Umi.Server.sendMessage called'); };
if(!Umi.Server.SendMessage) Umi.Server.SendMessage = Umi.Server.sendMessage.bind(Umi.Server);
path = path.split('.');
if(!Umi.Protocol) Umi.Protocol = {};
if(!Umi.Protocol.SockLegacy) Umi.Protocol.SockLegacy = {};
if(!Umi.Protocol.SockLegacy.Protocol) Umi.Protocol.SockLegacy.Protocol = {};
if(!Umi.Protocol.SockLegacy.Protocol.Instance) Umi.Protocol.SockLegacy.Protocol.Instance = {};
if(!Umi.Protocol.SockLegacy.Protocol.Instance.SendMessage) Umi.Protocol.SockLegacy.Protocol.Instance.SendMessage = Umi.Server.sendMessage.bind(Umi.Server);
const final = path.pop();
if(final === undefined)
throw 'invalid path';
if(!Umi.Parser) Umi.Parser = {};
if(!Umi.Parser.SockChatBBcode) Umi.Parser.SockChatBBcode = {};
if(!Umi.Parser.SockChatBBcode.EmbedStub) Umi.Parser.SockChatBBcode.EmbedStub = function() {};
for(const part of path) {
if(!(part in current))
current[part] = {};
current = current[part];
}
if(!Umi.UI) Umi.UI = {};
if(!Umi.UI.View) Umi.UI.View = {};
if(!Umi.UI.View.SetText) Umi.UI.View.SetText = function() { console.log('Umi.UI.View.SetText called'); };
if(!(final in current))
current[final] = handler;
};
if(!Umi.UI.Menus) Umi.UI.Menus = {};
if(!Umi.UI.Menus.Add) Umi.UI.Menus.Add = function() { console.log('Umi.UI.Menus.Add called'); };
if(!Umi.UI.Menus.Get) Umi.UI.Menus.Get = function() { console.log('Umi.UI.Menus.Get called'); };
// Backwards compat for scripts
// Keep in sync with <https://fii.moe/fp/13176> for as long as possible
MamiCompat(Umi, 'Server.SendMessage', Umi.Server.sendMessage.bind(Umi.Server));
MamiCompat(Umi, 'Protocol.SockLegacy.Protocol.Instance.SendMessage', Umi.Server.sendMessage.bind(Umi.Server));
MamiCompat(Umi, 'Parser.SockChatBBcode.EmbedStub', function() {}); // intentionally a no-op
MamiCompat(Umi, 'UI.View.SetText', function() { console.log('Umi.UI.View.SetText called'); });
MamiCompat(Umi, 'UI.Menus.Add', function() { console.log('Umi.UI.Menus.Add called'); });
MamiCompat(Umi, 'UI.Menus.Get', function() { console.log('Umi.UI.Menus.Get called'); });

View file

@ -702,8 +702,6 @@ Umi.Settings = function(metaData) {
localStorage.removeItem(prefix + name);
};
removeRaw('cookiesMigrated');
const hasValue = function(name) {
if(!mutable.includes(name))
return false;

View file

@ -19,7 +19,6 @@
#include ui/loading-overlay.jsx
#include sound/umisound.js
if(!Umi) window.Umi = {};
if(!Umi.Protocol) Umi.Protocol = {};
if(!Umi.Protocol.SockChat) Umi.Protocol.SockChat = {};
if(!Umi.Protocol.SockChat.Protocol) Umi.Protocol.SockChat.Protocol = {};