Skip to content

Commit 1d19c50

Browse files
committed
[✨ Feat] Add settings for Aikari Telemetry
1 parent 8656fd0 commit 1d19c50

5 files changed

Lines changed: 202 additions & 4 deletions

File tree

src/aura/ui/aikari/onConnectedSeq.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,36 @@ const actions = {
4040
data: {},
4141
})
4242
);
43-
const promise = new Promise((resolve) => {
43+
const promiseForConfig = new Promise((resolve) => {
4444
wsGetCallbacks.set(eventId, resolve);
4545
});
46-
const data = await promise;
46+
const data = await promiseForConfig;
4747
if (data.success) {
4848
console.debug(
4949
"[HugoAura / UI / Aikari OCMS] Received Aikari launcher config: ",
5050
data
5151
);
52-
return data.data;
5352
} else {
5453
return null;
5554
}
55+
wsObj.send(
56+
JSON.stringify({
57+
module: "launcher",
58+
eventId,
59+
method: "config.actions.getTelemetryIsEnabled",
60+
data: {},
61+
})
62+
);
63+
const promiseForTelemetry = new Promise((resolve) => {
64+
wsGetCallbacks.set(eventId, resolve);
65+
});
66+
const telemetryConfig = await promiseForTelemetry;
67+
if (telemetryConfig.success) {
68+
data.data.telemetryEnabled = telemetryConfig.data.isEnabled;
69+
} else {
70+
data.data.telemetryEnabled = false;
71+
}
72+
return data.data;
5673
},
5774
getAikariPLSRules: async (wsObj) => {
5875
const eventId = genRandomHex();

src/aura/ui/composables/aikariConfigManager.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,46 @@ const updateAikariConfigToRemote = async (
8080
});
8181
};
8282

83+
/**
84+
*
85+
* @param {boolean} newValue
86+
*/
87+
const updateAikariTelemetryConfigToRemote = async (newValue) => {
88+
const aikariConfigUpdateEvent = new CustomEvent("onAikariConfigUpdate", {
89+
detail: {
90+
path: ["telemetry"],
91+
value: newValue,
92+
},
93+
});
94+
document.dispatchEvent(aikariConfigUpdateEvent);
95+
const settingsEntries = document.getElementsByClassName(
96+
"aura-settings-entry"
97+
);
98+
if (settingsEntries.length > 0) {
99+
Array.from(settingsEntries).forEach((entry) => {
100+
entry.dispatchEvent(aikariConfigUpdateEvent);
101+
});
102+
}
103+
104+
/**
105+
* @type {ClientAikariRequest}
106+
*/
107+
const data = {
108+
method: "config.actions.setTelemetryIsEnabled",
109+
data: {
110+
isEnabled: newValue,
111+
},
112+
eventId: genRandomHex(),
113+
module: "launcher",
114+
};
115+
116+
global.ipcRenderer.invoke(`${IPC_METHOD_BASE}.ws.sendWsMessage`, data);
117+
global.ipcRenderer.invoke(`${IPC_METHOD_BASE}.syncAikariConfig`, {
118+
basic: global.__HUGO_AURA__.aikariSettings,
119+
rules: global.__HUGO_AURA__.aikariRules,
120+
});
121+
};
122+
83123
// [!] Will be deprecated
84124
const updateAikariPLSRulesToRemote = async (
85125
configKey,
@@ -131,6 +171,7 @@ module.exports = {
131171
updateAikariRulesFromLocal,
132172
updateAikariStatusFromLocal,
133173
updateAikariSettingsFromLocal,
174+
updateAikariTelemetryConfigToRemote,
134175
updateAikariConfigToRemote,
135176
updateAikariPLSRulesToRemote,
136177
};

src/aura/ui/composables/settingsRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ const renderNormalSettingsItem = (entry, formEl) => {
380380
}
381381

382382
if (entry.aikariRequired) {
383-
if (!global.__HUGO_AURA__.aikariStats.connected) {
383+
if (!global.__HUGO_AURA__.aikariStats.connected && !entry.alwaysEnable) {
384384
setDisableStatus(entryOperationArea, true, "连接至 Aikari 以继续");
385385
}
386386

src/aura/ui/pages/configSubPages/behaviourCtrl/aikariStatus.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,14 @@ if (!global.__HUGO_AURA_UI_REACTIVES__.subConfig)
606606
const result = await ipcRenderer.invoke(
607607
`${IPC_METHOD_BASE}.retryAikariConnect`
608608
);
609+
if (
610+
!global.__HUGO_AURA__.aikariSettings ||
611+
(global.__HUGO_AURA__.aikariStats.connected === false &&
612+
global.__HUGO_AURA__.aikariStats.launched === true)
613+
) {
614+
ipcRenderer.invoke(`${IPC_METHOD_BASE}.forceReloadKeepAliveWin`);
615+
}
616+
609617
if (result.success && result.status === "Retrying") {
610618
updateOperationBtnStatus("Refresh", true, "正在重连");
611619

src/aura/ui/pages/configSubPages/behaviourCtrl/settings/basic.js

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
const REQUIRE_BASE = ".";
22

3+
const path = require("path");
4+
5+
const AIKARI_ROOT_DIR = path.join("C:\\ProgramData", "HugoAura", "Aikari");
6+
37
const {
48
updateAikariConfigToRemote,
9+
updateAikariTelemetryConfigToRemote,
510
} = require(`${REQUIRE_BASE}/../../../../composables/aikariConfigManager`);
611

712
const basicSettings = [
@@ -80,6 +85,133 @@ const basicSettings = [
8085
},
8186
],
8287
},
88+
{
89+
id: 1,
90+
categoryName: "分析",
91+
child: [
92+
{
93+
index: 0,
94+
id: "aikariTelemetryCtrl",
95+
type: "switch",
96+
name: "启用错误收集与分析",
97+
description: "启用后, Aikari 将在发生错误时上报自托管 Sentry",
98+
reactive: true,
99+
reactiveVal: ["root.settings"],
100+
restart: false,
101+
reload: false,
102+
aikariRequired: false,
103+
restartAikari: false,
104+
warning: true,
105+
warningContent:
106+
"我们不会收集您的设备用户名、管家内的学校名等信息, 也不会保存您的 IP 地址, 所有上传的数据仅供调试使用, 不会与任何第三方共享",
107+
associateVal: null,
108+
auraIf: () => true,
109+
defaultValue: false,
110+
valueGetter: () => {
111+
if (
112+
!global.__HUGO_AURA__.aikariSettings ||
113+
!global.__HUGO_AURA__.aikariStats.connected
114+
) {
115+
const fs = require("fs");
116+
return fs.existsSync(
117+
path.join(AIKARI_ROOT_DIR, ".telemetryEnabled")
118+
);
119+
} else {
120+
return global.__HUGO_AURA__.aikariSettings.telemetryEnabled;
121+
}
122+
},
123+
callbackFn: (newVal) => {
124+
if (
125+
!global.__HUGO_AURA__.aikariSettings ||
126+
!global.__HUGO_AURA__.aikariStats.connected
127+
) {
128+
if (newVal) {
129+
const fs = require("fs");
130+
fs.appendFile(
131+
path.join(AIKARI_ROOT_DIR, ".telemetryEnabled"),
132+
"",
133+
(err) => {
134+
if (err) console.warn(err);
135+
}
136+
);
137+
return true;
138+
} else {
139+
const fs = require("fs");
140+
try {
141+
fs.unlinkSync(path.join(AIKARI_ROOT_DIR, ".telemetryEnabled"));
142+
return true;
143+
} catch (err) {
144+
console.error("Error removing telemetry flag: ", err);
145+
}
146+
}
147+
} else {
148+
global.__HUGO_AURA__.aikariSettings.telemetryEnabled = newVal;
149+
updateAikariTelemetryConfigToRemote(newVal);
150+
return true;
151+
}
152+
},
153+
},
154+
{
155+
index: 1,
156+
id: "aikariTelemetryId",
157+
type: "button",
158+
style: "outline",
159+
name: "Aikari Telemetry ID",
160+
reactive: true,
161+
reactiveVal: ["telemetry"],
162+
restart: false,
163+
reload: false,
164+
aikariRequired: true,
165+
restartAikari: false,
166+
warning: true,
167+
warningContent: "此标识符完全在初始化时随机生成, 与设备特征无关",
168+
associateVal: ["telemetry"],
169+
auraIf: () => true,
170+
alwaysEnable: true,
171+
buttonContent: "复制",
172+
valueGetter: async () => {
173+
if (!global.__HUGO_AURA_UI_REACTIVES__.subConfig.behaviourCtrl)
174+
global.__HUGO_AURA_UI_REACTIVES__.subConfig.behaviourCtrl = {};
175+
const getIdPromise = new Promise((resolve) => {
176+
setTimeout(() => {
177+
const fs = require("fs");
178+
const telemetryIdPath = path.join(
179+
AIKARI_ROOT_DIR,
180+
".telemetryId"
181+
);
182+
if (fs.existsSync(telemetryIdPath)) {
183+
const fileContent = fs
184+
.readFileSync(telemetryIdPath, { encoding: "utf-8" })
185+
.trim();
186+
187+
global.__HUGO_AURA_UI_REACTIVES__.subConfig.behaviourCtrl.telemetryId =
188+
fileContent;
189+
resolve("标识符: " + fileContent);
190+
}
191+
global.__HUGO_AURA_UI_REACTIVES__.subConfig.behaviourCtrl.telemetryId =
192+
null;
193+
resolve("未能获取标识符, Aikari 未安装或未初始化");
194+
}, 1000);
195+
});
196+
return await getIdPromise;
197+
},
198+
callbackFn: async (event) => {
199+
if (
200+
global.__HUGO_AURA_UI_REACTIVES__.subConfig.behaviourCtrl
201+
.telemetryId
202+
) {
203+
await navigator.clipboard.writeText(
204+
global.__HUGO_AURA_UI_REACTIVES__.subConfig.behaviourCtrl
205+
.telemetryId
206+
);
207+
event.target.textContent = "已复制";
208+
} else {
209+
event.target.textContent = "复制失败";
210+
}
211+
},
212+
},
213+
],
214+
},
83215
];
84216

85217
module.exports = { basicSettings };

0 commit comments

Comments
 (0)