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
8// FIXME: not indexed as importable
9const Constants = spacepack.require("discord/Constants");
10const UserSettingsSections = spacepack.findObjectFromKey(
11 Constants,
12 "APPEARANCE_THEME_PICKER"
13);
14
15const { ThemeDarkIcon } = Components;
16
17function plural(str: string, num: number) {
18 return `${str}${num > 1 ? "s" : ""}`;
19}
20
21function listener() {
22 if (
23 MoonbaseSettingsStore.shouldShowNotice &&
24 MoonbaseSettingsStore.getExtensionConfigRaw(
25 "moonbase",
26 "updateBanner",
27 true
28 )
29 ) {
30 // @ts-expect-error epic type fail
31 MoonbaseSettingsStore.removeChangeListener(listener);
32
33 const version = MoonbaseSettingsStore.newVersion;
34 const extensionUpdateCount = Object.keys(
35 MoonbaseSettingsStore.updates
36 ).length;
37 const hasExtensionUpdates = extensionUpdateCount > 0;
38
39 let message;
40
41 if (version != null) {
42 message =
43 moonlightNode.branch === MoonlightBranch.NIGHTLY
44 ? `A new version of moonlight is available`
45 : `moonlight ${version} is available`;
46 }
47
48 if (hasExtensionUpdates) {
49 let concat = false;
50 if (message == null) {
51 message = "";
52 } else {
53 concat = true;
54 message += ", and ";
55 }
56 message += `${extensionUpdateCount} ${concat ? "" : "moonlight "}${plural(
57 "extension",
58 extensionUpdateCount
59 )} can be updated`;
60 }
61
62 if (message != null) message += ".";
63
64 Notices.addNotice({
65 element: (
66 <div className="moonbase-updates-notice_text-wrapper">
67 <ThemeDarkIcon size="sm" color="currentColor" />
68 {message}
69 </div>
70 ),
71 color: "moonbase-updates-notice",
72 buttons: [
73 {
74 name: "Open Moonbase",
75 onClick: () => {
76 const { open } = spacepack.findByExports(
77 "setSection",
78 "clearSubsection"
79 )[0].exports.Z;
80
81 // settings is lazy loaded thus lazily patched
82 // FIXME: figure out a way to detect if settings has been opened
83 // alreadyjust so the transition isnt as jarring
84 open(UserSettingsSections.ACCOUNT);
85 setTimeout(() => {
86 if (
87 MoonbaseSettingsStore.getExtensionConfigRaw<boolean>(
88 "moonbase",
89 "sections",
90 false
91 )
92 ) {
93 open("moonbase-extensions");
94 } else {
95 open("moonbase", 0);
96 }
97 }, 0);
98 return true;
99 }
100 }
101 ]
102 });
103 }
104}
105
106// @ts-expect-error epic type fail
107MoonbaseSettingsStore.addChangeListener(listener);