mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-08-01 19:21:34 -07:00
feat(notifications): add overlay notifications with position config (#110)
This commit is contained in:
@@ -15,6 +15,7 @@ export interface UpdateCheckRequest {
|
||||
source: UpdateCheckSource;
|
||||
force?: boolean;
|
||||
launcherPath?: string;
|
||||
installWhenAvailable?: boolean;
|
||||
}
|
||||
|
||||
export type UpdateCheckStatus =
|
||||
@@ -107,7 +108,14 @@ function summarizeError(error: unknown): string {
|
||||
}
|
||||
|
||||
export function createUpdateService(deps: UpdateServiceDeps) {
|
||||
const inFlightBySource = new Map<UpdateCheckSource, Promise<UpdateCheckResult>>();
|
||||
const inFlightBySource = new Map<string, Promise<UpdateCheckResult>>();
|
||||
|
||||
function getInFlightKey(request: UpdateCheckRequest): string {
|
||||
if (request.source === 'manual') {
|
||||
return request.installWhenAvailable ? 'manual:install' : 'manual:check';
|
||||
}
|
||||
return request.source;
|
||||
}
|
||||
|
||||
async function runCheck(request: UpdateCheckRequest): Promise<UpdateCheckResult> {
|
||||
const now = deps.now();
|
||||
@@ -164,9 +172,11 @@ export function createUpdateService(deps: UpdateServiceDeps) {
|
||||
return { status: 'update-available', version: latest.version };
|
||||
}
|
||||
|
||||
const choice = await deps.showUpdateAvailableDialog(latest.version);
|
||||
if (choice === 'close') {
|
||||
return { status: 'update-available', version: latest.version };
|
||||
if (!request.installWhenAvailable) {
|
||||
const choice = await deps.showUpdateAvailableDialog(latest.version);
|
||||
if (choice === 'close') {
|
||||
return { status: 'update-available', version: latest.version };
|
||||
}
|
||||
}
|
||||
|
||||
const canInstallAppUpdate = appUpdate.available && appUpdate.canUpdate !== false;
|
||||
@@ -203,12 +213,13 @@ export function createUpdateService(deps: UpdateServiceDeps) {
|
||||
|
||||
return {
|
||||
checkForUpdates(request: UpdateCheckRequest): Promise<UpdateCheckResult> {
|
||||
const inFlight = inFlightBySource.get(request.source);
|
||||
const key = getInFlightKey(request);
|
||||
const inFlight = inFlightBySource.get(key);
|
||||
if (inFlight) return inFlight;
|
||||
const nextInFlight = runCheck(request).finally(() => {
|
||||
inFlightBySource.delete(request.source);
|
||||
inFlightBySource.delete(key);
|
||||
});
|
||||
inFlightBySource.set(request.source, nextInFlight);
|
||||
inFlightBySource.set(key, nextInFlight);
|
||||
return nextInFlight;
|
||||
},
|
||||
startAutomaticChecks(options: { startupDelayMs?: number; pollIntervalMs?: number } = {}): void {
|
||||
|
||||
Reference in New Issue
Block a user