Build with assets; Misc app work

This commit is contained in:
octospacc 2023-04-24 15:03:51 +02:00
parent 2fc970d24c
commit efc4c49a7f
3 changed files with 68 additions and 11 deletions

View File

@ -1,11 +1,22 @@
function MakeWindow(Attrs) {
var Window = document.createElement('div');
function HtmlEl(Tag, Attrs) {
var El = document.createElement(Tag);
if (Attrs) {
Object.keys(Attrs).forEach(function(Attr){
Window[Attr] = Attrs[Attr];
El[Attr] = Attrs[Attr];
});
};
return El;
};
function MakeWindow(Attrs) {
var Window = HtmlEl('div', Attrs);
Window.className += ' Window';
Root.appendChild(Window);
return Window;
};
function Dropdown(Attrs) {
var Menu = HtmlEl('div', Attrs);
Window.className += ' Dropdown';
return Menu;
};

View File

@ -3,6 +3,16 @@ var Present = CopyObj(Persist);
var Tasker = {};
var ApiCache = {Urls: {},};
Assets._ = function _(Name) {
if (Name in Assets) {
if (Assets[Name].startsWith('data:')) {
return Assets[Name];
} else {
return `./Assets/${Assets[Name]}`;
};
};
};
function DoAsync(First, Then, Data) {
var Job = RndId();
Tasker[Job] = {
@ -149,10 +159,29 @@ function PostNote(Text) {
function ManageSettings() {
MakeWindow().innerHTML = `
* Sources
* Identities
* Data Import/Export
* Cache Persistance
<h2>Settings</h2>
<h3>Misc</h3>
<p>
Language: ${Dropdown()}
</p>
<p>
Theme:
</p>
<p>
<label>Wait <input type="number"/> seconds after clicking send for a note to be sent</label>
</p>
<h3>Identities</h3>
...
<h3>Sources</h3>
...
<h3>Data</h3>
<p>
<button>Import User Data</button>
<button>Export User Data</button>
</p>
<p>
<label><input type="checkbox"/> Persist cache on app reload</label>
</p>
`;
};

View File

@ -1,5 +1,7 @@
#!/usr/bin/env python3
import os
from base64 import b64encode
from mimetypes import guess_type
from pathlib import Path
os.chdir(os.path.dirname(os.path.abspath(__file__)))
@ -17,11 +19,26 @@ def FragReplace(Find, Replace, Pattern='*.*'):
with open(File, 'r') as Frag:
Frag = Replace.format(File=File, Frag=Frag.read())
for Prefix in ('', './'):
File = Prefix + File
Base = Base.replace(Find.format(File=File), Frag)
Name = Prefix + File
Base = Base.replace(Find.format(File=Name), Frag)
#BaseNew = []
#BaseNew += Base.split('<script data-build-json="true">')
BaseNew = ''
Split = '<script data-build-json="true">'
Frags = Base.split(Split)
BaseNew += Frags[0] + Split
Split = '</script>'
Frags = Frags[1].split(Split)
for File in Path('./Assets').rglob('*.*'):
File = str(File)
Mime = guess_type(File)
Mime = (Mime[0] if Mime else 'application/octet-stream')
with open(File, 'rb') as Frag:
Frag = b64encode(Frag.read()).decode()
for Prefix in ('', './'):
Name = Prefix + '/'.join(File.split('/')[1:])
Frags[0] = Frags[0].replace(f'"{Name}"', f'"data:{Mime};base64,{Frag}"')
BaseNew += Split.join(Frags)
Base = BaseNew
FragReplace('<link rel="stylesheet" href="{File}"/>', '<style data-source="{File}">{Frag}</style>', '*.css')
FragReplace('<script src="{File}"></script>', '<script data-source="{File}">{Frag}</script>', '*.js')