feat: Initial clean release of CHM
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
这个提交包含在:
85
packages/lib/ntp.ts
普通文件
85
packages/lib/ntp.ts
普通文件
@@ -0,0 +1,85 @@
|
||||
import shim from './shim';
|
||||
import time from './time';
|
||||
const ntpClient_ = require('./vendor/ntp-client');
|
||||
|
||||
interface NtpServer {
|
||||
domain: string;
|
||||
port: number;
|
||||
}
|
||||
|
||||
function ntpClient() {
|
||||
ntpClient_.dgram = shim.dgram();
|
||||
return ntpClient_;
|
||||
}
|
||||
|
||||
const parseNtpServer = (ntpServer: string): NtpServer => {
|
||||
const s = ntpServer.split(':');
|
||||
if (s.length !== 2) throw new Error('NTP server URL must be in format `domain:port`');
|
||||
return {
|
||||
domain: s[0],
|
||||
port: Number(s[1]),
|
||||
};
|
||||
};
|
||||
|
||||
export async function getNetworkTime(ntpServer: string): Promise<Date> {
|
||||
return new Promise<Date>((resolve, reject) => {
|
||||
const s = parseNtpServer(ntpServer);
|
||||
ntpClient().getNetworkTime(s.domain, s.port, (error: Error | null, date: Date) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(date);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export async function getDeviceTimeDrift(ntpServer: string): Promise<number> {
|
||||
const maxTries = 3;
|
||||
let tryCount = 0;
|
||||
|
||||
let ntpTime: Date = null;
|
||||
|
||||
while (true) {
|
||||
tryCount++;
|
||||
try {
|
||||
ntpTime = await getNetworkTime(ntpServer);
|
||||
break;
|
||||
} catch (error) {
|
||||
if (tryCount >= maxTries) {
|
||||
const newError = typeof error === 'string' ? new Error(error) : error;
|
||||
newError.message = `Cannot retrieve the network time from ${ntpServer}: ${newError.message}`;
|
||||
throw newError;
|
||||
} else {
|
||||
await time.msleep(tryCount * 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ntpTime.getTime() - Date.now();
|
||||
}
|
||||
|
||||
// export default async function(): Promise<Date> {
|
||||
// if (shouldSyncTime()) {
|
||||
// const release = await fetchingTimeMutex.acquire();
|
||||
|
||||
// try {
|
||||
// if (shouldSyncTime()) {
|
||||
// const date = await networkTime();
|
||||
// nextSyncTime = Date.now() + 60 * 1000;
|
||||
// timeOffset = date.getTime() - Date.now();
|
||||
// }
|
||||
// } catch (error) {
|
||||
// logger.warn('Could not get NTP time - falling back to device time:', error);
|
||||
// // Fallback to device time since
|
||||
// // most of the time it's actually correct
|
||||
// nextSyncTime = Date.now() + 20 * 1000;
|
||||
// timeOffset = 0;
|
||||
// } finally {
|
||||
// release();
|
||||
// }
|
||||
// }
|
||||
|
||||
// return new Date(Date.now() + timeOffset);
|
||||
// }
|
||||
在新工单中引用
屏蔽一个用户