signal-desktop/ts/window.d.ts

328 lines
11 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2020 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
// Captures the globals put in place by preload.js, background.js and others
2022-09-06 20:51:34 +00:00
import type { Store } from 'redux';
import type * as Backbone from 'backbone';
import type PQueue from 'p-queue/dist';
import type { assert } from 'chai';
import type { PhoneNumber, PhoneNumberFormat } from 'google-libphonenumber';
2024-06-28 00:22:06 +00:00
import type { MochaOptions } from 'mocha';
2023-04-10 21:30:33 +00:00
import type { ConversationModelCollectionType } from './model-types.d';
2022-09-06 20:51:34 +00:00
import type { textsecure } from './textsecure';
import type { Storage } from './textsecure/Storage';
import type {
ChallengeHandler,
IPCRequest as IPCChallengeRequest,
} from './challenge';
2023-01-13 00:24:59 +00:00
import type AccountManager from './textsecure/AccountManager';
2022-09-06 20:51:34 +00:00
import type { WebAPIConnectType } from './textsecure/WebAPI';
import type { CallingClass } from './services/calling';
import type * as StorageService from './services/storage';
2024-03-15 14:20:33 +00:00
import type { BackupsService } from './services/backups';
2022-09-06 20:51:34 +00:00
import type * as Groups from './groups';
import type * as Crypto from './Crypto';
import type * as Curve from './Curve';
import type * as RemoteConfig from './RemoteConfig';
import type { OSType } from './util/os/shared';
2024-11-06 02:05:24 +00:00
import type { LocalizerType, SystemThemeType, ThemeType } from './types/Util';
import type { Receipt } from './types/Receipt';
2022-09-06 20:51:34 +00:00
import type { ConversationController } from './ConversationController';
import type { ReduxActions } from './state/types';
import type { createApp } from './state/roots/createApp';
import type { MessageModel } from './models/messages';
import type { ConversationModel } from './models/conversations';
2023-04-11 03:54:43 +00:00
import type { BatcherType } from './util/batcher';
2022-09-06 20:51:34 +00:00
import type { ConfirmationDialog } from './components/ConfirmationDialog';
import type { SignalProtocolStore } from './SignalProtocolStore';
import type { SocketStatus } from './types/SocketStatus';
import type { ScreenShareStatus } from './types/Calling';
2022-09-06 20:51:34 +00:00
import type SyncRequest from './textsecure/SyncRequest';
import type { MessageCache } from './services/MessageCache';
2022-09-06 20:51:34 +00:00
import type { StateType } from './state/reducer';
import type { Address } from './types/Address';
import type { QualifiedAddress } from './types/QualifiedAddress';
2023-01-13 00:24:59 +00:00
import type { CIType } from './CI';
2022-09-06 20:51:34 +00:00
import type { IPCEventsType } from './util/createIPCEvents';
import type { SignalContextType } from './windows/context';
import type * as Message2 from './types/Message2';
import type { initializeMigrations } from './signal';
2023-04-10 21:30:33 +00:00
import type { RetryPlaceholders } from './util/retryPlaceholders';
import type { PropsPreloadType as PreferencesPropsType } from './components/Preferences';
2023-08-01 16:06:29 +00:00
import type { WindowsNotificationData } from './services/notifications';
2024-10-28 17:11:19 +00:00
import type { QueryStatsOptions } from './sql/main';
2020-09-04 01:25:19 +00:00
export { Long } from 'long';
2023-01-13 00:24:59 +00:00
export type IPCType = {
addSetupMenuItems: () => void;
2023-08-01 16:06:29 +00:00
clearAllWindowsNotifications: () => Promise<void>;
2023-01-13 00:24:59 +00:00
closeAbout: () => void;
crashReports: {
getCount: () => Promise<number>;
writeToLog: () => Promise<void>;
2023-01-13 00:24:59 +00:00
erase: () => Promise<void>;
};
drawAttention: () => void;
getAutoLaunch: () => Promise<boolean>;
getMediaAccessStatus: (
mediaType: 'screen' | 'microphone' | 'camera'
) => Promise<string | undefined>;
2023-01-13 00:24:59 +00:00
getMediaCameraPermissions: () => Promise<boolean>;
getMediaPermissions: () => Promise<boolean>;
logAppLoadedEvent?: (options: { processedCount?: number }) => void;
readyForUpdates: () => void;
removeSetupMenuItems: () => unknown;
setAutoHideMenuBar: (value: boolean) => void;
setAutoLaunch: (value: boolean) => Promise<void>;
setBadge: (badge: number | 'marked-unread') => void;
2023-01-13 00:24:59 +00:00
setMenuBarVisibility: (value: boolean) => void;
showDebugLog: () => void;
showPermissionsPopup: (
forCalling: boolean,
forCamera: boolean
) => Promise<void>;
showSettings: () => void;
showWindow: () => void;
2023-08-01 16:06:29 +00:00
showWindowsNotification: (data: WindowsNotificationData) => Promise<void>;
2023-01-13 00:24:59 +00:00
shutdown: () => void;
2024-10-28 17:11:19 +00:00
startTrackingQueryStats: () => void;
stopTrackingQueryStats: (options?: QueryStatsOptions) => void;
2023-01-13 00:24:59 +00:00
titleBarDoubleClick: () => void;
updateTrayIcon: (count: number) => void;
};
export type FeatureFlagType = {
GV2_ENABLE_SINGLE_CHANGE_PROCESSING: boolean;
GV2_ENABLE_CHANGE_PROCESSING: boolean;
GV2_ENABLE_STATE_PROCESSING: boolean;
GV2_ENABLE_PRE_JOIN_FETCH: boolean;
GV2_MIGRATION_DISABLE_ADD: boolean;
GV2_MIGRATION_DISABLE_INVITE: boolean;
};
type AboutWindowPropsType = {
2024-11-06 02:05:24 +00:00
appEnv: string;
arch: string;
platform: string;
};
type DebugLogWindowPropsType = {
downloadLog: (text: string) => unknown;
fetchLogs: () => Promise<string>;
uploadLogs: (text: string) => Promise<string>;
};
type PermissionsWindowPropsType = {
forCamera: boolean;
forCalling: boolean;
onAccept: () => void;
onClose: () => void;
};
type ScreenShareWindowPropsType = {
onStopSharing: () => void;
2024-09-20 01:03:44 +00:00
presentedSourceName: string | undefined;
getStatus: () => ScreenShareStatus;
setRenderCallback: (cb: () => void) => void;
};
type SettingsOnRenderCallbackType = (props: PreferencesPropsType) => void;
type SettingsWindowPropsType = {
onRender: (callback: SettingsOnRenderCallbackType) => void;
2023-03-14 15:55:31 +00:00
};
export type SignalCoreType = {
AboutWindowProps?: AboutWindowPropsType;
Crypto: typeof Crypto;
Curve: typeof Curve;
DebugLogWindowProps?: DebugLogWindowPropsType;
Groups: typeof Groups;
PermissionsWindowProps?: PermissionsWindowPropsType;
RemoteConfig: typeof RemoteConfig;
ScreenShareWindowProps?: ScreenShareWindowPropsType;
Services: {
calling: CallingClass;
2024-03-15 14:20:33 +00:00
backups: BackupsService;
initializeGroupCredentialFetcher: () => Promise<void>;
initializeNetworkObserver: (network: ReduxActions['network']) => void;
initializeUpdateListener: (updates: ReduxActions['updates']) => void;
2023-04-10 21:30:33 +00:00
retryPlaceholders?: RetryPlaceholders;
lightSessionResetQueue?: PQueue;
storage: typeof StorageService;
};
SettingsWindowProps?: SettingsWindowPropsType;
Migrations: ReturnType<typeof initializeMigrations>;
Types: {
Message: typeof Message2;
Address: typeof Address;
QualifiedAddress: typeof QualifiedAddress;
};
Components: {
ConfirmationDialog: typeof ConfirmationDialog;
};
OS: OSType;
State: {
Roots: {
createApp: typeof createApp;
};
};
conversationControllerStart: () => void;
challengeHandler?: ChallengeHandler;
2024-08-08 23:10:25 +00:00
// Only for debugging in Dev Tools
DataReader?: unknown;
DataWriter?: unknown;
};
declare global {
2022-09-06 20:51:34 +00:00
// We want to extend various globals, so we need to use interfaces.
/* eslint-disable no-restricted-syntax */
interface Window {
// Used in Sticker Creator to create proper paths to emoji images
ROOT_PATH?: string;
// Used for sticker creator localization
localeMessages: { [key: string]: { message: string } };
2023-02-27 22:34:43 +00:00
openArtCreator: (opts: { username: string; password: string }) => void;
enterKeyboardMode: () => void;
enterMouseMode: () => void;
getAccountManager: () => AccountManager;
getAppInstance: () => string | undefined;
getConversations: () => ConversationModelCollectionType;
getBuildCreation: () => number;
2023-01-18 23:31:10 +00:00
getBuildExpiration: () => number;
getHostName: () => string;
2020-10-30 17:52:21 +00:00
getInteractionMode: () => 'mouse' | 'keyboard';
2020-09-09 02:25:05 +00:00
getServerPublicParams: () => string;
2024-02-22 21:19:50 +00:00
getGenericServerPublicParams: () => string;
2024-04-22 21:25:56 +00:00
getBackupServerPublicParams: () => string;
getSfuUrl: () => string;
getIceServerOverride: () => string;
2021-06-09 22:28:54 +00:00
getSocketStatus: () => SocketStatus;
getSyncRequest: (timeoutMillis?: number) => SyncRequest;
getTitle: () => string;
2020-09-09 02:25:05 +00:00
waitForEmptyEventQueue: () => Promise<void>;
getVersion: () => string;
2021-05-03 16:38:20 +00:00
isAfterVersion: (version: string, anotherVersion: string) => boolean;
isBeforeVersion: (version: string, anotherVersion: string) => boolean;
2022-05-11 22:58:14 +00:00
initialTheme?: ThemeType;
libphonenumberInstance: {
parse: (number: string) => PhoneNumber;
getRegionCodeForNumber: (number: PhoneNumber) => string | undefined;
format: (number: PhoneNumber, format: PhoneNumberFormat) => string;
};
libphonenumberFormat: typeof PhoneNumberFormat;
nodeSetImmediate: typeof setImmediate;
2020-06-04 18:16:19 +00:00
platform: string;
2022-07-13 00:37:21 +00:00
preloadedImages: Array<HTMLImageElement>;
setImmediate: typeof setImmediate;
sendChallengeRequest: (request: IPCChallengeRequest) => void;
showKeyboardShortcuts: () => void;
storage: Storage;
2024-11-06 02:05:24 +00:00
systemTheme: SystemThemeType;
2021-12-16 15:02:22 +00:00
Signal: SignalCoreType;
2023-01-13 00:24:59 +00:00
getServerTrustRoot: () => string;
logAuthenticatedConnect?: () => void;
// ========================================================================
// The types below have been somewhat organized. See DESKTOP-4801
// ========================================================================
// Backbone
Backbone: typeof Backbone;
ConversationController: ConversationController;
2021-08-18 20:08:14 +00:00
Events: IPCEventsType;
2023-01-13 00:24:59 +00:00
FontFace: typeof FontFace;
MessageCache: MessageCache;
2021-02-26 23:42:45 +00:00
SignalProtocolStore: typeof SignalProtocolStore;
WebAPI: WebAPIConnectType;
Whisper: WhisperType;
2023-01-13 00:24:59 +00:00
getSignalProtocolStore: () => SignalProtocolStore;
i18n: LocalizerType;
// Note: used in background.html, and not type-checked
startApp: () => void;
textsecure: typeof textsecure;
2020-06-04 18:16:19 +00:00
2023-01-13 00:24:59 +00:00
// IPC
IPC: IPCType;
2020-11-13 19:57:55 +00:00
2023-01-13 00:24:59 +00:00
// State
reduxActions: ReduxActions;
reduxStore: Store<StateType>;
// Feature Flags
Flags: FeatureFlagType;
2021-08-20 16:06:15 +00:00
2023-01-13 00:24:59 +00:00
// Paths
BasePaths: {
attachments: string;
draft: string;
stickers: string;
temp: string;
};
// Test only
SignalCI?: CIType;
2023-01-13 00:24:59 +00:00
// TODO DESKTOP-4801
SignalContext: SignalContextType;
2023-01-13 00:24:59 +00:00
// Used only in preload to calculate load time
preloadStartTime: number;
preloadEndTime: number;
// Test only
2023-01-13 00:24:59 +00:00
RETRY_DELAY: boolean;
assert: typeof assert;
testUtilities: {
2024-06-28 00:22:06 +00:00
setup: MochaOptions;
2024-07-02 19:56:40 +00:00
debug: (info: unknown) => void;
2024-06-28 00:22:06 +00:00
onTestEvent: (event: unknown) => void;
initialize: () => Promise<void>;
prepareTests: () => void;
};
}
2020-05-27 21:37:06 +00:00
interface Element {
// WebKit-specific
scrollIntoViewIfNeeded: (bringToCenter?: boolean) => void;
}
// Uint8Array and ArrayBuffer are type-compatible in TypeScript's covariant
// type checker, but in reality they are not. Let's assert correct use!
interface Uint8Array {
__uint8array: never;
}
interface ArrayBuffer {
2022-09-06 20:51:34 +00:00
__arrayBuffer: never;
}
interface SharedArrayBuffer {
2022-09-06 20:51:34 +00:00
__arrayBuffer: never;
}
2024-09-06 17:52:19 +00:00
interface Set<T> {
// Needed until TS upgrade
difference<U>(other: ReadonlySet<U>): Set<T>;
}
}
export type WhisperType = {
2021-08-30 21:32:56 +00:00
Conversation: typeof ConversationModel;
ConversationCollection: typeof ConversationModelCollectionType;
Message: typeof MessageModel;
deliveryReceiptQueue: PQueue;
deliveryReceiptBatcher: BatcherType<Receipt>;
events: Backbone.Events;
};