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) {