Skip to content
Open
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
8 changes: 7 additions & 1 deletion src/controllers/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { FileSaveConfig } from "../models/configs/FileSaveConfig";
import { DashboardConfig } from "../models/configs/DashboardConfig";
import { DamageSnapshotConfig, DamageSnapshotMode } from "../models/configs/DamageSnapshotConfig";
import { GameWindowConfig } from "../models/configs/GameWindowConfig";
import { Logbook } from "../models/Logbook";
import { NotificationService } from "../services/NotificationService";

const onMessage = new Router<typeof chrome.runtime.onMessage>();
Expand Down Expand Up @@ -84,6 +85,11 @@ onMessage.on("/damage-snapshot/capture", async (req, sender) => {
const img = await WorkerImage.from(raw);
const uri = await (new CropService(img)).crop("damagesnapshot");

// 海域と連戦数の情報を取得
const sortie = Logbook.sortie;
const seaAreaInfo = sortie.map ? `${sortie.map.area}-${sortie.map.info}` : "";
const battleCount = sortie.battles.length;

const config = await DamageSnapshotConfig.user();
switch (config.mode) {
case DamageSnapshotMode.DISABLED:
Expand All @@ -93,7 +99,7 @@ onMessage.on("/damage-snapshot/capture", async (req, sender) => {
case DamageSnapshotMode.SEPARATE: {
const win = await Launcher.damagesnapshot(config);
if (!win || !win.tabs || !win.tabs[0].id) throw new Error("Failed to get damage snapshot window");
return chrome.tabs.sendMessage(win.tabs[0].id, { __action__: "/dsnapshot/separate:push", uri, timestamp });
return chrome.tabs.sendMessage(win.tabs[0].id, { __action__: "/dsnapshot/separate:push", uri, timestamp, seaArea: seaAreaInfo, battleCount });
}
}
});
Expand Down
15 changes: 12 additions & 3 deletions src/page/snapshot/DamageSnapshotPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@ import { useEffect, useState } from "react"

export function DamageSnapshotPage() {
const [uris, setURIs] = useState<string[]>([]);

useEffect(() => {
chrome.runtime.onMessage.addListener((msg) => {
if (msg.__action__ === "/dsnapshot/separate:push") {
setURIs((prev) => [...prev, msg.uri as string]);
const { uri, seaArea, battleCount } = msg;
setURIs((prev) => [...prev, uri]);

// タイトルを海域と連戦数で更新
if (seaArea && battleCount) {
document.title = `${seaArea} (${battleCount}) - 艦隊状況`;
} else if (seaArea) {
document.title = `${seaArea} - 艦隊状況`;
} else {
document.title = "艦隊状況";
}
}
});
// TODO: どの海域の何戦目かを表示するタイトルにする
document.title = "艦隊状況";
// TODO: このウィンドウのサイズ・位置を保存して次回起動時に復元する
}, []);
return (
Expand Down