Skip to content
This repository has been archived by the owner on Jun 20, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/3.6.3' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
arielsvg committed Mar 25, 2021
2 parents e25ff84 + 333c84f commit 8a9bff8
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 116 deletions.
7 changes: 7 additions & 0 deletions app/javascripts/main/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** Build-time constants */

declare const AUTO_UPDATING_AVAILABLE: boolean;
declare const KEYCHAIN_ACCESS_IS_USER_CONFIGURABLE: boolean;

export const autoUpdatingAvailable = AUTO_UPDATING_AVAILABLE;
export const keychainAccessIsUserConfigurable = KEYCHAIN_ACCESS_IS_USER_CONFIGURABLE;
3 changes: 2 additions & 1 deletion app/javascripts/main/keychain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { app, BrowserWindow, ipcMain } from 'electron';
import keytar from 'keytar';
import { isLinux } from './platforms';
import { AppName } from './strings';
import { isDev, isTesting, keychainAccessIsUserConfigurable } from './utils';
import { keychainAccessIsUserConfigurable } from './constants';
import { isDev, isTesting } from './utils';
import { IpcMessages } from '../shared/ipcMessages';
import {
grantLinuxPasswordsAccessJsPath,
Expand Down
3 changes: 2 additions & 1 deletion app/javascripts/main/menus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
WebContents,
} from 'electron';
import { autorun } from 'mobx';
import { autoUpdatingAvailable } from './constants';
import { MessageType } from '../../../test/TestIpcMessage';
import { BackupsManager } from './backupsManager';
import { isLinux, isMac } from './platforms';
Expand All @@ -23,7 +24,7 @@ import {
openChangelog,
showUpdateInstallationDialog,
} from './updateManager';
import { autoUpdatingAvailable, isDev, isTesting } from './utils';
import { isDev, isTesting } from './utils';

export const enum MenuId {
SpellcheckerLanguages = 'SpellcheckerLanguages',
Expand Down
3 changes: 2 additions & 1 deletion app/javascripts/main/updateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { BrowserWindow, dialog, shell } from 'electron';
import electronLog from 'electron-log';
import { autoUpdater } from 'electron-updater';
import { action, autorun, computed, makeObservable, observable } from 'mobx';
import { autoUpdatingAvailable } from './constants';
import { MessageType } from '../../../test/TestIpcMessage';
import { AppState } from '../../application';
import { BackupsManager } from './backupsManager';
import { isMac } from './platforms';
import { StoreKeys } from './store';
import { updates as str } from './strings';
import { handle } from './testing';
import { autoUpdatingAvailable, isTesting } from './utils';
import { isTesting } from './utils';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function logError(...message: any) {
Expand Down
6 changes: 0 additions & 6 deletions app/javascripts/main/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { CommandLineArgs } from '../shared/CommandLineArgs';

declare const AUTO_UPDATING_AVAILABLE: boolean;
declare const KEYCHAIN_ACCESS_IS_USER_CONFIGURABLE: boolean;

export const autoUpdatingAvailable = AUTO_UPDATING_AVAILABLE;
export const keychainAccessIsUserConfigurable = KEYCHAIN_ACCESS_IS_USER_CONFIGURABLE;

export function isDev(): boolean {
return process.env.NODE_ENV === 'development';
}
Expand Down
178 changes: 85 additions & 93 deletions app/javascripts/main/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,82 @@ export async function createWindowState({
}): Promise<WindowState> {
const window = await createWindow(appState.store);
const services = createWindowServices(window, appState, appLocale);
registerWindowEventListeners({
shell,
appState,
window,
backupsManager: services.backupsManager,
trayManager: services.trayManager,
onClosed: teardown,

const shouldOpenUrl = (url: string) =>
url.startsWith('http') || url.startsWith('mailto');

window.on('closed', teardown);

window.on('show', () => {
checkForUpdate(appState, appState.updates, false);
});

window.on('focus', () => {
window.webContents.send(IpcMessages.WindowFocused, null);
});

window.on('blur', () => {
window.webContents.send(IpcMessages.WindowBlurred, null);
services.backupsManager.applicationDidBlur();
});

window.once('ready-to-show', () => {
window.show();
});

window.webContents.on('ipc-message', async (_event, message) => {
if (message === IpcMessages.SigningOut) {
await window.webContents.session.clearStorageData();
window.webContents.session.flushStorageData();
}
});

window.on('close', (event) => {
if (
!appState.willQuitApp &&
(isMac() || services.trayManager.shouldMinimizeToTray())
) {
/**
* On MacOS, closing a window does not quit the app. On Window and Linux,
* it only does if you haven't enabled minimize to tray.
*/
event.preventDefault();
/**
* Handles Mac full screen issue where pressing close results
* in a black screen.
*/
if (window.isFullScreen()) {
window.setFullScreen(false);
}
window.hide();
}
});

/** handle link clicks */
window.webContents.on('new-window', (event, url) => {
if (shouldOpenUrl(url)) {
shell.openExternal(url);
}
event.preventDefault();
});

/**
* handle link clicks (this event is fired instead of 'new-window' when
* target is not set to _blank)
*/
window.webContents.on('will-navigate', (event, url) => {
/** Check for windowUrl equality in the case of window.reload() calls. */
if (fileUrlsAreEqual(url, appState.startUrl)) {
return;
}
if (shouldOpenUrl(url)) {
shell.openExternal(url);
}
event.preventDefault();
});

window.webContents.on('context-menu', (_event, params) => {
buildContextMenu(window.webContents, params).popup();
});

return {
Expand Down Expand Up @@ -98,6 +167,15 @@ async function createWindow(store: Store): Promise<Electron.BrowserWindow> {
handle(MessageType.SpellCheckerLanguages, () =>
window.webContents.session.getSpellCheckerLanguages()
);
handle(MessageType.SetLocalStorageValue, async (key, value) => {
await window.webContents.executeJavaScript(
`localStorage.setItem("${key}", "${value}")`
);
window.webContents.session.flushStorageData();
});
handle(MessageType.ExecuteJavaScript, (code) =>
window.webContents.executeJavaScript(code)
);
window.webContents.once('did-finish-load', () => {
send(AppMessageType.WindowLoaded);
});
Expand Down Expand Up @@ -171,92 +249,6 @@ function fileUrlsAreEqual(a: string, b: string): boolean {
}
}

function registerWindowEventListeners({
shell,
appState,
window,
backupsManager,
trayManager,
onClosed,
}: {
shell: Shell;
appState: AppState;
window: Electron.BrowserWindow;
backupsManager: BackupsManager;
trayManager: TrayManager;
onClosed: () => void;
}) {
const shouldOpenUrl = (url: string) =>
url.startsWith('http') || url.startsWith('mailto');

window.on('closed', onClosed);

window.on('show', () => {
checkForUpdate(appState, appState.updates, false);
});

window.on('focus', () => {
window.webContents.send(IpcMessages.WindowFocused, null);
});

window.on('blur', () => {
window.webContents.send(IpcMessages.WindowBlurred, null);
backupsManager.applicationDidBlur();
});

window.once('ready-to-show', () => {
window.show();
});

window.on('close', (event) => {
if (
!appState.willQuitApp &&
(isMac() || trayManager.shouldMinimizeToTray())
) {
/**
* On MacOS, closing a window does not quit the app. On Window and Linux,
* it only does if you haven't enabled minimize to tray.
*/
event.preventDefault();
/**
* Handles Mac full screen issue where pressing close results
* in a black screen.
*/
if (window.isFullScreen()) {
window.setFullScreen(false);
}
window.hide();
}
});

/** handle link clicks */
window.webContents.on('new-window', (event, url) => {
if (shouldOpenUrl(url)) {
shell.openExternal(url);
}
event.preventDefault();
});

/**
* handle link clicks (this event is fired instead of 'new-window' when
* target is not set to _blank)
*/
window.webContents.on('will-navigate', (event, url) => {
/** Check for windowUrl equality in the case of window.reload() calls. */
if (fileUrlsAreEqual(url, appState.startUrl)) {
return;
}
if (shouldOpenUrl(url)) {
shell.openExternal(url);
}
event.preventDefault();
});

window.webContents.on('context-menu', (_event, params) => {
buildContextMenu(window.webContents, params).popup();
});
}

interface WindowPosition {
bounds: Rectangle;
isMaximized: boolean;
Expand Down
2 changes: 1 addition & 1 deletion app/javascripts/renderer/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ process.once('loaded', function () {
function loadTransmitter() {
transmitter.expose({
extServerHost: Store.get(StoreKeys.ExtServerHost),
useNativeKeychain: Store.get(StoreKeys.UseNativeKeychain),
useNativeKeychain: Store.get(StoreKeys.UseNativeKeychain) ?? true,
rendererPath,
isMacOS: process.platform === 'darwin',
appVersion: remote.app.getVersion(),
Expand Down
10 changes: 7 additions & 3 deletions app/javascripts/renderer/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ declare global {
electronAppVersion: string;
zip: any;
startApplication: StartApplication;
bridge: Bridge;
}
}

Expand All @@ -37,17 +38,17 @@ window._bugsnag_api_key = BUGSNAG_API_KEY;

await configureWindow(mainThread);

const webBridge = await createWebBridge(mainThread);
window.bridge = await createWebBridge(mainThread);
window.startApplication(
// eslint-disable-next-line no-undef
DEFAULT_SYNC_SERVER || 'https://sync.standardnotes.org',
webBridge
window.bridge
);

await new Promise((resolve) =>
window.angular.element(document).ready(resolve)
);
registerIpcMessageListener(webBridge);
registerIpcMessageListener(window.bridge);
})();
loadZipLibrary();

Expand Down Expand Up @@ -127,6 +128,9 @@ async function createWebBridge(mainThread: any): Promise<Bridge> {
onInitialDataLoad() {
mainThread.sendIpcMessage(IpcMessages.InitialDataLoaded, {});
},
onSignOut() {
mainThread.sendIpcMessage(IpcMessages.SigningOut, {});
},
async downloadBackup() {
const desktopManager = window.desktopManager;
desktopManager.desktop_didBeginBackup();
Expand Down
1 change: 1 addition & 0 deletions app/javascripts/shared/ipcMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export enum IpcMessages {
Quit = 'Quit',
UseLocalstorageForKeychain = 'UseLocalstorageForKeychain',
LearnMoreAboutKeychainAccess = 'LearnMoreAboutKeychainAccess',
SigningOut = 'SigningOut',
}
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"productName": "Standard Notes",
"description": "A simple and private place for your notes, thoughts, and life's work.",
"author": "Standard Notes <[email protected]>",
"version": "3.6.2",
"version": "3.6.3",
"main": "./dist/index.js",
"dependencies": {
"keytar": "^7.4.0",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "standard-notes",
"main": "./app/dist/index.js",
"version": "3.6.2",
"version": "3.6.3",
"repository": {
"type": "git",
"url": "git://github.com/standardnotes/desktop"
Expand Down
2 changes: 2 additions & 0 deletions test/TestIpcMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export enum MessageType {
StoreData,
StoreSettingsLocation,
StoreSet,
SetLocalStorageValue,
AppMenuItems,
SpellCheckerManager,
SpellCheckerLanguages,
Expand All @@ -46,4 +47,5 @@ export enum MessageType {
AutoUpdateEnabled,
HasReloadedMenu,
AppStateCall,
ExecuteJavaScript,
}
9 changes: 8 additions & 1 deletion test/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ class Driver {
appStateCall = (methodName: string, ...args: any): Promise<any> =>
this.send(MessageType.AppStateCall, methodName, ...args);

readonly store = {
readonly window = {
executeJavascript: (code: string): Promise<unknown> =>
this.send(MessageType.ExecuteJavaScript, code),
};

readonly storage = {
dataOnDisk: async (): Promise<{ [key in StoreKeys]: any }> => {
const location = await this.send(MessageType.StoreSettingsLocation);
return readJSONFile(location);
Expand All @@ -119,6 +124,8 @@ class Driver {
this.send(MessageType.StoreSettingsLocation),
setZoomFactor: (factor: number) =>
this.send(MessageType.StoreSet, 'zoomFactor', factor),
setLocalStorageValue: (key: string, value: string): Promise<void> =>
this.send(MessageType.SetLocalStorageValue, key, value),
};

readonly appMenu = {
Expand Down
Loading

0 comments on commit 8a9bff8

Please sign in to comment.