feat: option to sign out all workspaces (#1005)

* feat: option to sign out all workspaces

* style: prettier width 120

* chore: bump snjs
This commit is contained in:
Mo 2022-04-26 15:28:30 -05:00 committed by GitHub
parent c6ed9534fb
commit bce8c5fcba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 132 additions and 111 deletions

View File

@ -1,6 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100,
"printWidth": 120,
"semi": false
}

View File

@ -64,7 +64,8 @@ export const WorkspaceMenuItem: FunctionComponent<Props> = ({
<div>
<button
className="w-5 h-5 p-0 mr-3 border-0 bg-transparent hover:bg-contrast cursor-pointer"
onClick={() => {
onClick={(e) => {
e.stopPropagation()
setIsRenaming((isRenaming) => !isRenaming)
}}
>
@ -72,7 +73,10 @@ export const WorkspaceMenuItem: FunctionComponent<Props> = ({
</button>
<button
className="w-5 h-5 p-0 border-0 bg-transparent hover:bg-contrast cursor-pointer"
onClick={onDelete}
onClick={(e) => {
e.stopPropagation()
onDelete()
}}
>
<Icon type="trash" className="sn-icon--mid color-danger" />
</button>

View File

@ -1,9 +1,9 @@
import { ApplicationGroup } from '@/UIModels/ApplicationGroup'
import { AppState } from '@/UIModels/AppState'
import { ApplicationDescriptor } from '@standardnotes/snjs'
import { ApplicationDescriptor, ButtonType } from '@standardnotes/snjs'
import { observer } from 'mobx-react-lite'
import { FunctionComponent } from 'preact'
import { useEffect, useState } from 'preact/hooks'
import { useCallback, useEffect, useState } from 'preact/hooks'
import { Icon } from '@/Components/Icon'
import { Menu } from '@/Components/Menu/Menu'
import { MenuItem, MenuItemSeparator, MenuItemType } from '@/Components/Menu/MenuItem'
@ -18,9 +18,7 @@ type Props = {
export const WorkspaceSwitcherMenu: FunctionComponent<Props> = observer(
({ mainApplicationGroup, appState, isOpen, hideWorkspaceOptions = false }) => {
const [applicationDescriptors, setApplicationDescriptors] = useState<ApplicationDescriptor[]>(
[],
)
const [applicationDescriptors, setApplicationDescriptors] = useState<ApplicationDescriptor[]>([])
useEffect(() => {
const removeAppGroupObserver = mainApplicationGroup.addApplicationChangeObserver(() => {
@ -33,6 +31,19 @@ export const WorkspaceSwitcherMenu: FunctionComponent<Props> = observer(
}
}, [mainApplicationGroup])
const signoutAll = useCallback(async () => {
const confirmed = await appState.application.alertService.confirm(
'Are you sure you want to sign out of all workspaces on this device?',
undefined,
'Sign out all',
ButtonType.Danger,
)
if (!confirmed) {
return
}
mainApplicationGroup.signOutAllWorkspaces().catch(console.error)
}, [mainApplicationGroup, appState.application.alertService])
return (
<Menu a11yLabel="Workspace switcher menu" className="px-0 focus:shadow-none" isOpen={isOpen}>
{applicationDescriptors.map((descriptor) => (
@ -43,23 +54,29 @@ export const WorkspaceSwitcherMenu: FunctionComponent<Props> = observer(
appState.accountMenu.setSigningOut(true)
}}
onClick={() => {
mainApplicationGroup.loadApplicationForDescriptor(descriptor).catch(console.error)
mainApplicationGroup.loadApplicationForDescriptor(descriptor)
}}
renameDescriptor={(label: string) =>
mainApplicationGroup.renameDescriptor(descriptor, label)
}
renameDescriptor={(label: string) => mainApplicationGroup.renameDescriptor(descriptor, label)}
/>
))}
<MenuItemSeparator />
<MenuItem
type={MenuItemType.IconButton}
onClick={() => {
mainApplicationGroup.addNewApplication().catch(console.error)
mainApplicationGroup.addNewApplication()
}}
>
<Icon type="user-add" className="color-neutral mr-2" />
Add another workspace
</MenuItem>
{!hideWorkspaceOptions && (
<MenuItem type={MenuItemType.IconButton} onClick={signoutAll}>
<Icon type="signOut" className="color-neutral mr-2" />
Sign out all workspaces
</MenuItem>
)}
</Menu>
)
},

View File

@ -55,7 +55,8 @@ export class ApplicationView extends PureComponent<Props, State> {
override componentDidMount(): void {
super.componentDidMount()
this.loadApplication().catch(console.error)
void this.loadApplication()
}
async loadApplication() {
@ -180,16 +181,10 @@ export class ApplicationView extends PureComponent<Props, State> {
)}
{renderAppContents && (
<>
<Footer
application={this.application}
applicationGroup={this.props.mainApplicationGroup}
/>
<Footer application={this.application} applicationGroup={this.props.mainApplicationGroup} />
<SessionsModal application={this.application} appState={this.appState} />
<PreferencesViewWrapper appState={this.appState} application={this.application} />
<RevisionHistoryModalWrapper
application={this.application}
appState={this.appState}
/>
<RevisionHistoryModalWrapper application={this.application} appState={this.appState} />
</>
)}
{this.state.challenges.map((challenge) => {
@ -211,7 +206,11 @@ export class ApplicationView extends PureComponent<Props, State> {
<NotesContextMenu application={this.application} appState={this.appState} />
<TagsContextMenu appState={this.appState} />
<PurchaseFlowWrapper application={this.application} appState={this.appState} />
<ConfirmSignoutContainer appState={this.appState} application={this.application} />
<ConfirmSignoutContainer
applicationGroup={this.props.mainApplicationGroup}
appState={this.appState}
application={this.application}
/>
<ToastContainer />
</>
)}

View File

@ -4,10 +4,13 @@ import { STRING_SIGN_OUT_CONFIRMATION } from '@/Strings'
import { WebApplication } from '@/UIModels/Application'
import { AppState } from '@/UIModels/AppState'
import { observer } from 'mobx-react-lite'
import { ApplicationGroup } from '@/UIModels/ApplicationGroup'
import { isDesktopApplication } from '@/Utils'
type Props = {
application: WebApplication
appState: AppState
applicationGroup: ApplicationGroup
}
export const ConfirmSignoutContainer = observer((props: Props) => {
@ -17,7 +20,7 @@ export const ConfirmSignoutContainer = observer((props: Props) => {
return <ConfirmSignoutModal {...props} />
})
export const ConfirmSignoutModal = observer(({ application, appState }: Props) => {
export const ConfirmSignoutModal = observer(({ application, appState, applicationGroup }: Props) => {
const [deleteLocalBackups, setDeleteLocalBackups] = useState(false)
const cancelRef = useRef<HTMLButtonElement>(null)
@ -31,6 +34,9 @@ export const ConfirmSignoutModal = observer(({ application, appState }: Props) =
application.desktopDevice?.localBackupsCount().then(setLocalBackupsCount).catch(console.error)
}, [appState.accountMenu.signingOut, application.desktopDevice])
const workspaces = applicationGroup.getDescriptors()
const showWorkspaceWarning = workspaces.length > 1 && isDesktopApplication()
return (
<AlertDialog onDismiss={closeDialog} leastDestructiveRef={cancelRef}>
<div className="sk-modal-content">
@ -38,11 +44,22 @@ export const ConfirmSignoutModal = observer(({ application, appState }: Props) =
<div className="sk-panel">
<div className="sk-panel-content">
<div className="sk-panel-section">
<AlertDialogLabel className="sk-h3 sk-panel-section-title">
Sign out workspace?
</AlertDialogLabel>
<AlertDialogLabel className="sk-h3 sk-panel-section-title">Sign out workspace?</AlertDialogLabel>
<AlertDialogDescription className="sk-panel-row">
<p className="color-foreground">{STRING_SIGN_OUT_CONFIRMATION}</p>
<div>
<p className="color-foreground">{STRING_SIGN_OUT_CONFIRMATION}</p>
{showWorkspaceWarning && (
<>
<br />
<p className="color-foreground">
<strong>Note: </strong>
Because you have other workspaces signed in, this sign out may leave logs and other metadata
of your session on this device. For a more robust sign out that performs a hard clear of all
app-related data, use the <i>Sign out all workspaces</i> option under <i>Switch workspace</i>.
</p>
</>
)}
</div>
</AlertDialogDescription>
{localBackupsCount > 0 && (

View File

@ -11,7 +11,7 @@ export interface PreferencesViewWrapperProps {
export const PreferencesViewWrapper: FunctionComponent<PreferencesViewWrapperProps> = observer(
({ appState, application }) => {
if (!appState.preferences.isOpen) {
if (!appState.preferences?.isOpen) {
return null
}

View File

@ -1,5 +1,5 @@
import { DeviceInterface, Environment } from '@standardnotes/snjs'
import { WebCommunicationReceiver } from './DesktopWebCommunication'
import { WebClientRequiresDesktopMethods } from './DesktopWebCommunication'
import { WebOrDesktopDeviceInterface } from './WebOrDesktopDeviceInterface'
export function isDesktopDevice(x: DeviceInterface): x is DesktopDeviceInterface {
@ -8,6 +8,6 @@ export function isDesktopDevice(x: DeviceInterface): x is DesktopDeviceInterface
export interface DesktopDeviceInterface
extends WebOrDesktopDeviceInterface,
WebCommunicationReceiver {
WebClientRequiresDesktopMethods {
environment: Environment.Desktop
}

View File

@ -1,7 +1,6 @@
import { DecryptedTransferPayload } from '@standardnotes/snjs'
/** Receives communications emitted by Web Core. This would be the Desktop client. */
export interface WebCommunicationReceiver {
export interface WebClientRequiresDesktopMethods {
localBackupsCount(): Promise<number>
viewlocalBackups(): void
@ -14,7 +13,10 @@ export interface WebCommunicationReceiver {
onInitialDataLoad(): void
onSignOut(): void
/**
* Destroys all sensitive storage data, such as localStorage, IndexedDB, and other log files.
*/
destroyAllData(): void
onSearch(text?: string): void
@ -23,8 +25,7 @@ export interface WebCommunicationReceiver {
get extensionsServerHost(): string
}
/** Receives communications emitted by the desktop client. This would be Web Core. */
export interface DesktopCommunicationReceiver {
export interface DesktopClientRequiresWebMethods {
updateAvailable(): void
windowGainedFocus(): void

View File

@ -13,11 +13,11 @@ import {
} from '@standardnotes/snjs'
import { WebAppEvent, WebApplication } from '@/UIModels/Application'
import { DesktopDeviceInterface } from '../Device/DesktopDeviceInterface'
import { DesktopCommunicationReceiver } from '@/Device/DesktopWebCommunication'
import { DesktopClientRequiresWebMethods } from '@/Device/DesktopWebCommunication'
export class DesktopManager
extends ApplicationService
implements DesktopManagerInterface, DesktopCommunicationReceiver
implements DesktopManagerInterface, DesktopClientRequiresWebMethods
{
updateObservers: {
callback: (component: SNComponent) => void

View File

@ -91,10 +91,6 @@ export class WebApplication extends SNApplication {
this.webServices = {} as WebServices
this.noteControllerGroup.deinit()
this.webEventObservers.length = 0
if (source === DeinitSource.SignOut) {
isDesktopDevice(this.deviceInterface) && this.deviceInterface.onSignOut()
}
} catch (error) {
console.error('Error while deiniting application', error)
}

View File

@ -1,11 +1,5 @@
import { WebApplication } from './Application'
import {
ApplicationDescriptor,
SNApplicationGroup,
Platform,
Runtime,
InternalEventBus,
} from '@standardnotes/snjs'
import { ApplicationDescriptor, SNApplicationGroup, Platform, Runtime, InternalEventBus } from '@standardnotes/snjs'
import { AppState } from '@/UIModels/AppState'
import { getPlatform, isDesktopApplication } from '@/Utils'
import { ArchiveManager } from '@/Services/ArchiveManager'
@ -33,17 +27,19 @@ export class ApplicationGroup extends SNApplicationGroup<WebOrDesktopDevice> {
})
if (isDesktopApplication()) {
Object.defineProperty(window, 'desktopCommunicationReceiver', {
Object.defineProperty(window, 'webClient', {
get: () => (this.primaryApplication as WebApplication).getDesktopService(),
})
}
}
private createApplication = (
descriptor: ApplicationDescriptor,
deviceInterface: WebOrDesktopDevice,
) => {
override handleAllWorkspacesSignedOut(): void {
isDesktopDevice(this.deviceInterface) && this.deviceInterface.destroyAllData()
}
private createApplication = (descriptor: ApplicationDescriptor, deviceInterface: WebOrDesktopDevice) => {
const platform = getPlatform()
const application = new WebApplication(
deviceInterface,
platform,
@ -52,6 +48,7 @@ export class ApplicationGroup extends SNApplicationGroup<WebOrDesktopDevice> {
this.webSocketUrl,
this.runtime,
)
const appState = new AppState(application, this.device)
const archiveService = new ArchiveManager(application)
const io = new IOService(platform === Platform.MacWeb || platform === Platform.MacDesktop)
@ -62,9 +59,7 @@ export class ApplicationGroup extends SNApplicationGroup<WebOrDesktopDevice> {
application.setWebServices({
appState,
archiveService,
desktopService: isDesktopDevice(this.device)
? new DesktopManager(application, this.device)
: undefined,
desktopService: isDesktopDevice(this.device) ? new DesktopManager(application, this.device) : undefined,
io,
autolockService,
statusManager,

View File

@ -72,7 +72,7 @@
"@standardnotes/components": "1.7.15",
"@standardnotes/filepicker": "1.13.3",
"@standardnotes/sncrypto-web": "1.8.4",
"@standardnotes/snjs": "2.99.1",
"@standardnotes/snjs": "2.100.0",
"@standardnotes/stylekit": "5.23.0",
"@zip.js/zip.js": "^2.4.10",
"mobx": "^6.5.0",

View File

@ -2450,32 +2450,32 @@
"@typescript-eslint/eslint-plugin" "^5.12.1"
"@typescript-eslint/parser" "^5.12.1"
"@standardnotes/domain-events@^2.27.10":
version "2.27.10"
resolved "https://registry.yarnpkg.com/@standardnotes/domain-events/-/domain-events-2.27.10.tgz#ce52a7c51849a8f8995678be907c68937b8cfe02"
integrity sha512-TD71BRl9KRaxZBtYPFU2dmvz8L0H1AZvLF12KJrpcXVAPbSwNaprMx0LdATerIlpIa47cR/SbBBW9GRFpk5RTA==
"@standardnotes/domain-events@^2.27.11":
version "2.27.11"
resolved "https://registry.yarnpkg.com/@standardnotes/domain-events/-/domain-events-2.27.11.tgz#0675304c19660b4907c3371e80bf2f7969761546"
integrity sha512-fV4nEfayUHjEpTC+9rD5q7h5R318onA9HuqT8eR7HQId1ATGGDcIS0bUITPrlPyZ0pVKmMg8ox7Glya8WTyfwA==
dependencies:
"@standardnotes/auth" "^3.18.11"
"@standardnotes/features" "^1.37.9"
"@standardnotes/features" "^1.38.0"
"@standardnotes/encryption@^1.4.9":
version "1.4.9"
resolved "https://registry.yarnpkg.com/@standardnotes/encryption/-/encryption-1.4.9.tgz#1e5f47dd0624e694eed0a851f703d8a620a02c82"
integrity sha512-Cdwusso9sPVxNo85HCicbZ46g5wmjMph+3WGEGbQ6/3Jb/FaGrH4WbwnNsHvPO9LvjI41wxBqb2iCbUxmsB+ZQ==
"@standardnotes/encryption@^1.4.10":
version "1.4.10"
resolved "https://registry.yarnpkg.com/@standardnotes/encryption/-/encryption-1.4.10.tgz#ff5d5a884aae9a14fff7e3afe3772f41af1bb642"
integrity sha512-BH5brDoevoGEyNXEIV/D6G28Bn1zHxKed01aofqgronOgbZdVGXtxKr7j/EOfzareg7vhhUO2oA73aTU73dAOA==
dependencies:
"@standardnotes/models" "^1.4.8"
"@standardnotes/responses" "^1.6.10"
"@standardnotes/services" "^1.9.10"
"@standardnotes/models" "^1.4.9"
"@standardnotes/responses" "^1.6.11"
"@standardnotes/services" "^1.9.11"
"@standardnotes/features@^1.37.9":
version "1.37.9"
resolved "https://registry.yarnpkg.com/@standardnotes/features/-/features-1.37.9.tgz#8de7cc747e29684976d5bb5534b2a36edfa0d07c"
integrity sha512-+j4/skCnd9SIY9KmULv7fX1KPBpgs8uOC78/TBf8rT20KEI1rNIw9c9RFTMEaQW/2tn2HPFweHAetWzIUiTWJg==
"@standardnotes/features@^1.38.0":
version "1.38.0"
resolved "https://registry.yarnpkg.com/@standardnotes/features/-/features-1.38.0.tgz#ddd6817af1544374013fec0bb19f5dff4a11ae60"
integrity sha512-6a56WZTgbB1/IefF8ADWuOI9FPthP30BpJT+Dmu4TEG8SdEC4QFCogAfRPwJ2z8Kh8xYeWuRZDr+CYsm20vqWg==
dependencies:
"@standardnotes/auth" "^3.18.11"
"@standardnotes/common" "^1.19.6"
"@standardnotes/filepicker@1.13.3":
"@standardnotes/filepicker@1.13.3", "@standardnotes/filepicker@^1.13.3":
version "1.13.3"
resolved "https://registry.yarnpkg.com/@standardnotes/filepicker/-/filepicker-1.13.3.tgz#fa4aee37432ec189a9be0dbbdb655ebdf9e33cbf"
integrity sha512-og2eU0PasZviLKfm55j6ZC6LfTJnVqTF+brEosgeJdcc5mOLmbRZ9aLhYT5N3qkjJdlRSXiwWQ7mYiYQ/rF4Kw==
@ -2483,40 +2483,32 @@
"@standardnotes/common" "^1.19.6"
"@standardnotes/utils" "^1.6.2"
"@standardnotes/filepicker@^1.13.2":
version "1.13.2"
resolved "https://registry.yarnpkg.com/@standardnotes/filepicker/-/filepicker-1.13.2.tgz#63fc12ae5c08c2704f76b6757a080d8fe385ba8c"
integrity sha512-BlGabKd1uBvnnWTWXXexGhydZTX7mTWO/0O9slP8B+h9yUz0G9DYXDlWEGyMSf3/1YArqJOnAHLU+ID/R1lvSA==
"@standardnotes/models@^1.4.9":
version "1.4.9"
resolved "https://registry.yarnpkg.com/@standardnotes/models/-/models-1.4.9.tgz#50b0055a4e149b948068405c69beeda1859a378d"
integrity sha512-34iv7Z+WiJIoOYcld8RPm4suexK0cuW2drtYdtl/10y/hJC+rXSlVIUVMj7ckPb9g4cuxyI+WVfZ1ebx8+1n0g==
dependencies:
"@standardnotes/common" "^1.19.6"
"@standardnotes/features" "^1.38.0"
"@standardnotes/responses" "^1.6.11"
"@standardnotes/utils" "^1.6.2"
"@standardnotes/models@^1.4.8":
version "1.4.8"
resolved "https://registry.yarnpkg.com/@standardnotes/models/-/models-1.4.8.tgz#7da29c5e3d7de4265c1f1a6f112e9b89c85c26c9"
integrity sha512-30cMS320htMTBvpYcPFsFhkmr6JyvQIkc/7IvCKPxK40yGWdTGRqwfNNSDMP5SMKXjf4t7sh1NJGjJe44DrdbQ==
dependencies:
"@standardnotes/features" "^1.37.9"
"@standardnotes/responses" "^1.6.10"
"@standardnotes/utils" "^1.6.2"
"@standardnotes/responses@^1.6.10":
version "1.6.10"
resolved "https://registry.yarnpkg.com/@standardnotes/responses/-/responses-1.6.10.tgz#7f3436ec183005c3802b60214fe9a5b8f817e14e"
integrity sha512-orR8DIUk8IzoOdSzcpOC620LZxPog1ts+qD7Lv+45/FqHOhbzCce2eoOgheMjkaQi+TTbyR68QfmdJN853rzHQ==
"@standardnotes/responses@^1.6.11":
version "1.6.11"
resolved "https://registry.yarnpkg.com/@standardnotes/responses/-/responses-1.6.11.tgz#78adf45af580a0b5ecc6f2a6b5b80c286107c36c"
integrity sha512-laQfkpTZMHKghyE2Vnc2lt9QEnEFpwEi2j0GezJ0QjbjKdxIyzGUMHMFCZREvQd9Z3PiVuwPXW49DGyGJZHAfQ==
dependencies:
"@standardnotes/auth" "^3.18.11"
"@standardnotes/common" "^1.19.6"
"@standardnotes/features" "^1.37.9"
"@standardnotes/features" "^1.38.0"
"@standardnotes/services@^1.9.10":
version "1.9.10"
resolved "https://registry.yarnpkg.com/@standardnotes/services/-/services-1.9.10.tgz#000a5e3d75671a8b127bc7751d66c1a24b6443b2"
integrity sha512-ff/WEyIq2KhJX6pG8+/BpQnI9Ulo1sd+x/6FmWUHn5C6ukK8srb5Ev1SV8z1hXdkRD1ltFaQvQaPrAYNuG32aQ==
"@standardnotes/services@^1.9.11":
version "1.9.11"
resolved "https://registry.yarnpkg.com/@standardnotes/services/-/services-1.9.11.tgz#b35e60098a8196a58d0a0547a61fc742b2895efc"
integrity sha512-UWGbwS7uvxKOpLFb+HfICe2oqY6oNoqfk4A5WzrLiUsfELvh8VtaahoE9KoGn/4QSzrrYBFG9jXk2CtA5IGEgg==
dependencies:
"@standardnotes/common" "^1.19.6"
"@standardnotes/models" "^1.4.8"
"@standardnotes/responses" "^1.6.10"
"@standardnotes/models" "^1.4.9"
"@standardnotes/responses" "^1.6.11"
"@standardnotes/utils" "^1.6.2"
"@standardnotes/settings@^1.14.1":
@ -2538,20 +2530,20 @@
buffer "^6.0.3"
libsodium-wrappers "^0.7.9"
"@standardnotes/snjs@2.99.1":
version "2.99.1"
resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.99.1.tgz#8274b1d44a15538b3a43bf35794301306238d6cb"
integrity sha512-/DFF9YFLmyc7z34iRvAn/rXBSH5G3zuDhUeyTVWVvotbgY7zvTSD2/wtgE4nZ1pmG58UlxGTDtzTlzyuxW99Ow==
"@standardnotes/snjs@2.100.0":
version "2.100.0"
resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.100.0.tgz#d62c7f0cd17a50b4f3d9e349c7c00a3f6de1192c"
integrity sha512-4pnmAJJ3mDDmLWx8ChR3qEKHcsKB4M1+/o1Nxj8rYOdOnVzvBhzqSERKUyUabNvDOcmo0RkAIDeHgIIRjkJtiQ==
dependencies:
"@standardnotes/auth" "^3.18.11"
"@standardnotes/common" "^1.19.6"
"@standardnotes/domain-events" "^2.27.10"
"@standardnotes/encryption" "^1.4.9"
"@standardnotes/features" "^1.37.9"
"@standardnotes/filepicker" "^1.13.2"
"@standardnotes/models" "^1.4.8"
"@standardnotes/responses" "^1.6.10"
"@standardnotes/services" "^1.9.10"
"@standardnotes/domain-events" "^2.27.11"
"@standardnotes/encryption" "^1.4.10"
"@standardnotes/features" "^1.38.0"
"@standardnotes/filepicker" "^1.13.3"
"@standardnotes/models" "^1.4.9"
"@standardnotes/responses" "^1.6.11"
"@standardnotes/services" "^1.9.11"
"@standardnotes/settings" "^1.14.1"
"@standardnotes/sncrypto-common" "^1.7.7"
"@standardnotes/utils" "^1.6.2"