Skip to content

Commit

Permalink
fix: display correct app version for desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
moughxyz authored and Karol Sójko committed Jan 5, 2022
1 parent e79f326 commit dfde84c
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 104 deletions.
4 changes: 2 additions & 2 deletions app/assets/javascripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import { NotesOptionsPanelDirective } from './components/NotesOptionsPanel';
import { IconDirective } from './components/Icon';
import { NoteTagsContainerDirective } from './components/NoteTagsContainer';
import { PreferencesDirective } from './preferences';
import { AppVersion, IsWebPlatform } from '@/version';
import { WebAppVersion, IsWebPlatform } from '@/version';
import { NotesListOptionsDirective } from './components/NotesListOptionsMenu';
import { PurchaseFlowDirective } from './purchaseFlow';
import { QuickSettingsMenuDirective } from './components/QuickSettingsMenu/QuickSettingsMenu';
Expand Down Expand Up @@ -224,7 +224,7 @@ const startApplication: StartApplication = async function startApplication(
if (IsWebPlatform) {
startApplication(
window._default_sync_server,
new BrowserBridge(AppVersion),
new BrowserBridge(WebAppVersion),
window._enable_unfinished_features,
window._websocket_url
);
Expand Down
71 changes: 0 additions & 71 deletions app/assets/javascripts/components/AccountMenu/Footer.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { STRING_GENERIC_SYNC_ERROR } from '@/strings';
import { useState } from 'preact/hooks';
import { AccountMenuPane } from '.';
import { FunctionComponent } from 'preact';
import { AppVersion } from '@/version';
import { Menu } from '../menu/Menu';
import { MenuItem, MenuItemSeparator, MenuItemType } from '../menu/MenuItem';

Expand Down Expand Up @@ -156,7 +155,7 @@ export const GeneralAccountMenu: FunctionComponent<Props> = observer(
<Icon type="help" className={iconClassName} />
Help &amp; feedback
</div>
<span className="color-neutral">v{AppVersion}</span>
<span className="color-neutral">v{appState.version}</span>
</MenuItem>
{user ? (
<>
Expand Down
6 changes: 3 additions & 3 deletions app/assets/javascripts/services/errorReporting.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { isNullOrUndefined, SNLog } from '@standardnotes/snjs';
import { isDesktopApplication, isDev } from '@/utils';
import { getDesktopVersion, isDesktopApplication, isDev } from '@/utils';
import { storage, StorageKey } from './localStorage';
import Bugsnag from '@bugsnag/js';
import { WebCrypto } from '../crypto';
import { AppVersion } from '@/version';
import { WebAppVersion } from '@/version';

function redactFilePath(line: string): string {
const fileName = line.match(/\w+\.(html|js)/)?.[0];
Expand Down Expand Up @@ -43,7 +43,7 @@ export function startErrorReporting(): void {
Bugsnag.start({
apiKey: window._bugsnag_api_key,
appType: isDesktopApplication() ? 'desktop' : 'web',
appVersion: AppVersion,
appVersion: getDesktopVersion() || WebAppVersion,
collectUserIp: false,
autoTrackSessions: false,
releaseStage: isDev ? 'development' : undefined,
Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/ui_models/app_state/app_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ export class AppState {
storage.set(StorageKey.ShowBetaWarning, true);
}

public get version(): string {
return this.bridge.appVersion;
}

async openNewNote(title?: string) {
if (!this.multiEditorSupport) {
this.closeActiveNoteController();
Expand Down
3 changes: 1 addition & 2 deletions app/assets/javascripts/ui_models/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { ThemeManager } from '@/services/themeManager';
import { PasswordWizardScope, PasswordWizardType } from '@/types';
import { AppState } from '@/ui_models/app_state';
import { NoteGroupController } from '@/views/note_group_view/note_group_controller';
import { AppVersion } from '@/version';
import { WebDeviceInterface } from '@/web_device_interface';
import {
DeinitSource,
Expand Down Expand Up @@ -59,7 +58,7 @@ export class WebApplication extends SNApplication {
identifier,
[],
defaultSyncServerHost,
AppVersion,
bridge.appVersion,
enableUnfinishedFeatures,
webSocketUrl
);
Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ export function isDesktopApplication() {
return IsDesktopPlatform;
}

export function getDesktopVersion() {
return (window as any).electronAppVersion;
}

export const isEmailValid = (email: string): boolean => {
return EMAIL_REGEX.test(email);
};
2 changes: 1 addition & 1 deletion app/assets/javascripts/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ declare const __VERSION__: string;
declare const __DESKTOP__: boolean;
declare const __WEB__: boolean;

export const AppVersion = __VERSION__;
export const WebAppVersion = __VERSION__;
export const IsDesktopPlatform = __DESKTOP__;
export const IsWebPlatform = __WEB__;
67 changes: 44 additions & 23 deletions app/assets/javascripts/web_device_interface.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
import { DeviceInterface, getGlobalScope, SNApplication, ApplicationIdentifier } from '@standardnotes/snjs';
import {
DeviceInterface,
getGlobalScope,
SNApplication,
ApplicationIdentifier,
} from '@standardnotes/snjs';
import { Database } from '@/database';
import { Bridge } from './services/bridge';

export class WebDeviceInterface extends DeviceInterface {
private databases: Database[] = [];

private databases: Database[] = []

constructor(
timeout: any,
private bridge: Bridge
) {
constructor(timeout: any, private bridge: Bridge) {
super(
timeout || setTimeout.bind(getGlobalScope()),
setInterval.bind(getGlobalScope())
);
}

setApplication(application: SNApplication) {
const database = new Database(application.identifier, application.alertService!);
const database = new Database(
application.identifier,
application.alertService
);
this.databases.push(database);
}

private databaseForIdentifier(identifier: ApplicationIdentifier) {
return this.databases.find(database => database.databaseName === identifier)!;
return this.databases.find(
(database) => database.databaseName === identifier
)!;
}

deinit() {
super.deinit();
for(const database of this.databases) {
for (const database of this.databases) {
database.deinit();
}
this.databases = [];
Expand All @@ -42,7 +48,7 @@ export class WebDeviceInterface extends DeviceInterface {
for (const key of Object.keys(localStorage)) {
results.push({
key: key,
value: localStorage[key]
value: localStorage[key],
});
}
return results;
Expand All @@ -63,29 +69,41 @@ export class WebDeviceInterface extends DeviceInterface {
async openDatabase(identifier: ApplicationIdentifier) {
this.databaseForIdentifier(identifier).unlock();
return new Promise((resolve, reject) => {
this.databaseForIdentifier(identifier).openDatabase(() => {
resolve({ isNewDatabase: true });
}).then(() => {
resolve({ isNewDatabase: false });
}).catch((error => {
reject(error);
}));
this.databaseForIdentifier(identifier)
.openDatabase(() => {
resolve({ isNewDatabase: true });
})
.then(() => {
resolve({ isNewDatabase: false });
})
.catch((error) => {
reject(error);
});
}) as Promise<{ isNewDatabase?: boolean } | undefined>;
}

async getAllRawDatabasePayloads(identifier: ApplicationIdentifier) {
return this.databaseForIdentifier(identifier).getAllPayloads();
}

async saveRawDatabasePayload(payload: any, identifier: ApplicationIdentifier) {
async saveRawDatabasePayload(
payload: any,
identifier: ApplicationIdentifier
) {
return this.databaseForIdentifier(identifier).savePayload(payload);
}

async saveRawDatabasePayloads(payloads: any[], identifier: ApplicationIdentifier) {
async saveRawDatabasePayloads(
payloads: any[],
identifier: ApplicationIdentifier
) {
return this.databaseForIdentifier(identifier).savePayloads(payloads);
}

async removeRawDatabasePayloadWithId(id: string, identifier: ApplicationIdentifier) {
async removeRawDatabasePayloadWithId(
id: string,
identifier: ApplicationIdentifier
) {
return this.databaseForIdentifier(identifier).deletePayload(id);
}

Expand All @@ -101,14 +119,17 @@ export class WebDeviceInterface extends DeviceInterface {
return keychain[identifier];
}

async setNamespacedKeychainValue(value: any, identifier: ApplicationIdentifier) {
async setNamespacedKeychainValue(
value: any,
identifier: ApplicationIdentifier
) {
let keychain = await this.getRawKeychainValue();
if (!keychain) {
keychain = {};
}
return this.bridge.setKeychainValue({
...keychain,
[identifier]: value
[identifier]: value,
});
}

Expand Down

0 comments on commit dfde84c

Please sign in to comment.