TS complete

This commit is contained in:
Mo Bitar
2020-04-13 10:04:19 -05:00
parent 3d955e4b7d
commit 7ee9610dca
29 changed files with 351 additions and 435 deletions

View File

@@ -1,7 +1,7 @@
export function autofocus($timeout: any): {
export declare function autofocus($timeout: ng.ITimeoutService): {
restrict: string;
scope: {
shouldFocus: string;
};
link: ($scope: any, $element: any) => void;
link: ($scope: import("angular").IScope, $element: JQLite) => void;
};

View File

@@ -1,5 +1,5 @@
export function clickOutside($document: any): {
export declare function clickOutside($document: ng.IDocumentService): {
restrict: string;
replace: boolean;
link: ($scope: any, $element: any, attrs: any) => void;
link: ($scope: import("angular").IScope, $element: JQLite, attrs: any) => void;
};

View File

@@ -1,8 +1,9 @@
export function delayHide($timeout: any): {
import angular from 'angular';
export declare function delayHide($timeout: ng.ITimeoutService): {
restrict: string;
scope: {
show: string;
delay: string;
};
link: (scope: any, elem: any, attrs: any) => void;
link: (scope: angular.IScope, elem: JQLite) => void;
};

View File

@@ -1,4 +1,4 @@
export function elemReady($parse: any): {
export declare function elemReady($parse: ng.IParseService): {
restrict: string;
link: ($scope: any, elem: any, attrs: any) => void;
link: ($scope: import("angular").IScope, elem: JQLite, attrs: any) => void;
};

View File

@@ -1,7 +1,7 @@
export function fileChange(): {
export declare function fileChange(): {
restrict: string;
scope: {
handler: string;
};
link: (scope: any, element: any) => void;
link: (scope: import("angular").IScope, element: JQLite) => void;
};

View File

@@ -1,9 +1,9 @@
export { autofocus } from "./autofocus";
export { clickOutside } from "./click-outside";
export { delayHide } from "./delay-hide";
export { elemReady } from "./elemReady";
export { fileChange } from "./file-change";
export { infiniteScroll } from "./infiniteScroll";
export { lowercase } from "./lowercase";
export { selectOnClick } from "./selectOnClick";
export { snEnter } from "./snEnter";
export { autofocus } from './autofocus';
export { clickOutside } from './click-outside';
export { delayHide } from './delay-hide';
export { elemReady } from './elemReady';
export { fileChange } from './file-change';
export { infiniteScroll } from './infiniteScroll';
export { lowercase } from './lowercase';
export { selectOnClick } from './selectOnClick';
export { snEnter } from './snEnter';

View File

@@ -1,3 +1,3 @@
export function infiniteScroll(): {
link: (scope: any, elem: any, attrs: any) => void;
export declare function infiniteScroll(): {
link: (scope: import("angular").IScope, elem: JQLite, attrs: any) => void;
};

View File

@@ -1,4 +1,4 @@
export function lowercase(): {
export declare function lowercase(): {
require: string;
link: (scope: any, element: any, attrs: any, modelCtrl: any) => void;
link: (scope: import("angular").IScope, _: JQLite, attrs: any, ctrl: any) => void;
};

View File

@@ -1,4 +1,4 @@
export function selectOnClick($window: any): {
export declare function selectOnClick($window: ng.IWindowService): {
restrict: string;
link: (scope: any, element: any, attrs: any) => void;
link: (scope: import("angular").IScope, element: JQLite) => void;
};

View File

@@ -1 +1 @@
export function snEnter(): (scope: any, element: any, attrs: any) => void;
export declare function snEnter(): (scope: import("angular").IScope, element: JQLite, attrs: any) => void;

View File

@@ -1,27 +1,4 @@
/// <reference types="pug" />
export class EditorMenu {
restrict: string;
template: import("pug").compileTemplate;
controller: typeof EditorMenuCtrl;
controllerAs: string;
bindToController: boolean;
scope: {
callback: string;
selectedEditor: string;
currentItem: string;
application: string;
};
import { WebDirective } from './../../types';
export declare class EditorMenu extends WebDirective {
constructor();
}
declare class EditorMenuCtrl extends PureCtrl {
constructor($timeout: any);
state: {
isDesktop: any;
};
selectComponent(component: any): void;
toggleDefaultForEditor(editor: any): void;
offlineAvailableForComponent(component: any): any;
makeEditorDefault(component: any): void;
removeEditorDefault(component: any): void;
}
import { PureCtrl } from "../../controllers/abstract/pure_ctrl";
export {};

View File

@@ -1,73 +1,4 @@
/// <reference types="pug" />
export class PanelResizer {
restrict: string;
template: import("pug").compileTemplate;
controller: typeof PanelResizerCtrl;
controllerAs: string;
bindToController: boolean;
scope: {
alwaysVisible: string;
collapsable: string;
control: string;
defaultWidth: string;
hoverable: string;
index: string;
minWidth: string;
onResizeFinish: string;
panelId: string;
property: string;
};
import { WebDirective } from './../../types';
export declare class PanelResizer extends WebDirective {
constructor();
}
declare class PanelResizerCtrl {
constructor($compile: any, $element: any, $timeout: any);
$compile: any;
$element: any;
$timeout: any;
handleResize(): void;
onMouseMove(event: any): void;
onMouseUp(): void;
onMouseDown(event: any): void;
$onInit(): void;
$onDestroy(): void;
onResizeFinish: any;
control: any;
configureControl(): void;
configureDefaults(): void;
panel: HTMLElement | null | undefined;
resizerColumn: any;
currentMinWidth: any;
pressed: boolean | undefined;
startWidth: any;
lastDownX: any;
collapsed: boolean | undefined;
lastWidth: any;
startLeft: number | undefined;
lastLeft: any;
appFrame: DOMRect | null | undefined;
widthBeforeLastDblClick: any;
configureRightPanel(): void;
getParentRect(): any;
reloadDefaultValues(): void;
addDoubleClickHandler(): void;
addMouseDownListener(): void;
addMouseMoveListener(): void;
handleWidthEvent(event: any): void;
handleLeftEvent(event: any): void;
addMouseUpListener(): void;
isAtMaxWidth(): any;
isCollapsed(): boolean;
setWidth(width: any, finish: any): void;
setLeft(left: any): void;
finishSettingWidth(): void;
/**
* If an iframe is displayed adjacent to our panel, and the mouse exits over the iframe,
* document[onmouseup] is not triggered because the document is no longer the same over
* the iframe. We add an invisible overlay while resizing so that the mouse context
* remains in our main document.
*/
addInvisibleOverlay(): void;
overlay: any;
removeInvisibleOverlay(): void;
flash(): void;
}
export {};

View File

@@ -1 +1 @@
export { trusted } from "./trusted";
export { trusted } from './trusted';

View File

@@ -1 +1 @@
export function trusted($sce: any): (url: any) => any;
export declare function trusted($sce: ng.ISCEService): (url: string) => any;

View File

@@ -1,6 +1,5 @@
export class AlertService extends SNAlertService {
constructor(deviceInterface: import("../../../../../snjs/dist/@types").DeviceInterface);
alert(title: any, text: any, closeButtonText?: string, onClose: any): Promise<any>;
confirm(title: any, text: any, confirmButtonText?: string, cancelButtonText?: string, onConfirm: any, onCancel: any, destructive?: boolean): Promise<any>;
import { SNAlertService } from 'snjs';
export declare class AlertService extends SNAlertService {
alert(title: string, text: string, closeButtonText: string | undefined, onClose: () => void): Promise<unknown>;
confirm(title: string, text: string, confirmButtonText: string | undefined, cancelButtonText: string | undefined, onConfirm: () => void, onCancel: () => void, destructive?: boolean): Promise<unknown>;
}
import { SNAlertService } from "../../../../../snjs/dist/@types";

View File

@@ -1,21 +1,16 @@
export class ArchiveManager {
constructor(application: any);
application: any;
/** @public */
public downloadBackup(encrypted: any): Promise<void>;
/** @public */
public downloadBackupOfItems(items: any, encrypted: any): Promise<void>;
/** @private */
import { WebApplication } from '@/application';
import { SNItem } from 'snjs';
export declare class ArchiveManager {
private readonly application;
private textFile?;
constructor(application: WebApplication);
downloadBackup(encrypted: boolean): Promise<void>;
downloadBackupOfItems(items: SNItem[], encrypted: boolean): Promise<void>;
private formattedDate;
/** @private */
private itemsData;
/** @private */
private get zip();
private loadZip;
/** @private */
private downloadZippedItems;
/** @private */
private hrefForData;
textFile: string | undefined;
/** @private */
private downloadData;
}

View File

@@ -1,49 +1,61 @@
export class DesktopManager extends ApplicationService {
constructor($rootScope: any, $timeout: any, application: any);
$rootScope: any;
$timeout: any;
componentActivationObservers: any[];
updateObservers: any[];
import { SNComponent, PurePayload } from 'snjs';
import { WebApplication } from '@/application';
import { ApplicationService, ApplicationEvent } from 'snjs';
declare type UpdateObserverCallback = (component: SNComponent) => void;
declare type ComponentActivationCallback = (payload: PurePayload) => void;
declare type ComponentActivationObserver = {
id: string;
callback: ComponentActivationCallback;
};
export declare class DesktopManager extends ApplicationService {
$rootScope: ng.IRootScopeService;
$timeout: ng.ITimeoutService;
componentActivationObservers: ComponentActivationObserver[];
updateObservers: {
callback: UpdateObserverCallback;
}[];
isDesktop: any;
/** @override */
onAppEvent(eventName: any): void;
dataLoaded: boolean | undefined;
dataLoaded: boolean;
dataLoadHandler?: () => void;
majorDataChangeHandler?: () => void;
extServerHost?: string;
installationSyncHandler?: (payloads: PurePayload[]) => void;
installComponentHandler?: (payload: PurePayload) => void;
lastSearchedText?: string;
searchHandler?: (text?: string) => void;
constructor($rootScope: ng.IRootScopeService, $timeout: ng.ITimeoutService, application: WebApplication);
get webApplication(): WebApplication;
deinit(): void;
onAppEvent(eventName: ApplicationEvent): Promise<void>;
saveBackup(): void;
getExtServerHost(): any;
getExtServerHost(): string | undefined;
/**
* Sending a component in its raw state is really slow for the desktop app
* Keys are not passed into ItemParams, so the result is not encrypted
*/
convertComponentForTransmission(component: any): Promise<any>;
syncComponentsInstallation(components: any): void;
installComponent(component: any): Promise<void>;
registerUpdateObserver(callback: any): () => void;
searchText(text: any): void;
lastSearchedText: any;
convertComponentForTransmission(component: SNComponent): Promise<PurePayload>;
syncComponentsInstallation(components: SNComponent[]): void;
installComponent(component: SNComponent): Promise<void>;
registerUpdateObserver(callback: UpdateObserverCallback): () => void;
searchText(text?: string): void;
redoSearch(): void;
desktop_setSearchHandler(handler: any): void;
searchHandler: any;
desktop_setSearchHandler(handler: (text?: string) => void): void;
desktop_windowGainedFocus(): void;
desktop_windowLostFocus(): void;
desktop_onComponentInstallationComplete(componentData: any, error: any): Promise<void>;
desktop_registerComponentActivationObserver(callback: any): {
id: () => number;
callback: any;
desktop_registerComponentActivationObserver(callback: ComponentActivationCallback): {
id: string;
callback: ComponentActivationCallback;
};
desktop_deregisterComponentActivationObserver(observer: any): void;
notifyComponentActivation(component: any): Promise<void>;
desktop_setExtServerHost(host: any): void;
extServerHost: any;
desktop_setComponentInstallationSyncHandler(handler: any): void;
installationSyncHandler: any;
desktop_setInstallComponentHandler(handler: any): void;
installComponentHandler: any;
desktop_setInitialDataLoadHandler(handler: any): void;
dataLoadHandler: any;
desktop_requestBackupFile(callback: any): Promise<void>;
desktop_setMajorDataChangeHandler(handler: any): void;
majorDataChangeHandler: any;
desktop_deregisterComponentActivationObserver(observer: ComponentActivationObserver): void;
notifyComponentActivation(component: SNComponent): Promise<void>;
desktop_setExtServerHost(host: string): void;
desktop_setComponentInstallationSyncHandler(handler: (payloads: PurePayload[]) => void): void;
desktop_setInstallComponentHandler(handler: (payload: PurePayload) => void): void;
desktop_setInitialDataLoadHandler(handler: () => void): void;
desktop_requestBackupFile(callback: (data: any) => void): Promise<void>;
desktop_setMajorDataChangeHandler(handler: () => void): void;
desktop_didBeginBackup(): void;
desktop_didFinishBackup(success: any): void;
desktop_didFinishBackup(success: boolean): void;
}
import { ApplicationService } from "../../../../../../../../../../Users/mo/Desktop/sn/dev/snjs/dist/@types";
export {};

View File

@@ -1,10 +1,10 @@
export { AlertService } from "./alertService";
export { ArchiveManager } from "./archiveManager";
export { DesktopManager } from "./desktopManager";
export { KeyboardManager } from "./keyboardManager";
export { LockManager } from "./lockManager";
export { NativeExtManager } from "./nativeExtManager";
export { PreferencesManager } from "./preferencesManager";
export { StatusManager } from "./statusManager";
export { ThemeManager } from "./themeManager";
export { AppState } from "./state";
export { AlertService } from './alertService';
export { ArchiveManager } from './archiveManager';
export { DesktopManager } from './desktopManager';
export { KeyboardManager } from './keyboardManager';
export { LockManager } from './lockManager';
export { NativeExtManager } from './nativeExtManager';
export { PreferencesManager } from './preferencesManager';
export { StatusManager } from './statusManager';
export { ThemeManager } from './themeManager';
export { AppState } from './state';

View File

@@ -1,17 +1,18 @@
import { SNPredicate, ApplicationService } from 'snjs';
import { PayloadContent } from '@/../../../../snjs/dist/@types/protocol/payloads/generator';
/** A class for handling installation of system extensions */
export class NativeExtManager extends ApplicationService {
constructor(application: any);
export declare class NativeExtManager extends ApplicationService {
extManagerId: string;
batchManagerId: string;
/** @override */
onAppLaunch(): void;
onAppLaunch(): Promise<void>;
get extManagerPred(): SNPredicate;
get batchManagerPred(): SNPredicate;
get extMgrUrl(): any;
get batchMgrUrl(): any;
reload(): void;
resolveExtensionsManager(): Promise<void>;
extensionsManagerTemplatePayload(): import("../../../../../snjs/dist/@types/protocol/payloads/pure_payload").PurePayload | undefined;
batchManagerTemplatePayload(): import("../../../../../snjs/dist/@types/protocol/payloads/pure_payload").PurePayload | undefined;
extensionsManagerTemplateContent(): PayloadContent;
resolveBatchManager(): Promise<void>;
batchManagerTemplateContent(): PayloadContent;
}
import { ApplicationService } from "../../../../../../../../../../Users/mo/Desktop/sn/dev/snjs/dist/@types";
import { SNPredicate } from "../../../../../../../../../../Users/mo/Desktop/sn/dev/snjs/dist/@types";

View File

@@ -1,29 +1,14 @@
export namespace WebPrefKey {
export const TagsPanelWidth: string;
export const NotesPanelWidth: string;
export const EditorWidth: string;
export const EditorLeft: string;
export const EditorMonospaceEnabled: string;
export const EditorSpellcheck: string;
export const EditorResizersEnabled: string;
export const SortNotesBy: string;
export const SortNotesReverse: string;
export const NotesShowArchived: string;
export const NotesHidePinned: string;
export const NotesHideNotePreview: string;
export const NotesHideDate: string;
export const NotesHideTags: string;
}
export class PreferencesManager extends ApplicationService {
constructor(application: import("../../../../../snjs/dist/@types/application").SNApplication);
import { WebApplication } from '@/application';
import { ApplicationService, WebPrefKey } from 'snjs';
export declare class PreferencesManager extends ApplicationService {
private userPreferences;
/** @override */
onAppLaunch(): void;
onAppLaunch(): Promise<void>;
get webApplication(): WebApplication;
streamPreferences(): void;
loadSingleton(): Promise<void>;
userPreferences: any;
preferencesDidChange(): void;
syncUserPreferences(): void;
getValue(key: any, defaultValue: any): any;
setUserPrefValue(key: any, value: any, sync: any): void;
getValue(key: WebPrefKey, defaultValue?: any): any;
setUserPrefValue(key: WebPrefKey, value: any, sync?: boolean): void;
}
import { ApplicationService } from "../../../../../../../../../../Users/mo/Desktop/sn/dev/snjs/dist/@types";

View File

@@ -1,26 +1,21 @@
export class ThemeManager extends ApplicationService {
constructor(application: any);
activeThemes: any[];
unsubState: any;
unregisterDesktop: any;
unregisterComponent: any;
import { WebApplication } from '@/application';
import { ApplicationService } from 'snjs';
export declare class ThemeManager extends ApplicationService {
private activeThemes;
private unsubState;
private unregisterDesktop;
private unregisterComponent;
constructor(application: WebApplication);
get webApplication(): WebApplication;
deinit(): void;
/** @override */
onAppStart(): void;
/** @access private */
activateCachedThemes(): Promise<void>;
/** @access private */
registerObservers(): void;
/** @access public */
onAppStart(): Promise<void>;
private activateCachedThemes;
private registerObservers;
deactivateAllThemes(): void;
/** @access private */
activateTheme(theme: any, writeToCache?: boolean): void;
/** @access private */
deactivateTheme(theme: any): void;
/** @access private */
cacheThemes(): Promise<void>;
/** @access private */
decacheThemes(): Promise<void>;
/** @access private */
getCachedThemes(): Promise<import("../../../../../snjs/dist/@types/models/core/item").SNItem[]>;
private activateTheme;
private deactivateTheme;
private cacheThemes;
private decacheThemes;
private getCachedThemes;
}
import { ApplicationService } from "../../../../../../../../../../Users/mo/Desktop/sn/dev/snjs/dist/@types";

View File

@@ -4,5 +4,5 @@ export declare function dictToArray(dict: any): any[];
export declare function getPlatformString(): string;
export declare function dateToLocalizedString(date: Date): string;
/** Via https://davidwalsh.name/javascript-debounce-function */
export declare function debounce(this: any, func: any, wait: number, immediate: boolean): () => void;
export declare function debounce(this: any, func: any, wait: number, immediate?: boolean): () => void;
export declare function isDesktopApplication(): any;

View File

@@ -956,7 +956,7 @@ class EditorCtrl extends PureCtrl {
}
}
async toggleWebPrefKey(key: string) {
async toggleWebPrefKey(key: WebPrefKey) {
(this as any)[key] = !(this as any)[key];
this.application.getPrefsService().setUserPrefValue(
key,

View File

@@ -655,7 +655,7 @@ class NotesCtrl extends PureCtrl {
this.setShowMenuFalse();
}
toggleWebPrefKey(key: string) {
toggleWebPrefKey(key: WebPrefKey) {
this.application!.getPrefsService().setUserPrefValue(key, !this.state[key]);
this.application!.getPrefsService().syncUserPreferences();
}

View File

@@ -6,7 +6,7 @@ export function lowercase() {
scope: ng.IScope,
_: JQLite,
attrs: any,
ctrl: ng.IController
ctrl: any
) {
const lowercase = (inputValue: string) => {
if (inputValue === undefined) inputValue = '';

View File

@@ -31,7 +31,7 @@ export class DesktopManager extends ApplicationService {
installationSyncHandler?: (payloads: PurePayload[]) => void
installComponentHandler?: (payload: PurePayload) => void
lastSearchedText?: string
searchHandler?: (text: string) => void
searchHandler?: (text?: string) => void
constructor(
$rootScope: ng.IRootScopeService,
@@ -118,7 +118,7 @@ export class DesktopManager extends ApplicationService {
};
}
searchText(text: string) {
searchText(text?: string) {
if (!this.isDesktop) {
return;
}
@@ -133,7 +133,7 @@ export class DesktopManager extends ApplicationService {
}
// Pass null to cancel search
desktop_setSearchHandler(handler: (text: string) => void) {
desktop_setSearchHandler(handler: (text?: string) => void) {
this.searchHandler = handler;
}

View File

@@ -1,183 +0,0 @@
import { isDesktopApplication, dictToArray } from '@/utils';
import {
SNPredicate,
ContentType,
CreateMaxPayloadFromAnyObject,
ApplicationService
} from 'snjs';
const STREAM_ITEMS_PERMISSION = 'stream-items';
/** A class for handling installation of system extensions */
export class NativeExtManager extends ApplicationService {
/* @ngInject */
constructor(application) {
super(application);
this.extManagerId = 'org.standardnotes.extensions-manager';
this.batchManagerId = 'org.standardnotes.batch-manager';
}
/** @override */
onAppLaunch() {
super.onAppLaunch();
this.reload();
}
get extManagerPred() {
const extManagerId = 'org.standardnotes.extensions-manager';
return SNPredicate.CompoundPredicate([
new SNPredicate('content_type', '=', ContentType.Component),
new SNPredicate('package_info.identifier', '=', extManagerId)
]);
}
get batchManagerPred() {
const batchMgrId = 'org.standardnotes.batch-manager';
return SNPredicate.CompoundPredicate([
new SNPredicate('content_type', '=', ContentType.Component),
new SNPredicate('package_info.identifier', '=', batchMgrId)
]);
}
reload() {
this.application.singletonManager.registerPredicate(this.extManagerPred);
this.application.singletonManager.registerPredicate(this.batchManagerPred);
this.resolveExtensionsManager();
this.resolveBatchManager();
}
async resolveExtensionsManager() {
const extensionsManager = await this.application.singletonManager.findOrCreateSingleton({
predicate: this.extManagerPred,
createPayload: this.extensionsManagerTemplatePayload()
});
let needsSync = false;
if (isDesktopApplication()) {
if (!extensionsManager.local_url) {
extensionsManager.local_url = window._extensions_manager_location;
needsSync = true;
}
} else {
if (!extensionsManager.hosted_url) {
extensionsManager.hosted_url = window._extensions_manager_location;
needsSync = true;
}
}
// Handle addition of SN|ExtensionRepo permission
const permission = extensionsManager.content.permissions.find((p) => p.name === STREAM_ITEMS_PERMISSION);
if (!permission.content_types.includes(ContentType.ExtensionRepo)) {
permission.content_types.push(ContentType.ExtensionRepo);
needsSync = true;
}
if (needsSync) {
this.application.saveItem({ item: extensionsManager });
}
}
extensionsManagerTemplatePayload() {
const url = window._extensions_manager_location;
if (!url) {
console.error('window._extensions_manager_location must be set.');
return;
}
const packageInfo = {
name: 'Extensions',
identifier: this.extManagerId
};
const content = {
name: packageInfo.name,
area: 'rooms',
package_info: packageInfo,
permissions: [
{
name: STREAM_ITEMS_PERMISSION,
content_types: [
ContentType.Component,
ContentType.Theme,
ContentType.ServerExtension,
ContentType.ActionsExtension,
ContentType.Mfa,
ContentType.Editor,
ContentType.ExtensionRepo
]
}
]
};
if (isDesktopApplication()) {
content.local_url = window._extensions_manager_location;
} else {
content.hosted_url = window._extensions_manager_location;
}
const payload = CreateMaxPayloadFromAnyObject({
object: {
content_type: ContentType.Component,
content: content
}
});
return payload;
}
batchManagerTemplatePayload() {
const url = window._batch_manager_location;
if (!url) {
console.error('window._batch_manager_location must be set.');
return;
}
const packageInfo = {
name: 'Batch Manager',
identifier: this.batchManagerId
};
const allContentType = dictToArray(ContentType);
const content = {
name: packageInfo.name,
area: 'modal',
package_info: packageInfo,
permissions: [
{
name: STREAM_ITEMS_PERMISSION,
content_types: allContentType
}
]
};
if (isDesktopApplication()) {
content.local_url = window._batch_manager_location;
} else {
content.hosted_url = window._batch_manager_location;
}
const payload = CreateMaxPayloadFromAnyObject({
object: {
content_type: ContentType.Component,
content: content
}
});
return payload;
}
async resolveBatchManager() {
const batchManager = await this.application.singletonManager.findOrCreateSingleton({
predicate: this.batchManagerPred,
createPayload: this.batchManagerTemplatePayload()
});
let needsSync = false;
if (isDesktopApplication()) {
if (!batchManager.local_url) {
batchManager.local_url = window._batch_manager_location;
needsSync = true;
}
} else {
if (!batchManager.hosted_url) {
batchManager.hosted_url = window._batch_manager_location;
needsSync = true;
}
}
// Handle addition of SN|ExtensionRepo permission
const permission = batchManager.content.permissions.find((p) => p.name === STREAM_ITEMS_PERMISSION);
if (!permission.content_types.includes(ContentType.ExtensionRepo)) {
permission.content_types.push(ContentType.ExtensionRepo);
needsSync = true;
}
if (needsSync) {
this.application.saveItem({ item: batchManager });
}
}
}

View File

@@ -0,0 +1,203 @@
import { isDesktopApplication, dictToArray } from '@/utils';
import {
SNPredicate,
ContentType,
SNComponent,
ApplicationService,
ComponentAction
} from 'snjs';
import { PayloadContent } from '@/../../../../snjs/dist/@types/protocol/payloads/generator';
import { FillItemContent } from '@/../../../../snjs/dist/@types/models/generator';
import { ComponentMutator } from '@/../../../../snjs/dist/@types/models';
/** A class for handling installation of system extensions */
export class NativeExtManager extends ApplicationService {
extManagerId = 'org.standardnotes.extensions-manager';
batchManagerId = 'org.standardnotes.batch-manager';
/** @override */
async onAppLaunch() {
super.onAppLaunch();
this.reload();
}
get extManagerPred() {
const extManagerId = 'org.standardnotes.extensions-manager';
return SNPredicate.CompoundPredicate([
new SNPredicate('content_type', '=', ContentType.Component),
new SNPredicate('package_info.identifier', '=', extManagerId)
]);
}
get batchManagerPred() {
const batchMgrId = 'org.standardnotes.batch-manager';
return SNPredicate.CompoundPredicate([
new SNPredicate('content_type', '=', ContentType.Component),
new SNPredicate('package_info.identifier', '=', batchMgrId)
]);
}
get extMgrUrl() {
return (window as any)._extensions_manager_location;
}
get batchMgrUrl() {
return (window as any)._batch_manager_location;
}
reload() {
this.application!.singletonManager!.registerPredicate(this.extManagerPred);
this.application!.singletonManager!.registerPredicate(this.batchManagerPred);
this.resolveExtensionsManager();
this.resolveBatchManager();
}
async resolveExtensionsManager() {
const extensionsManager = (await this.application!.singletonManager!.findOrCreateSingleton(
this.extManagerPred,
ContentType.Component,
this.extensionsManagerTemplateContent()
)) as SNComponent;
let needsSync = false;
if (isDesktopApplication()) {
if (!extensionsManager.local_url) {
await this.application!.changeItem(extensionsManager.uuid, (m) => {
const mutator = m as ComponentMutator;
mutator.local_url = this.extMgrUrl;
});
needsSync = true;
}
} else {
if (!extensionsManager.hosted_url) {
await this.application!.changeItem(extensionsManager.uuid, (m) => {
const mutator = m as ComponentMutator;
mutator.hosted_url = this.extMgrUrl;
});
needsSync = true;
}
}
// Handle addition of SN|ExtensionRepo permission
const permissions = extensionsManager!.permissions.slice();
const permission = permissions.find((p) => {
return p.name === ComponentAction.StreamItems
});
if (permission && !permission.content_types!.includes(ContentType.ExtensionRepo)) {
permission.content_types!.push(ContentType.ExtensionRepo);
await this.application!.changeItem(extensionsManager.uuid, (m) => {
const mutator = m as ComponentMutator;
mutator.permissions = permissions;
});
needsSync = true;
}
if (needsSync) {
this.application!.saveItem(extensionsManager.uuid);
}
}
extensionsManagerTemplateContent() {
const url = this.extMgrUrl;
if (!url) {
throw Error('this.extMgrUrl must be set.');
}
const packageInfo = {
name: 'Extensions',
identifier: this.extManagerId
};
const content = FillItemContent({
name: packageInfo.name,
area: 'rooms',
package_info: packageInfo,
permissions: [
{
name: ComponentAction.StreamItems,
content_types: [
ContentType.Component,
ContentType.Theme,
ContentType.ServerExtension,
ContentType.ActionsExtension,
ContentType.Mfa,
ContentType.Editor,
ContentType.ExtensionRepo
]
}
]
}) as PayloadContent;
if (isDesktopApplication()) {
content.local_url = this.extMgrUrl;
} else {
content.hosted_url = this.extMgrUrl;
}
return content;
}
async resolveBatchManager() {
const batchManager = (await this.application!.singletonManager!.findOrCreateSingleton(
this.batchManagerPred,
ContentType.Component,
this.batchManagerTemplateContent()
)) as SNComponent;
let needsSync = false;
if (isDesktopApplication()) {
if (!batchManager.local_url) {
await this.application!.changeItem(batchManager.uuid, (m) => {
const mutator = m as ComponentMutator;
mutator.local_url = this.batchMgrUrl;
});
needsSync = true;
}
} else {
if (!batchManager.hosted_url) {
await this.application!.changeItem(batchManager.uuid, (m) => {
const mutator = m as ComponentMutator;
mutator.hosted_url = this.batchMgrUrl;
});
needsSync = true;
}
}
// Handle addition of SN|ExtensionRepo permission
const permissions = batchManager!.permissions.slice();
const permission = permissions.find((p) => {
return p.name === ComponentAction.StreamItems
});
if (permission && !permission.content_types!.includes(ContentType.ExtensionRepo)) {
permission.content_types!.push(ContentType.ExtensionRepo);
await this.application!.changeItem(batchManager.uuid, (m) => {
const mutator = m as ComponentMutator;
mutator.permissions = permissions;
});
needsSync = true;
}
if (needsSync) {
this.application!.saveItem(batchManager.uuid);
}
}
batchManagerTemplateContent() {
const url = this.batchMgrUrl;
if (!url) {
throw Error('window._batch_manager_location must be set.');
}
const packageInfo = {
name: 'Batch Manager',
identifier: this.batchManagerId
};
const allContentType = dictToArray(ContentType);
const content = FillItemContent({
name: packageInfo.name,
area: 'modal',
package_info: packageInfo,
permissions: [
{
name: ComponentAction.StreamItems,
content_types: allContentType
}
]
});
if (isDesktopApplication()) {
content.local_url = this.batchMgrUrl;
} else {
content.hosted_url = this.batchMgrUrl;
}
return content;
}
}

View File

@@ -54,7 +54,7 @@ export class PreferencesManager extends ApplicationService {
}
}
getValue(key: WebPrefKey, defaultValue: any) {
getValue(key: WebPrefKey, defaultValue?: any) {
if (!this.userPreferences) { return defaultValue; }
const value = this.userPreferences.getPref(key);
return (value !== undefined && value !== null) ? value : defaultValue;