1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2025-02-08 07:48:45 +01:00

refs #267 Update application menu and tray menu when add accounts

This commit is contained in:
AkiraFukushima 2021-04-06 22:17:18 +09:00
parent 93272288f8
commit 049c4dd8e2
4 changed files with 29 additions and 8 deletions

View File

@ -70,7 +70,7 @@ export default class Authentication {
return res.url return res.url
} }
async getAccessToken(sns: 'mastodon' | 'pleroma' | 'misskey', code: string | null, proxy: ProxyConfig | false): Promise<string> { async getAndUpdateAccessToken(sns: 'mastodon' | 'pleroma' | 'misskey', code: string | null, proxy: ProxyConfig | false): Promise<string> {
if (!this.baseURL) { if (!this.baseURL) {
throw new Error('domain is required') throw new Error('domain is required')
} }

View File

@ -458,9 +458,25 @@ type TokenRequest = {
sns: 'mastodon' | 'pleroma' | 'misskey' sns: 'mastodon' | 'pleroma' | 'misskey'
} }
ipcMain.handle('get-access-token', async (_: IpcMainInvokeEvent, request: TokenRequest) => { ipcMain.handle('get-and-update-access-token', async (_: IpcMainInvokeEvent, request: TokenRequest) => {
const proxy = await proxyConfiguration.forMastodon() const proxy = await proxyConfiguration.forMastodon()
const token = await auth.getAccessToken(request.sns, request.code, proxy) const token = await auth.getAndUpdateAccessToken(request.sns, request.code, proxy)
// Update instance menu
const accounts = await listAccounts()
const accountsChange: Array<MenuItemConstructorOptions> = accounts.map((a, index) => {
return {
label: a.domain,
accelerator: `CmdOrCtrl+${index + 1}`,
click: () => changeAccount(a, index)
}
})
await updateApplicationMenu(accountsChange)
await updateDockMenu(accountsChange)
if (process.platform !== 'darwin' && tray !== null) {
tray.setContextMenu(TrayMenu(accountsChange, i18next))
}
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
accountDB.findOne( accountDB.findOne(
{ {

View File

@ -18,7 +18,7 @@ const actions: ActionTree<AuthorizeState, RootState> = {
code: request.code.trim() code: request.code.trim()
}) })
} }
const id = await win.ipcRenderer.invoke('get-access-token', req) const id = await win.ipcRenderer.invoke('get-and-update-access-token', req)
return id return id
} }
} }

View File

@ -49,10 +49,15 @@ const actions: ActionTree<LoginState, RootState> = {
confirmInstance: async ({ commit }, domain: string): Promise<boolean> => { confirmInstance: async ({ commit }, domain: string): Promise<boolean> => {
commit(MUTATION_TYPES.CHANGE_SEARCHING, true) commit(MUTATION_TYPES.CHANGE_SEARCHING, true)
const cleanDomain = domain.trim() const cleanDomain = domain.trim()
const sns = await detector(`https://${cleanDomain}`) try {
commit(MUTATION_TYPES.CHANGE_SEARCHING, false) const sns = await detector(`https://${cleanDomain}`)
commit(MUTATION_TYPES.CHANGE_INSTANCE, cleanDomain) commit(MUTATION_TYPES.CHANGE_INSTANCE, cleanDomain)
commit(MUTATION_TYPES.CHANGE_SNS, sns) commit(MUTATION_TYPES.CHANGE_SNS, sns)
} catch {
return false
} finally {
commit(MUTATION_TYPES.CHANGE_SEARCHING, false)
}
return true return true
} }
} }