mirror of
https://github.com/h3poteto/whalebird-desktop
synced 2025-02-08 07:48:45 +01:00
Merge pull request #2330 from h3poteto/iss-267
refs #267 Update application menu and tray menu when add/remove accounts
This commit is contained in:
commit
020ee0c3f5
@ -70,7 +70,7 @@ export default class Authentication {
|
||||
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) {
|
||||
throw new Error('domain is required')
|
||||
}
|
||||
|
@ -458,9 +458,25 @@ type TokenRequest = {
|
||||
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 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) => {
|
||||
accountDB.findOne(
|
||||
{
|
||||
@ -494,6 +510,22 @@ ipcMain.handle('update-account', async (_: IpcMainInvokeEvent, acct: LocalAccoun
|
||||
|
||||
ipcMain.handle('remove-account', async (_: IpcMainInvokeEvent, id: string) => {
|
||||
const accountId = await accountManager.removeAccount(id)
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
stopUserStreaming(accountId)
|
||||
})
|
||||
|
||||
@ -514,6 +546,21 @@ ipcMain.handle('refresh-accounts', async (_: IpcMainInvokeEvent) => {
|
||||
|
||||
ipcMain.handle('remove-all-accounts', async (_: IpcMainInvokeEvent) => {
|
||||
await accountManager.removeAll()
|
||||
|
||||
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))
|
||||
}
|
||||
})
|
||||
|
||||
ipcMain.handle('change-auto-launch', async (_: IpcMainInvokeEvent, enable: boolean) => {
|
||||
|
@ -18,7 +18,7 @@ const actions: ActionTree<AuthorizeState, RootState> = {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -49,10 +49,15 @@ const actions: ActionTree<LoginState, RootState> = {
|
||||
confirmInstance: async ({ commit }, domain: string): Promise<boolean> => {
|
||||
commit(MUTATION_TYPES.CHANGE_SEARCHING, true)
|
||||
const cleanDomain = domain.trim()
|
||||
try {
|
||||
const sns = await detector(`https://${cleanDomain}`)
|
||||
commit(MUTATION_TYPES.CHANGE_SEARCHING, false)
|
||||
commit(MUTATION_TYPES.CHANGE_INSTANCE, cleanDomain)
|
||||
commit(MUTATION_TYPES.CHANGE_SNS, sns)
|
||||
} catch {
|
||||
return false
|
||||
} finally {
|
||||
commit(MUTATION_TYPES.CHANGE_SEARCHING, false)
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user