Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ function registerCommands() {
commands.installKeybindings();
void keybindings.load();
report.init();
window.setTimeout(() => void update.check(false), 5000);
update.schedule(5000);
}

// ── 창 ─────────────────────────────────────────────────
Expand Down
23 changes: 17 additions & 6 deletions app/src/update.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
// 업데이트 확인. 시작할 때 하루 한 번 조용히 확인하고, 메뉴에서 직접 확인할 수도 있다.
// 업데이트 확인. 시작할 때마다, 그리고 켜 둔 동안 몇 시간마다 조용히 확인하고, 메뉴에서 직접 확인할 수도 있다.
// "나중에"로 닫은 버전은 이번 실행 동안 다시 띄우지 않는다 (다음에 켜면 다시 알린다).
// 설치 파일은 서명을 검증한 뒤에만 설치된다 (tauri.conf.json의 plugins.updater.pubkey).
import { invoke } from "@tauri-apps/api/core";
import { errorText } from "./api";
import { store } from "./dom";
import * as toast from "./toast";

interface UpdateInfo { version: string; notes: string | null }
const DAY = 24 * 60 * 60 * 1000;
const HOURS = 60 * 60 * 1000;
/** 켜 둔 동안 다시 확인하는 간격 */
const RECHECK = 6 * HOURS;

/** 이번 실행에서 이미 알린 버전 (알림이 떠 있거나 "나중에"로 닫음) */
const shown = new Set<string>();

async function install(version: string) {
const close = toast.show({ kind: "info", message: `Lantern ${version}을(를) 내려받는 중…`, detail: "설치가 끝나면 자동으로 다시 시작합니다.", timeout: 0 });
Expand All @@ -18,16 +23,16 @@ async function install(version: string) {
}
}

/** manual이면 결과(최신/실패)를 항상 알린다 */
/** manual이면 결과(최신/실패)를 항상 알리고, 이미 알린 버전도 다시 띄운다 */
export async function check(manual: boolean) {
if (!manual && Date.now() - store.get<number>("update.lastCheck", 0) < DAY) return;
store.set("update.lastCheck", Date.now());
try {
const u = await invoke<UpdateInfo | null>("check_update");
if (!u) {
if (manual) toast.success("최신 버전을 쓰고 있습니다");
return;
}
if (!manual && shown.has(u.version)) return;
shown.add(u.version);
toast.show({
kind: "info",
message: `새 버전 Lantern ${u.version}이(가) 있습니다`,
Expand All @@ -39,3 +44,9 @@ export async function check(manual: boolean) {
if (manual) toast.warn("업데이트를 확인하지 못했습니다", errorText(e));
}
}

/** 시작 직후 한 번, 그 뒤로 RECHECK마다 */
export function schedule(firstDelayMs: number) {
window.setTimeout(() => void check(false), firstDelayMs);
window.setInterval(() => void check(false), RECHECK);
}