2021-06-14 19:01:00 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { ThunkAction } from 'redux-thunk';
|
2023-01-13 20:07:26 +00:00
|
|
|
import type { ReadonlyDeep } from 'type-fest';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { StateType as RootStateType } from '../reducer';
|
2021-09-17 18:27:53 +00:00
|
|
|
import * as log from '../../logging/log';
|
2021-06-14 19:01:00 +00:00
|
|
|
|
|
|
|
// State
|
|
|
|
|
|
|
|
export enum AppViewType {
|
|
|
|
Blank = 'Blank',
|
|
|
|
Inbox = 'Inbox',
|
|
|
|
Installer = 'Installer',
|
|
|
|
Standalone = 'Standalone',
|
|
|
|
}
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type AppStateType = ReadonlyDeep<{
|
2021-06-14 19:01:00 +00:00
|
|
|
appView: AppViewType;
|
|
|
|
hasInitialLoadCompleted: boolean;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2021-06-14 19:01:00 +00:00
|
|
|
|
|
|
|
// Actions
|
|
|
|
|
|
|
|
const INITIAL_LOAD_COMPLETE = 'app/INITIAL_LOAD_COMPLETE';
|
|
|
|
const OPEN_INBOX = 'app/OPEN_INBOX';
|
|
|
|
const OPEN_INSTALLER = 'app/OPEN_INSTALLER';
|
|
|
|
const OPEN_STANDALONE = 'app/OPEN_STANDALONE';
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type InitialLoadCompleteActionType = ReadonlyDeep<{
|
2021-06-14 19:01:00 +00:00
|
|
|
type: typeof INITIAL_LOAD_COMPLETE;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2021-06-14 19:01:00 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type OpenInboxActionType = ReadonlyDeep<{
|
2021-06-14 19:01:00 +00:00
|
|
|
type: typeof OPEN_INBOX;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2021-06-14 19:01:00 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type OpenInstallerActionType = ReadonlyDeep<{
|
2021-06-14 19:01:00 +00:00
|
|
|
type: typeof OPEN_INSTALLER;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2021-06-14 19:01:00 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type OpenStandaloneActionType = ReadonlyDeep<{
|
2021-06-14 19:01:00 +00:00
|
|
|
type: typeof OPEN_STANDALONE;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2021-06-14 19:01:00 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type AppActionType = ReadonlyDeep<
|
2021-06-14 19:01:00 +00:00
|
|
|
| InitialLoadCompleteActionType
|
|
|
|
| OpenInboxActionType
|
|
|
|
| OpenInstallerActionType
|
2023-01-13 20:07:26 +00:00
|
|
|
| OpenStandaloneActionType
|
|
|
|
>;
|
2021-06-14 19:01:00 +00:00
|
|
|
|
|
|
|
export const actions = {
|
|
|
|
initialLoadComplete,
|
|
|
|
openInbox,
|
|
|
|
openInstaller,
|
|
|
|
openStandalone,
|
|
|
|
};
|
|
|
|
|
|
|
|
function initialLoadComplete(): InitialLoadCompleteActionType {
|
|
|
|
return {
|
|
|
|
type: INITIAL_LOAD_COMPLETE,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function openInbox(): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
OpenInboxActionType
|
|
|
|
> {
|
|
|
|
return async dispatch => {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.info('open inbox');
|
2021-06-14 19:01:00 +00:00
|
|
|
|
2021-11-04 21:11:47 +00:00
|
|
|
await window.ConversationController.load();
|
2021-06-14 19:01:00 +00:00
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: OPEN_INBOX,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function openInstaller(): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
OpenInstallerActionType
|
|
|
|
> {
|
|
|
|
return dispatch => {
|
2023-01-13 00:24:59 +00:00
|
|
|
window.IPC.addSetupMenuItems();
|
2021-06-14 19:01:00 +00:00
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: OPEN_INSTALLER,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function openStandalone(): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
OpenStandaloneActionType
|
|
|
|
> {
|
|
|
|
return dispatch => {
|
|
|
|
if (window.getEnvironment() === 'production') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-13 00:24:59 +00:00
|
|
|
window.IPC.addSetupMenuItems();
|
2021-06-14 19:01:00 +00:00
|
|
|
dispatch({
|
|
|
|
type: OPEN_STANDALONE,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reducer
|
|
|
|
|
|
|
|
export function getEmptyState(): AppStateType {
|
|
|
|
return {
|
|
|
|
appView: AppViewType.Blank,
|
|
|
|
hasInitialLoadCompleted: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function reducer(
|
|
|
|
state: Readonly<AppStateType> = getEmptyState(),
|
|
|
|
action: Readonly<AppActionType>
|
|
|
|
): AppStateType {
|
|
|
|
if (action.type === OPEN_INBOX) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
appView: AppViewType.Inbox,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === INITIAL_LOAD_COMPLETE) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
hasInitialLoadCompleted: true,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === OPEN_INSTALLER) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
appView: AppViewType.Installer,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === OPEN_STANDALONE) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
appView: AppViewType.Standalone,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|