refactor: rely on component versions from checksums file (#1111)

This commit is contained in:
Mo
2022-06-16 11:56:32 -05:00
committed by GitHub
parent 6921c6abe1
commit dc10a5cb25
738 changed files with 389 additions and 381 deletions

View File

@@ -8,7 +8,7 @@ import {
DeinitSource,
Environment,
IconsController,
NoteGroupController,
ItemGroupController,
platformFromString,
SNApplication,
SNComponentManager,
@@ -42,7 +42,7 @@ type MobileServices = {
export class MobileApplication extends SNApplication {
private MobileServices!: MobileServices
public editorGroup: NoteGroupController
public editorGroup: ItemGroupController
public iconsController: IconsController
private startedDeinit = false
@@ -71,7 +71,7 @@ export class MobileApplication extends SNApplication {
})
this.Uuid = Math.random().toString()
this.editorGroup = new NoteGroupController(this)
this.editorGroup = new ItemGroupController(this)
this.iconsController = new IconsController()
void this.mobileComponentManager.initialize(this.protocolService)

View File

@@ -265,13 +265,13 @@ export class ApplicationState extends ApplicationService {
: this.selectedTag.uuid
: undefined
this.application.editorGroup.closeActiveNoteController()
this.application.editorGroup.closeActiveItemController()
const noteView = await this.application.editorGroup.createNoteController(undefined, title, selectedTagUuid)
const noteView = await this.application.editorGroup.createItemController({ title, tag: selectedTagUuid })
const defaultEditor = this.application.componentManager.getDefaultEditor()
if (defaultEditor) {
await associateComponentWithNote(this.application, defaultEditor, this.getActiveNoteController().note)
await associateComponentWithNote(this.application, defaultEditor, this.getActiveNoteController().item)
}
return noteView
@@ -281,10 +281,10 @@ export class ApplicationState extends ApplicationService {
const note = this.application.items.findItem(noteUuid) as SNNote
const activeEditor = this.getActiveNoteController()
if (activeEditor) {
this.application.editorGroup.closeActiveNoteController()
this.application.editorGroup.closeActiveItemController()
}
const noteView = await this.application.editorGroup.createNoteController(noteUuid)
const noteView = (await this.application.editorGroup.createItemController(note)) as NoteViewController
if (note && note.conflictOf) {
void InteractionManager.runAfterInteractions(() => {
@@ -297,32 +297,32 @@ export class ApplicationState extends ApplicationService {
return noteView
}
getActiveNoteController() {
return this.application.editorGroup.noteControllers[0]
getActiveNoteController(): NoteViewController {
return this.application.editorGroup.itemControllers[0] as NoteViewController
}
getEditors() {
return this.application.editorGroup.noteControllers
getEditors(): NoteViewController[] {
return this.application.editorGroup.itemControllers as NoteViewController[]
}
closeEditor(editor: NoteViewController) {
this.notifyOfStateChange(AppStateType.EditorClosed)
this.application.editorGroup.closeNoteController(editor)
this.application.editorGroup.closeItemController(editor)
}
closeActiveEditor() {
this.notifyOfStateChange(AppStateType.EditorClosed)
this.application.editorGroup.closeActiveNoteController()
this.application.editorGroup.closeActiveItemController()
}
closeAllEditors() {
this.notifyOfStateChange(AppStateType.EditorClosed)
this.application.editorGroup.closeAllNoteControllers()
this.application.editorGroup.closeAllItemControllers()
}
editorForNote(uuid: Uuid): NoteViewController | void {
for (const editor of this.getEditors()) {
if (editor.note?.uuid === uuid) {
if (editor.item?.uuid === uuid) {
return editor
}
}

View File

@@ -1,5 +1,6 @@
import { MobileTheme } from '@Root/Style/MobileTheme'
import FeatureChecksums from '@standardnotes/components-meta/dist/zips/checksums.json'
import { ComponentChecksumsType } from '@standardnotes/components-meta'
import RawComponentChecksumsFile from '@standardnotes/components-meta/dist/zips/checksums.json'
import { FeatureDescription, FeatureIdentifier, GetFeatures } from '@standardnotes/features'
import {
ComponentMutator,
@@ -21,13 +22,8 @@ import { componentsCdn } from '../../package.json'
import { MobileThemeContent } from '../Style/MobileTheme'
import { IsDev } from './Utils'
type TFeatureChecksums = {
[key in FeatureIdentifier]: {
version: string
base64: string
binary: string
}
}
const FeatureChecksums = RawComponentChecksumsFile as ComponentChecksumsType
export enum ComponentLoadingError {
FailedDownload = 'FailedDownload',
ChecksumMismatch = 'ChecksumMismatch',
@@ -49,7 +45,7 @@ export class ComponentManager extends SNComponentManager {
private thirdPartyIndexPaths: Record<string, string> = {}
public async initialize(protocolService: EncryptionService) {
this.loggingEnabled = false
this.loggingEnabled = true
this.protocolService = protocolService
await this.createServer()
}
@@ -111,14 +107,20 @@ export class ComponentManager extends SNComponentManager {
throw Error('Attempting to download component with no download url')
}
const version = nativeFeature?.version || component.package_info?.version
const currentPackageJson = await this.getDownloadedComponentPackageJsonFile(identifier)
const currentVersion = currentPackageJson?.version
const newVersion = nativeFeature ? FeatureChecksums[identifier].version : component.package_info?.version
const existingPackageJson = await this.getDownloadedComponentPackageJsonFile(identifier)
const existingVersion = existingPackageJson?.version
this.log('Existing package version', existingVersion)
this.log('Latest package version', version)
if (!newVersion) {
this.log('Cannot retrieve new version string for component', identifier)
return false
}
const shouldDownload = !existingPackageJson || isRightVersionGreaterThanLeft(existingVersion, version!)
this.log('Existing package version', currentVersion)
this.log('Latest package version', newVersion)
const shouldDownload = !currentPackageJson || isRightVersionGreaterThanLeft(currentVersion, newVersion)
this.log('Needs upgrade', shouldDownload)
return shouldDownload
}
@@ -170,15 +172,17 @@ export class ComponentManager extends SNComponentManager {
const zipContents = await RNFS.readFile(filePath, 'base64')
const checksum = await this.protocolService.crypto.sha256(zipContents)
const desiredChecksum = (FeatureChecksums as TFeatureChecksums)[featureIdentifier]?.base64
const desiredChecksum = FeatureChecksums[featureIdentifier]?.base64
if (!desiredChecksum) {
this.log(`Checksum is missing for ${featureIdentifier}; aborting installation`)
return false
}
if (checksum !== desiredChecksum) {
this.log(`Checksums don't match for ${featureIdentifier}; ${checksum} != ${desiredChecksum}; aborting install`)
return false
}
this.log(`Checksum ${checksum} matches ${desiredChecksum} for ${featureIdentifier}`)
return true
@@ -312,7 +316,8 @@ export class ComponentManager extends SNComponentManager {
const splitPackagePath = componentPath.split(COMPONENTS_PATH)
const relativePackagePath = splitPackagePath[splitPackagePath.length - 1]
const relativeMainFilePath = `${relativePackagePath}/${indexFilePath}`
return `${this.staticServerUrl}${relativeMainFilePath}`
const url = `${this.staticServerUrl}${relativeMainFilePath}`
return url
}
public setMobileActiveTheme(theme: MobileTheme) {

View File

@@ -88,7 +88,7 @@ export class Compose extends React.Component<PropsWhenNavigating | PropsWhenRend
this.context = context
const noteUuid = 'noteUuid' in props ? props.noteUuid : props.route.params.noteUuid
const editor = this.context.editorGroup.noteControllers.find(c => c.note.uuid === noteUuid)
const editor = this.context.editorGroup.itemControllers.find(c => c.item.uuid === noteUuid) as NoteViewController
if (!editor) {
throw 'Unable to to find note controller'
}
@@ -96,8 +96,8 @@ export class Compose extends React.Component<PropsWhenNavigating | PropsWhenRend
this.editor = editor
this.state = {
title: this.editor.note.title,
text: this.editor.note.text,
title: this.editor.item.title,
text: this.editor.item.text,
componentViewer: undefined,
saveError: false,
webViewError: undefined,
@@ -260,7 +260,7 @@ export class Compose extends React.Component<PropsWhenNavigating | PropsWhenRend
}
get note() {
return this.editor.note
return this.editor.item
}
dismissKeyboard = () => {

View File

@@ -165,7 +165,7 @@ export const Notes = React.memo(
let mounted = true
const removeEditorObserver = application.editorGroup.addActiveControllerChangeObserver(activeEditor => {
if (mounted) {
setSelectedNoteId(activeEditor?.note?.uuid)
setSelectedNoteId(activeEditor?.item?.uuid)
}
})
@@ -361,7 +361,7 @@ export const Notes = React.memo(
application.getAppState().closeActiveEditor()
}
} else {
const activeNote = application.getAppState().getActiveNoteController()?.note
const activeNote = application.getAppState().getActiveNoteController()?.item
if (activeNote) {
const isTrashView =
@@ -389,7 +389,7 @@ export const Notes = React.memo(
const onNoteCreate = useCallback(async () => {
const title = application.getAppState().isTabletDevice ? `Note ${notes.length + 1}` : undefined
const noteView = await application.getAppState().createEditor(title)
openCompose(true, noteView.note.uuid)
openCompose(true, noteView.item.uuid)
reloadNotes(true)
}, [application, notes.length, openCompose, reloadNotes])

View File

@@ -51,7 +51,9 @@ export const Root = () => {
}
})
const removeNoteObserver = application?.editorGroup.addActiveControllerChangeObserver(activeController => {
setActiveNoteView(activeController)
if (activeController instanceof NoteViewController) {
setActiveNoteView(activeController)
}
})
return () => {
@@ -112,7 +114,7 @@ export const Root = () => {
</NotesContainer>
{activeNoteView && !activeNoteView.dealloced && isInTabletMode && (
<ComposeContainer>
<Compose noteUuid={activeNoteView.note.uuid} />
<Compose noteUuid={activeNoteView.item.uuid} />
<ExpandTouchable style={{ bottom: collapseIconBottomPosition }} onPress={toggleNoteList}>
<Icon name={collapseIconName} size={24} color={hexToRGBA(theme.stylekitInfoColor, 0.85)} />
</ExpandTouchable>

View File

@@ -156,8 +156,8 @@ export const NoteSideMenu = React.memo((props: Props) => {
useEffect(() => {
let mounted = true
if ((!editor || props.drawerOpen) && mounted) {
const initialEditor = application.editorGroup.activeNoteViewController
const tempNote = initialEditor?.note
const initialEditor = application.editorGroup.activeItemViewController as NoteViewController
const tempNote = initialEditor?.item
setEditor(initialEditor)
setNote(tempNote)
}
@@ -170,8 +170,8 @@ export const NoteSideMenu = React.memo((props: Props) => {
let mounted = true
const removeEditorObserver = application.editorGroup.addActiveControllerChangeObserver(() => {
if (mounted) {
const activeController = application.editorGroup.activeNoteViewController
setNote(activeController?.note)
const activeController = application.editorGroup.activeItemViewController as NoteViewController
setNote(activeController?.item)
setEditor(activeController)
}
})