mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-05 21:45:59 +02:00
enhance(frontend): お問い合わせページからデバイス情報を出力できるように (#16598)
* enhance(frontend): デバイス情報を出力できるように
* fix lint
* Update Changelog
* enhance: getHighEntropyValuesが使用できなかった場合のフォールバックを追加
* fix lint
* fix: getHighEntropyValuesが使用できない場合は生のUAを返すように
* enhance: getHighEntropyValuesが使用できる場合でも生のUAを含めるように
* ✌️
* onHeaderClicked -> onOpened
This commit is contained in:
66
packages/frontend/src/utility/get-user-environment.ts
Normal file
66
packages/frontend/src/utility/get-user-environment.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
export type UserEnvironment = {
|
||||
os: string;
|
||||
browser: string;
|
||||
userAgent: string;
|
||||
screenWidth: number;
|
||||
screenHeight: number;
|
||||
viaGetHighEntropyValues: true;
|
||||
} | {
|
||||
userAgent: string;
|
||||
screenWidth: number;
|
||||
screenHeight: number;
|
||||
viaGetHighEntropyValues: false;
|
||||
};
|
||||
|
||||
export async function getUserEnvironment(): Promise<UserEnvironment> {
|
||||
if ('userAgentData' in navigator && navigator.userAgentData != null) {
|
||||
try {
|
||||
const uaData: any = await navigator.userAgentData.getHighEntropyValues([
|
||||
'fullVersionList',
|
||||
'platformVersion',
|
||||
]);
|
||||
|
||||
let osVersion = 'v' + uaData.platformVersion;
|
||||
|
||||
if (uaData.platform === 'Windows' && uaData.platformVersion != null) {
|
||||
// https://learn.microsoft.com/ja-jp/microsoft-edge/web-platform/how-to-detect-win11
|
||||
const majorPlatformVersion = parseInt(uaData.platformVersion.split('.')[0]);
|
||||
if (majorPlatformVersion >= 13) {
|
||||
osVersion = '11 or later';
|
||||
} else if (majorPlatformVersion > 0) {
|
||||
osVersion = '10';
|
||||
} else {
|
||||
osVersion = '8.1 or earlier';
|
||||
}
|
||||
}
|
||||
|
||||
const browserData = uaData.fullVersionList.find((item) => !/^\s*not.+a.+brand\s*$/i.test(item.brand));
|
||||
return {
|
||||
os: `${uaData.platform} ${osVersion}`,
|
||||
browser: browserData ? `${browserData.brand} v${browserData.version}` : 'Unknown',
|
||||
userAgent: navigator.userAgent,
|
||||
screenWidth: window.innerWidth,
|
||||
screenHeight: window.innerHeight,
|
||||
viaGetHighEntropyValues: true,
|
||||
};
|
||||
} catch {
|
||||
return getViaUa();
|
||||
}
|
||||
} else {
|
||||
return getViaUa();
|
||||
}
|
||||
}
|
||||
|
||||
function getViaUa(): UserEnvironment {
|
||||
return {
|
||||
userAgent: navigator.userAgent,
|
||||
screenWidth: window.innerWidth,
|
||||
screenHeight: window.innerHeight,
|
||||
viaGetHighEntropyValues: false,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user