diff --git a/src/components/AddColumn/PublicTimeline.vue b/src/components/AddColumn/PublicTimeline.vue index 618357df..28508f76 100644 --- a/src/components/AddColumn/PublicTimeline.vue +++ b/src/components/AddColumn/PublicTimeline.vue @@ -68,7 +68,8 @@ type DeleteListener = (e: Event, id: number) => void type Instance = string type Timeline = { name: string - statuses?: Map + statuses: Map + error?: Error } type Timelines = Timeline[] type UpdateListener = (e: Event, status: Status) => void @@ -107,35 +108,36 @@ export default class AddColumn extends Vue { } public addTL() { - let timeline: Timeline = { name: this.instance } + let timeline: Timeline = { name: this.instance, statuses: new Map() } this.showInput = false this.instance = "" this.pubTL.push(timeline) // 最新のTLを取得 - this.loadTL(timeline) + ipcRenderer.once(`timeline-${timeline.name}-no-auth`, (e: Event, statuses: Status[], error?: Error) => { + timeline.error = error + if (error === undefined) { + this.loadTL(timeline, statuses) + } + this.$forceUpdate() + }) + ipcRenderer.send("no-auth-timeline", timeline.name) + } + + + public loadTL(timeline: Timeline, statuses: Status[]) { + timeline.statuses = new Map( + statuses.map((status): [number, Status] => [status.id, status]) + ) // streamingを開始 this.subscribeStreaming(timeline) } - public loadTL(timeline: Timeline) { - let statuses: Status[] = ipcRenderer.sendSync( - "no-auth-timeline", - timeline.name - ) - timeline.statuses = new Map( - statuses.map((status): [number, Status] => [status.id, status]) - ) - } - public async subscribeStreaming(timeline: Timeline) { // updateイベントを購読 let updateListener = (_: Event, status: Status) => { - if (timeline.statuses === undefined) { - timeline.statuses = new Map() - } timeline.statuses.set(status.id, status) this.$forceUpdate() } @@ -147,9 +149,6 @@ export default class AddColumn extends Vue { // deleteイベントを購読 let deleteListener = (_: Event, id: number) => { - if (timeline.statuses === undefined) { - timeline.statuses = new Map() - } timeline.statuses.delete(id) this.$forceUpdate() } diff --git a/src/main/Timeline.ts b/src/main/Timeline.ts index d60e699e..9adec9e0 100644 --- a/src/main/Timeline.ts +++ b/src/main/Timeline.ts @@ -11,8 +11,12 @@ export default class Timeline { public static ready() { ipcMain.on('no-auth-timeline', async (event: Event, name: string) => { const client = Client.getNoAuthClient(name) - let res: Response<[Status]> = await client.get<[Status]>('/timelines/public?local=true') - event.returnValue = res.data + try { + let res: Response<[Status]> = await client.get<[Status]>('/timelines/public?local=true') + event.sender.send(`timeline-${name}-no-auth`, res.data) + } catch (error) { + event.sender.send(`timeline-${name}-no-auth`, [], error) + } }) } } \ No newline at end of file