CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/browser.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { redux } from "./app-framework";
7
8
// Calling set_window_title will set the title, but also put a notification
9
// count to the left of the title; if called with no arguments just updates
10
// the count, maintaining the previous title.
11
type NotifyFunction = () => number;
12
let notify_count: NotifyFunction | undefined = undefined;
13
14
export function set_notify_count_function() {
15
const store = redux.getStore("file_use");
16
if (store == null) throw Error("file_use must be defined");
17
notify_count = store?.get_notify_count;
18
}
19
20
let last_title: string = "";
21
22
export function set_window_title(title?: string): void {
23
if (title == null) {
24
title = last_title;
25
}
26
last_title = title;
27
const u = notify_count?.();
28
if (u) {
29
title = `(${u}) ${title}`;
30
}
31
const site_name = redux.getStore("customize").get("site_name");
32
if (title.length > 0) {
33
document.title = title + " - " + site_name;
34
} else {
35
document.title = site_name;
36
}
37
}
38
39