this repo has no description
1import spacepack from "@moonlight-mod/wp/spacepack_spacepack";
2import { MoonbaseSettingsStore } from "@moonlight-mod/wp/moonbase_stores";
3import Notices from "@moonlight-mod/wp/notices_notices";
4import { MoonlightBranch } from "@moonlight-mod/types";
5import React from "@moonlight-mod/wp/react";
6import * as Components from "@moonlight-mod/wp/discord/components/common/index";
7
8const { ThemeDarkIcon } = Components;
9
10function plural(str: string, num: number) {
11 return `${str}${num > 1 ? "s" : ""}`;
12}
13
14function listener() {
15 if (
16 MoonbaseSettingsStore.shouldShowNotice &&
17 MoonbaseSettingsStore.getExtensionConfigRaw("moonbase", "updateBanner", true)
18 ) {
19 MoonbaseSettingsStore.removeChangeListener(listener);
20
21 const version = MoonbaseSettingsStore.newVersion;
22 const extensionUpdateCount = Object.keys(MoonbaseSettingsStore.updates).length;
23 const hasExtensionUpdates = extensionUpdateCount > 0;
24
25 let message;
26
27 if (version != null) {
28 message =
29 moonlightNode.branch === MoonlightBranch.NIGHTLY
30 ? `A new version of moonlight is available`
31 : `moonlight ${version} is available`;
32 }
33
34 if (hasExtensionUpdates) {
35 let concat = false;
36 if (message == null) {
37 message = "";
38 } else {
39 concat = true;
40 message += ", and ";
41 }
42 message += `${extensionUpdateCount} ${concat ? "" : "moonlight "}${plural(
43 "extension",
44 extensionUpdateCount
45 )} can be updated`;
46 }
47
48 if (message != null) message += ".";
49
50 Notices.addNotice({
51 element: (
52 <div className="moonbase-updates-notice_text-wrapper">
53 <ThemeDarkIcon size="sm" color="currentColor" />
54 {message}
55 </div>
56 ),
57 color: "moonbase-updates-notice",
58 buttons: [
59 {
60 name: "Open Moonbase",
61 onClick: () => {
62 const { open } = spacepack.findByExports("setSection", "clearSubsection")[0].exports.Z;
63 if (MoonbaseSettingsStore.getExtensionConfigRaw<boolean>("moonbase", "sections", false)) {
64 open("moonbase-extensions");
65 } else {
66 MoonbaseSettingsStore.showOnlyUpdateable = true;
67 open("moonbase", 0);
68 }
69 return true;
70 }
71 }
72 ]
73 });
74 }
75}
76
77MoonbaseSettingsStore.addChangeListener(listener);