mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-10-21 00:51:29 -05:00
Update CurrentUser type
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import React, { useCallback, useMemo } from 'react';
|
||||
import { StyleSheet, Text } from 'react-native';
|
||||
import { CurrentUser } from '../../../api/coral-types.js';
|
||||
import { CurrentUserFriendCodeLink } from '../../../api/coral-types.js';
|
||||
import ipc from '../ipc.js';
|
||||
|
||||
export default function FriendCode(props: {
|
||||
friendcode: CurrentUser['links']['friendCode'];
|
||||
friendcode: CurrentUserFriendCodeLink;
|
||||
} | {
|
||||
id: string;
|
||||
}) {
|
||||
|
||||
@@ -6,7 +6,7 @@ export default function NintendoSwitchUser(props: {
|
||||
friend: Friend;
|
||||
nickname?: string;
|
||||
} | {
|
||||
user: CurrentUser;
|
||||
user: CurrentUser<true> | CurrentUser<false>;
|
||||
nickname?: string;
|
||||
}) {
|
||||
const user = 'friend' in props ? props.friend : props.user;
|
||||
|
||||
@@ -9,7 +9,7 @@ import { askAddNsoAccount, askAddPctlAccount } from './na-auth.js';
|
||||
import { App } from './index.js';
|
||||
import { EmbeddedPresenceMonitor } from './monitor.js';
|
||||
import { DiscordPresenceConfiguration, DiscordPresenceSource, DiscordStatus, LoginItemOptions, WindowType } from '../common/types.js';
|
||||
import { CurrentUser, Friend, Game, PresencePlatform, PresenceState, WebService } from '../../api/coral-types.js';
|
||||
import { CurrentUser, CurrentUserFriendCodeLink, Friend, Game, PresencePlatform, PresenceState, WebService } from '../../api/coral-types.js';
|
||||
import { NintendoAccountSessionTokenJwtPayload, NintendoAccountUser } from '../../api/na.js';
|
||||
import { DiscordPresence } from '../../discord/types.js';
|
||||
import { getDiscordRpcClients } from '../../discord/rpc.js';
|
||||
@@ -201,7 +201,7 @@ export function setupIpc(appinstance: App, ipcMain: IpcMain) {
|
||||
handle('misc:share', (e, item: SharingItem) =>
|
||||
new ShareMenu(item).popup({window: BrowserWindow.fromWebContents(e.sender)!}));
|
||||
|
||||
handle('menu:user', (e, user: NintendoAccountUser, nso?: CurrentUser, moon?: boolean) =>
|
||||
handle('menu:user', (e, user: NintendoAccountUser, nso?: CurrentUser<true> | CurrentUser<false>, moon?: boolean) =>
|
||||
(buildUserMenu(appinstance, user, nso, moon, BrowserWindow.fromWebContents(e.sender) ?? undefined)
|
||||
.popup({window: BrowserWindow.fromWebContents(e.sender)!}), undefined));
|
||||
handle('menu:add-user', e => (Menu.buildFromTemplate([
|
||||
@@ -212,7 +212,7 @@ export function setupIpc(appinstance: App, ipcMain: IpcMain) {
|
||||
(item: MenuItem, window: BrowserWindow | undefined, event: KeyboardEvent) =>
|
||||
askAddPctlAccount(appinstance, !event.shiftKey)}),
|
||||
]).popup({window: BrowserWindow.fromWebContents(e.sender)!}), undefined));
|
||||
handle('menu:friend-code', (e, fc: CurrentUser['links']['friendCode']) => (Menu.buildFromTemplate([
|
||||
handle('menu:friend-code', (e, fc: CurrentUserFriendCodeLink) => (Menu.buildFromTemplate([
|
||||
new MenuItem({label: 'SW-' + fc.id, enabled: false}),
|
||||
new MenuItem({label: t('friend_code.share')!, role: 'shareMenu', sharingItem: {texts: ['SW-' + fc.id]}}),
|
||||
new MenuItem({label: t('friend_code.copy')!, click: () => clipboard.writeText('SW-' + fc.id)}),
|
||||
@@ -223,7 +223,7 @@ export function setupIpc(appinstance: App, ipcMain: IpcMain) {
|
||||
formatParams: { date: { dateStyle: 'short', timeStyle: 'medium' } },
|
||||
})!, enabled: false}),
|
||||
]).popup({window: BrowserWindow.fromWebContents(e.sender)!}), undefined));
|
||||
handle('menu:friend', (e, user: NintendoAccountUser, nso: CurrentUser, friend: Friend) =>
|
||||
handle('menu:friend', (e, user: NintendoAccountUser, nso: CurrentUser<true> | CurrentUser<false>, friend: Friend) =>
|
||||
(buildFriendMenu(appinstance, user, nso, friend)
|
||||
.popup({window: BrowserWindow.fromWebContents(e.sender)!}), undefined));
|
||||
|
||||
@@ -255,7 +255,7 @@ export function sendToAllWindows(channel: string, ...args: any[]) {
|
||||
}
|
||||
}
|
||||
|
||||
function buildUserMenu(app: App, user: NintendoAccountUser, nso?: CurrentUser, moon?: boolean, window?: BrowserWindow) {
|
||||
function buildUserMenu(app: App, user: NintendoAccountUser, nso?: CurrentUser<true> | CurrentUser<false>, moon?: boolean, window?: BrowserWindow) {
|
||||
const t = app.i18n.getFixedT(null, 'menus', 'user');
|
||||
const dm = app.monitors.getActiveDiscordPresenceMonitor();
|
||||
const monitor = app.monitors.monitors.find(m => m instanceof EmbeddedPresenceMonitor &&
|
||||
@@ -307,7 +307,7 @@ function buildUserMenu(app: App, user: NintendoAccountUser, nso?: CurrentUser, m
|
||||
]);
|
||||
}
|
||||
|
||||
function buildFriendMenu(app: App, user: NintendoAccountUser, nso: CurrentUser, friend: Friend) {
|
||||
function buildFriendMenu(app: App, user: NintendoAccountUser, nso: CurrentUser<true> | CurrentUser<false>, friend: Friend) {
|
||||
const t = app.i18n.getFixedT(null, 'menus', 'friend');
|
||||
const discord_presence_source = app.monitors.getDiscordPresenceSource();
|
||||
const discord_presence_active = !!discord_presence_source && 'na_id' in discord_presence_source &&
|
||||
|
||||
@@ -574,7 +574,7 @@ export class ElectronNotificationManager extends NotificationManager {
|
||||
this.t = i18n.getFixedT(null, 'notifications');
|
||||
}
|
||||
|
||||
async onFriendOnline(friend: CurrentUser | Friend, prev?: CurrentUser | Friend, naid?: string, ir?: boolean) {
|
||||
async onFriendOnline(friend: CurrentUser<false> | Friend, prev?: CurrentUser<false> | Friend, naid?: string, ir?: boolean) {
|
||||
const currenttitle = friend.presence.game as PresenceGame;
|
||||
|
||||
new Notification({
|
||||
@@ -585,7 +585,7 @@ export class ElectronNotificationManager extends NotificationManager {
|
||||
}).show();
|
||||
}
|
||||
|
||||
async onFriendOffline(friend: CurrentUser | Friend, prev?: CurrentUser | Friend, naid?: string, ir?: boolean) {
|
||||
async onFriendOffline(friend: CurrentUser<false> | Friend, prev?: CurrentUser<false> | Friend, naid?: string, ir?: boolean) {
|
||||
new Notification({
|
||||
title: friend.name,
|
||||
body: this.t('offline')!,
|
||||
@@ -593,7 +593,7 @@ export class ElectronNotificationManager extends NotificationManager {
|
||||
}).show();
|
||||
}
|
||||
|
||||
async onFriendPlayingChangeTitle(friend: CurrentUser | Friend, prev?: CurrentUser | Friend, naid?: string, ir?: boolean) {
|
||||
async onFriendPlayingChangeTitle(friend: CurrentUser<false> | Friend, prev?: CurrentUser<false> | Friend, naid?: string, ir?: boolean) {
|
||||
const currenttitle = friend.presence.game as PresenceGame;
|
||||
|
||||
new Notification({
|
||||
@@ -604,7 +604,7 @@ export class ElectronNotificationManager extends NotificationManager {
|
||||
}).show();
|
||||
}
|
||||
|
||||
async onFriendTitleStateChange(friend: CurrentUser | Friend, prev?: CurrentUser | Friend, naid?: string, ir?: boolean) {
|
||||
async onFriendTitleStateChange(friend: CurrentUser<false> | Friend, prev?: CurrentUser<false> | Friend, naid?: string, ir?: boolean) {
|
||||
const currenttitle = friend.presence.game as PresenceGame;
|
||||
|
||||
new Notification({
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { SavedToken } from '../../common/auth/coral.js';
|
||||
import type { SavedMoonToken } from '../../common/auth/moon.js';
|
||||
import type { UpdateCacheData } from '../../common/update.js';
|
||||
import type { StatusUpdate } from '../../common/status.js';
|
||||
import type { Announcements_4, CoralSuccessResponse, CurrentUser, Friend, Friend_4, FriendCodeUrl, FriendCodeUser, GetActiveEventResult, ReceivedFriendRequests, SentFriendRequests, WebService, WebServices_4 } from '../../api/coral-types.js';
|
||||
import type { Announcements_4, CoralSuccessResponse, CurrentUser, CurrentUserFriendCodeLink, Friend, Friend_4, FriendCodeUrl, FriendCodeUser, GetActiveEventResult, ReceivedFriendRequests, SentFriendRequests, WebService, WebServices_4 } from '../../api/coral-types.js';
|
||||
import type { DiscordPresence } from '../../discord/types.js';
|
||||
import type { CachedErrorKey } from '../main/ipc.js';
|
||||
import type { DiscordSetupProps } from '../browser/discord/index.js';
|
||||
@@ -102,10 +102,10 @@ const ipc = {
|
||||
openExternalUrl: (url: string) => inv('misc:open-url', url),
|
||||
share: (item: SharingItem) => inv('misc:share', item),
|
||||
|
||||
showUserMenu: (user: NintendoAccountUserCoral | NintendoAccountUserMoon, nso?: CurrentUser, moon?: boolean) => inv('menu:user', user, nso, moon),
|
||||
showUserMenu: (user: NintendoAccountUserCoral | NintendoAccountUserMoon, nso?: CurrentUser<true> | CurrentUser<false>, moon?: boolean) => inv('menu:user', user, nso, moon),
|
||||
showAddUserMenu: () => inv('menu:add-user'),
|
||||
showFriendCodeMenu: (fc: CurrentUser['links']['friendCode']) => inv('menu:friend-code', fc),
|
||||
showFriendMenu: (user: NintendoAccountUserCoral, nso: CurrentUser, friend: Friend_4) => inv('menu:friend', user, nso, friend),
|
||||
showFriendCodeMenu: (fc: CurrentUserFriendCodeLink) => inv('menu:friend-code', fc),
|
||||
showFriendMenu: (user: NintendoAccountUserCoral, nso: CurrentUser<true> | CurrentUser<false>, friend: Friend_4) => inv('menu:friend', user, nso, friend),
|
||||
|
||||
registerEventListener: (event: string, listener: (args: any[]) => void) => events.on(event, listener),
|
||||
removeEventListener: (event: string, listener: (args: any[]) => void) => events.removeListener(event, listener),
|
||||
|
||||
Reference in New Issue
Block a user