## Problem and outcome / 问题与结果 App authorization could stay busy after a stalled save, a pending microphone request could survive a capture-source handoff, and compact room controls could lose focus, position or readable names. This maintenance phase corrects those owners and makes connection help easier to find. ## Verification / 验证 Validation: the exact candidate tree passed all 1,943 Web tests and documentation checks. Its unchanged product source has passed TypeScript and a production Web build. Controlled UI checks cover delayed microphone permission, stalled approval responses, keyboard viewport changes, rapid floating-panel hide/show and narrow nickname layouts. Published 2.x wire, native control and storage contracts are unchanged. ## Impact / 影响 Compatible 2.x maintenance release. Existing App, site and persisted room contracts are retained. Matching packages, download mirrors and both managed sites are verified through the normal release workflow. ## Release notes **Piik, now in your pocket.** Piik App supports Android screen sharing, with touch controls for a friend's computer. **手机,也能开播。** Piik App 支持 Android 屏幕分享,也能用手机控制朋友的电脑。 ### English This maintenance update improves App authorization, capture-source switching and controls on smaller screens. - Fix commentary controls remaining busy after switching from Browser capture to the App. - Let App site approval recover from a stalled save, keeping access already granted. - Preserve numeric-input focus when the mobile keyboard resizes the page, and provide increase/decrease buttons. Keep interaction windows at their remembered position after rapid hide/show actions. - Give nicknames readable space on smaller screens, while retaining edit controls and accessible labels. Keep launcher diagnostics inside the shared Help menu. - Make room-connection help easier to find, and clarify Safari screen-sharing and sound support. - Complete package mirroring after a later CI publication step fails, and verify managed-service deployments against the intended source revision. This maintenance update preserves the established 2.x room, invitation, media, App-control and storage contracts. Refresh a site's open pages after it is updated. App-local users need the updated App bundle to receive its included Web fixes. Existing compatible 2.x App/site workflows remain supported. ### 中文 本次维护更新改善 App 授权、切换分享源和小屏操作。 - 修复浏览器切换为 App 采集后,分享麦克风控制一直处于忙碌状态的问题。 - App 站点授权不再因保存卡住而一直转圈;可以重试,已批准的授权也会保留。 - 手机键盘改变页面尺寸时保留数字输入焦点,并提供增减按钮;互动窗口快速隐藏再打开后保留记忆位置。 - 小屏上为昵称保留可读空间,同时保留编辑入口与无障碍名称;启动页诊断统一收进帮助菜单。 - 更容易找到房间连接问题的排查入口,并说明 Safari 屏幕分享与声音的支持情况。 - 发布流程后续步骤失败时,仍可补全已经发布的程序包镜像;部署核验明确比对预期源码版本。 本维护更新保留既有 2.x 房间、邀请、媒体、App 控制与存储契约。 站点更新后请刷新已打开的网页;App 本地使用者需更新程序包,才能使用其中的新网页修复。 已有兼容的 2.x App/站点使用方式继续支持。
176 lines
7.7 KiB
TypeScript
176 lines
7.7 KiB
TypeScript
import { compare, major, valid } from "semver";
|
|
|
|
export const DEFAULT_RELEASE_API_URL =
|
|
"https://api.github.com/repos/TNTcraftHIM/Piik/releases/latest";
|
|
export const MIRROR_RELEASE_API_URL = "https://api.atomgit.com/api/v5/repos/TNTcraftHIM/Piik/releases";
|
|
const RELEASE_PAGE = "https://github.com/TNTcraftHIM/Piik/releases/tag/";
|
|
const MIRROR_RELEASE_PAGE = "https://atomgit.com/TNTcraftHIM/Piik/releases";
|
|
|
|
export interface ReleaseIdentity {
|
|
version: string;
|
|
revision: string;
|
|
}
|
|
export interface AppReleaseIdentity extends ReleaseIdentity {
|
|
packageTarget?: string;
|
|
}
|
|
interface PublishedRelease {
|
|
version: string;
|
|
revision: string | null;
|
|
url: string;
|
|
releaseURL: string;
|
|
publishedAt?: string;
|
|
}
|
|
export interface ReleaseUpdateNotice extends PublishedRelease {
|
|
kind: "update-available" | "major-update" | "different-build" | "official-release";
|
|
}
|
|
|
|
export function normalizeReleaseRevision(value: unknown): string | null {
|
|
const revision = typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
return /^[0-9a-f]{40}$/.test(revision) ? revision : null;
|
|
}
|
|
|
|
function normalizeVersion(value: unknown): string | null {
|
|
const version = typeof value === "string" ? valid(value) : null;
|
|
return version ? `v${version}` : null;
|
|
}
|
|
|
|
function packageDownloadURL(release: PublishedRelease, assets: unknown, target?: string): string {
|
|
if (!target || !/^[a-z0-9]+-[a-z0-9]+$/.test(target) || !Array.isArray(assets)) return release.url;
|
|
const extension = target === "android-universal" ? "apk" : "zip";
|
|
const mirror = release.releaseURL === MIRROR_RELEASE_PAGE;
|
|
const names = [`piik-app-${target}.${extension}`];
|
|
if (release.revision && extension === "zip") names.push(`piik-app-${target}-${release.revision.slice(0, 7)}.zip`);
|
|
for (const name of names) {
|
|
const matches = assets.filter(asset => asset?.name === name);
|
|
if (!matches.length) continue;
|
|
const asset = matches[0];
|
|
const expectedURL = mirror ? `${MIRROR_RELEASE_PAGE}/download/${release.version}/${name}`
|
|
: `${release.releaseURL.replace("/releases/tag/", "/releases/download/")}/${name}`;
|
|
return matches.length === 1 && (mirror ? asset.type === "attach" :
|
|
(Number.isSafeInteger(asset.size) && asset.size > 0 && asset.state === "uploaded")) &&
|
|
asset.browser_download_url === expectedURL ? asset.browser_download_url : release.url;
|
|
}
|
|
return release.url;
|
|
}
|
|
|
|
export function parseReleaseMetadata(value: unknown, packageTarget?: string): PublishedRelease | null {
|
|
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
const release = value as Record<string, unknown>;
|
|
if ((release.draft !== undefined && release.draft !== false) ||
|
|
(release.prerelease !== undefined && release.prerelease !== false)) return null;
|
|
const version = normalizeVersion(release.tag_name);
|
|
if (!version || version !== release.tag_name || !/^v\d+\.\d+\.\d+$/.test(version) ||
|
|
release.html_url !== RELEASE_PAGE + version) return null;
|
|
const publishedTime = typeof release.published_at === "string" && /^\d{4}-\d{2}-\d{2}T/.test(release.published_at)
|
|
? Date.parse(release.published_at) : NaN;
|
|
const normalized = {
|
|
version,
|
|
// GitHub permits a branch here; only our publisher's full SHA is provenance.
|
|
revision: normalizeReleaseRevision(release.target_commitish),
|
|
url: RELEASE_PAGE + version,
|
|
releaseURL: RELEASE_PAGE + version,
|
|
...(Number.isFinite(publishedTime) ? { publishedAt: new Date(publishedTime).toISOString() } : {}),
|
|
};
|
|
return { ...normalized, url: packageDownloadURL(normalized, release.assets, packageTarget) };
|
|
}
|
|
|
|
export function parseMirrorReleaseMetadata(value: unknown, packageTarget?: string): PublishedRelease | null {
|
|
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
const release = value as Record<string, unknown>;
|
|
if (release.prerelease !== false || typeof release.body !== "string") return null;
|
|
const sources = [...release.body.matchAll(/^<!-- piik-source: ([0-9a-f]{40}) -->\r?$/gm)];
|
|
if (sources.length !== 1) return null;
|
|
// The mirror publisher records original source identity in this marker.
|
|
const normalized = parseReleaseMetadata({
|
|
tag_name: release.tag_name, html_url: RELEASE_PAGE + String(release.tag_name),
|
|
target_commitish: sources[0][1],
|
|
});
|
|
if (!normalized) return null;
|
|
const mirror = { ...normalized, url: MIRROR_RELEASE_PAGE,
|
|
releaseURL: MIRROR_RELEASE_PAGE };
|
|
return { ...mirror, url: packageDownloadURL(mirror, release.assets, packageTarget) };
|
|
}
|
|
|
|
export function releaseUpdateNotice(
|
|
current: ReleaseIdentity,
|
|
latest: PublishedRelease,
|
|
): ReleaseUpdateNotice | null {
|
|
const version = normalizeVersion(current.version);
|
|
const revision = normalizeReleaseRevision(current.revision);
|
|
if (version) {
|
|
const order = compare(latest.version, version);
|
|
if (order > 0) return { ...latest,
|
|
kind: major(latest.version) > major(version) ? "major-update" : "update-available" };
|
|
if (order === 0 && revision && latest.revision && revision !== latest.revision) {
|
|
return { ...latest, kind: "different-build" };
|
|
}
|
|
return null;
|
|
}
|
|
return revision && latest.revision && revision !== latest.revision
|
|
? { ...latest, kind: "official-release" }
|
|
: null;
|
|
}
|
|
|
|
export async function checkReleaseUpdate(
|
|
current: ReleaseIdentity,
|
|
options: {
|
|
apiURL?: string;
|
|
mirrorAPIURL?: string;
|
|
fetchImpl?: typeof fetch;
|
|
timeoutMs?: number;
|
|
packageTarget?: string;
|
|
} = {},
|
|
): Promise<ReleaseUpdateNotice | null> {
|
|
if (!normalizeVersion(current.version) && !normalizeReleaseRevision(current.revision)) return null;
|
|
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
if (typeof fetchImpl !== "function") return null;
|
|
const sources = [
|
|
{ url: options.apiURL ?? DEFAULT_RELEASE_API_URL, mirror: false },
|
|
{ url: options.mirrorAPIURL ?? (options.apiURL ? undefined : MIRROR_RELEASE_API_URL), mirror: true },
|
|
];
|
|
for (const source of sources) {
|
|
if (!source.url) continue;
|
|
const controller = new AbortController();
|
|
const timer = globalThis.setTimeout(() => controller.abort(), options.timeoutMs ?? 3_000);
|
|
try {
|
|
const endpoint = new URL(source.url);
|
|
if (endpoint.protocol !== "https:" && endpoint.protocol !== "http:") continue;
|
|
let latest: PublishedRelease | null = null;
|
|
// Bound both time and pages. Never treat a truncated mirror list as latest.
|
|
for (let page = 1; page <= 10; page++) {
|
|
if (source.mirror) {
|
|
endpoint.searchParams.set("per_page", "100");
|
|
endpoint.searchParams.set("page", String(page));
|
|
endpoint.searchParams.set("direction", "desc");
|
|
}
|
|
const response = await fetchImpl(endpoint.toString(), {
|
|
cache: "no-store", credentials: "omit", redirect: "error", signal: controller.signal,
|
|
headers: source.mirror ? { Accept: "application/json" } :
|
|
{ Accept: "application/vnd.github+json", "X-GitHub-Api-Version": "2022-11-28" },
|
|
});
|
|
if (!response.ok) break;
|
|
const data: unknown = await response.json();
|
|
if (!source.mirror) {
|
|
latest = parseReleaseMetadata(data, options.packageTarget);
|
|
if (latest) return releaseUpdateNotice(current, latest);
|
|
break;
|
|
}
|
|
if (!Array.isArray(data) || data.length > 100) break;
|
|
for (const value of data) {
|
|
const candidate = parseMirrorReleaseMetadata(value, options.packageTarget);
|
|
if (candidate && (!latest || compare(candidate.version, latest.version) > 0)) latest = candidate;
|
|
}
|
|
if (data.length < 100) {
|
|
if (latest) return releaseUpdateNotice(current, latest);
|
|
break;
|
|
}
|
|
}
|
|
} catch {
|
|
// A blocked, timed-out or malformed provider leaves the next source usable.
|
|
} finally {
|
|
globalThis.clearTimeout(timer);
|
|
}
|
|
}
|
|
return null;
|
|
}
|