Fix web template
This commit is contained in:
parent
9e3d215ca8
commit
eb7aa690c7
|
|
@ -1,21 +1,26 @@
|
||||||
{{ '{{flutter_js}}' }}
|
{{ '{{flutter_js}}' }}
|
||||||
{{ '{{flutter_build_config}}' }}
|
{{ '{{flutter_build_config}}' }}
|
||||||
|
|
||||||
var config = {};
|
var flutterConfig = {
|
||||||
if (globalThis.webRenderer != "auto") {
|
multiViewEnabled: flet.multiView,
|
||||||
config.renderer = globalThis.webRenderer;
|
assetBase: flet.assetBase
|
||||||
|
};
|
||||||
|
if (flet.webRenderer != "auto") {
|
||||||
|
flutterConfig.renderer = flet.webRenderer;
|
||||||
}
|
}
|
||||||
if (globalThis.canvasKitBaseUrl) {
|
if (flet.noCdn) {
|
||||||
config.canvasKitBaseUrl = globalThis.canvasKitBaseUrl;
|
flutterConfig.canvasKitBaseUrl = flet.canvasKitBaseUrl;
|
||||||
|
flutterConfig.fontFallbackBaseUrl = flet.fontFallbackBaseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
_flutter.loader.load({
|
_flutter.loader.load({
|
||||||
config: config,
|
config: flutterConfig,
|
||||||
serviceWorkerSettings: {
|
serviceWorkerSettings: {
|
||||||
serviceWorkerVersion: {{ '{{flutter_service_worker_version}}' }},
|
serviceWorkerVersion: {{flutter_service_worker_version}},
|
||||||
},
|
},
|
||||||
onEntrypointLoaded: async function (engineInitializer) {
|
onEntrypointLoaded: async function (engineInitializer) {
|
||||||
const appRunner = await engineInitializer.initializeEngine({useColorEmoji: useColorEmoji});
|
const engine = await engineInitializer.initializeEngine(flutterConfig);
|
||||||
await appRunner.runApp();
|
flet.flutterApp = await engine.runApp();
|
||||||
|
flet.flutterAppResolve(flet.flutterApp);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -11,33 +11,38 @@
|
||||||
<meta name="mobile-web-app-capable" content="yes">
|
<meta name="mobile-web-app-capable" content="yes">
|
||||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||||
<meta name="apple-mobile-web-app-title" content="{{ cookiecutter.product_name }}">
|
<meta name="apple-mobile-web-app-title" content="{{ cookiecutter.product_name }}">
|
||||||
<link rel="apple-touch-icon" href="icons/Icon-192.png">
|
<link rel="apple-touch-icon" href="icons/apple-touch-icon-192.png">
|
||||||
|
|
||||||
<!-- Favicon -->
|
<!-- Favicon -->
|
||||||
<link rel="icon" type="image/png" href="favicon.png" />
|
<link rel="icon" type="image/png" href="favicon.png" />
|
||||||
|
|
||||||
<!-- Flet specific -->
|
|
||||||
<meta name="flet-route-url-strategy" content="{{ cookiecutter.route_url_strategy }}">
|
|
||||||
<meta name="flet-web-pyodide" content="true">
|
|
||||||
|
|
||||||
<title>{{ cookiecutter.product_name }}</title>
|
<title>{{ cookiecutter.product_name }}</title>
|
||||||
<link rel="manifest" href="manifest.json">
|
<link rel="manifest" href="manifest.json">
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var webRenderer = "{{ cookiecutter.web_renderer }}";
|
var flet = {
|
||||||
var useColorEmoji = "{{ cookiecutter.use_color_emoji }}".toLowerCase() == "true";
|
pyodide: true,
|
||||||
var appPackageUrl = "assets/app/app.zip";
|
multiView: false,
|
||||||
var pythonModuleName = "{{ cookiecutter.python_module_name }}";
|
noCdn: "{{ cookiecutter.no_cdn }}".toLowerCase() == "true",
|
||||||
var noCdn = "{{ cookiecutter.no_cdn }}".toLowerCase() == "true";
|
webSocketEndpoint: "/ws",
|
||||||
</script>
|
assetBase: "/",
|
||||||
|
routeUrlStrategy: "{{ cookiecutter.route_url_strategy }}",
|
||||||
<script>
|
canvasKitBaseUrl: "/canvaskit/",
|
||||||
if (noCdn) {
|
pyodideUrl: "/pyodide/pyodide.js",
|
||||||
var canvasKitBaseUrl = "/canvaskit/";
|
pythonModuleName: "{{ cookiecutter.python_module_name }}",
|
||||||
var pyodideUrl = "/pyodide/pyodide.js";
|
webRenderer: "{{ cookiecutter.web_renderer }}",
|
||||||
|
fontFallbackBaseUrl: "assets/fonts/", // for Noto Emoji, use Google CDN
|
||||||
|
appPackageUrl: "assets/app/app.zip"
|
||||||
}
|
}
|
||||||
</script>
|
|
||||||
|
|
||||||
|
flet.flutterAppLoaded = new Promise((resolve) => {
|
||||||
|
flet.flutterAppResolve = resolve;
|
||||||
|
});
|
||||||
|
|
||||||
|
flet.flutterAppLoaded.then((flutterApp) => {
|
||||||
|
console.log("Flutter app loaded");
|
||||||
|
});
|
||||||
|
</script>
|
||||||
<script src="python.js"></script>
|
<script src="python.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
@ -45,4 +50,4 @@
|
||||||
<script src="flutter_bootstrap.js" async></script>
|
<script src="flutter_bootstrap.js" async></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -24,16 +24,16 @@ self.initPyodide = async function () {
|
||||||
|
|
||||||
if "app_package_url" in py_args:
|
if "app_package_url" in py_args:
|
||||||
app_package_url = py_args["app_package_url"]
|
app_package_url = py_args["app_package_url"]
|
||||||
|
|
||||||
if app_package_url is None:
|
if app_package_url is None:
|
||||||
app_package_url = "assets/app/app.zip"
|
app_package_url = "assets/app/app.zip"
|
||||||
|
|
||||||
if "python_module_name" in py_args:
|
if "python_module_name" in py_args:
|
||||||
python_module_name = py_args["python_module_name"]
|
python_module_name = py_args["python_module_name"]
|
||||||
|
|
||||||
if python_module_name is None:
|
if python_module_name is None:
|
||||||
python_module_name = "main"
|
python_module_name = "main"
|
||||||
|
|
||||||
if "micropip_include_pre" in py_args:
|
if "micropip_include_pre" in py_args:
|
||||||
micropip_include_pre = py_args["micropip_include_pre"]
|
micropip_include_pre = py_args["micropip_include_pre"]
|
||||||
|
|
||||||
|
|
@ -51,12 +51,12 @@ self.initPyodide = async function () {
|
||||||
print("Saving script to a file")
|
print("Saving script to a file")
|
||||||
with open(f"{python_module_name}.py", "w") as f:
|
with open(f"{python_module_name}.py", "w") as f:
|
||||||
f.write(py_args["script"]);
|
f.write(py_args["script"]);
|
||||||
|
|
||||||
pkgs_path = "__pypackages__"
|
pkgs_path = "__pypackages__"
|
||||||
if os.path.exists(pkgs_path):
|
if os.path.exists(pkgs_path):
|
||||||
print(f"Adding {pkgs_path} to sys.path")
|
print(f"Adding {pkgs_path} to sys.path")
|
||||||
sys.path.insert(0, pkgs_path)
|
sys.path.insert(0, pkgs_path)
|
||||||
|
|
||||||
if os.path.exists("requirements.txt"):
|
if os.path.exists("requirements.txt"):
|
||||||
with open("requirements.txt", "r") as f:
|
with open("requirements.txt", "r") as f:
|
||||||
deps = [line.rstrip() for line in f]
|
deps = [line.rstrip() for line in f]
|
||||||
|
|
@ -65,7 +65,7 @@ self.initPyodide = async function () {
|
||||||
|
|
||||||
if "dependencies" in py_args:
|
if "dependencies" in py_args:
|
||||||
await micropip.install(py_args["dependencies"], pre=micropip_include_pre)
|
await micropip.install(py_args["dependencies"], pre=micropip_include_pre)
|
||||||
|
|
||||||
# Execute app
|
# Execute app
|
||||||
runpy.run_module(python_module_name, run_name="__main__")
|
runpy.run_module(python_module_name, run_name="__main__")
|
||||||
`);
|
`);
|
||||||
|
|
@ -95,4 +95,4 @@ self.onmessage = async (event) => {
|
||||||
// message
|
// message
|
||||||
flet_js.send(event.data);
|
flet_js.send(event.data);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
const defaultPyodideUrl = "https://cdn.jsdelivr.net/pyodide/v0.27.5/full/pyodide.js";
|
const defaultPyodideUrl = "https://cdn.jsdelivr.net/pyodide/v0.27.7/full/pyodide.js";
|
||||||
|
|
||||||
let _apps = {};
|
let _apps = {};
|
||||||
let _documentUrl = document.URL;
|
let _documentUrl = document.URL;
|
||||||
|
|
@ -30,12 +30,12 @@ globalThis.jsConnect = async function(appId, args, dartOnMessage) {
|
||||||
|
|
||||||
// initialize worker
|
// initialize worker
|
||||||
app.worker.postMessage({
|
app.worker.postMessage({
|
||||||
pyodideUrl: globalThis.pyodideUrl ?? defaultPyodideUrl,
|
pyodideUrl: flet.noCdn ? flet.pyodideUrl : defaultPyodideUrl,
|
||||||
args: args,
|
args: args,
|
||||||
documentUrl: _documentUrl,
|
documentUrl: _documentUrl,
|
||||||
appPackageUrl: globalThis.appPackageUrl,
|
appPackageUrl: flet.appPackageUrl,
|
||||||
micropipIncludePre: globalThis.micropipIncludePre,
|
micropipIncludePre: flet.micropipIncludePre,
|
||||||
pythonModuleName: globalThis.pythonModuleName
|
pythonModuleName: flet.pythonModuleName
|
||||||
});
|
});
|
||||||
|
|
||||||
await pythonInitialized;
|
await pythonInitialized;
|
||||||
|
|
@ -67,4 +67,4 @@ globalThis.jsDisconnect = async function(appId) {
|
||||||
app.worker.onmessage = null;
|
app.worker.onmessage = null;
|
||||||
app.worker.onerror = null;
|
app.worker.onerror = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue