Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/hub/manifest.ts
5965 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
// dynamically generate the manifest json file – for html5 web app's
7
8
import { Response } from "express";
9
import { join } from "path";
10
import { SiteSettingsKeys } from "@cocalc/util/db-schema/site-defaults";
11
import base_path from "@cocalc/backend/base-path";
12
13
// Control PWA installability -- https://github.com/sagemathinc/cocalc/issues/8474
14
// Keeps theme colors and styling but prevents Chrome's "Install app" prompt
15
const ENABLE_PWA_INSTALL = false;
16
17
interface Custom {
18
configuration: Record<SiteSettingsKeys, string>;
19
}
20
21
export function send(res: Response, custom: Custom) {
22
const config = custom.configuration;
23
24
// See https://developer.mozilla.org/en-US/docs/Web/Manifest, which says
25
// "the response of the manifest file should return Content-Type: application/manifest+json)"
26
res.header("Content-Type", "application/manifest+json");
27
28
const base_app = join(base_path, "app");
29
30
const manifest: any = {
31
name: config.site_name,
32
short_name: config.site_name,
33
start_url: `${base_app}?utm_medium=manifest`,
34
scope: base_path,
35
background_color: "#fbb635",
36
theme_color: "#4474c0",
37
description: config.site_description,
38
icons: [
39
{
40
src:
41
config.logo_square ??
42
"https://storage.googleapis.com/cocalc-extra/cocalc-icon-white-fillin.256px.png",
43
sizes: "256x256",
44
type: "image/png",
45
},
46
],
47
};
48
49
// Without that display property, browsers won't show the "Install app" prompt
50
if (ENABLE_PWA_INSTALL) {
51
manifest.display = "minimal-ui";
52
}
53
54
res.send(JSON.stringify(manifest, null, 2));
55
}
56
57