1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

fixed tests

This commit is contained in:
Laurent Cozic 2021-06-20 13:46:50 +01:00
parent 8e55fe31ee
commit d13b1f96ba
6 changed files with 37 additions and 72 deletions

View File

@ -1,4 +1,5 @@
import bridge from '../bridge';
const { clipboard, nativeImage } = require('electron');
interface JoplinViewsDialogs {
showMessageBox(message: string): Promise<number>;
@ -16,6 +17,9 @@ interface Components {
[key: string]: any;
}
// PlatformImplementation provides access to platform specific dependencies,
// such as the clipboard, message dialog, etc. It allows having the same plugin
// API for all platforms, but with different implementations.
export default class PlatformImplementation {
private static instance_: PlatformImplementation;
@ -27,6 +31,14 @@ export default class PlatformImplementation {
return this.instance_;
}
public get clipboard() {
return clipboard;
}
public get nativeImage() {
return nativeImage;
}
constructor() {
this.components_ = {};

View File

@ -2,10 +2,12 @@ import { ModelType } from "../../BaseModel";
export interface BaseItemEntity {
id?: string;
encryption_applied?: boolean;
encryption_applied?: number;
is_shared?: number;
share_id?: string;
type_?: ModelType;
updated_time?: number;
created_time?: number;
}

View File

@ -12,51 +12,15 @@ import Joplin from './Joplin';
export default class Global {
private joplin_: Joplin;
// private requireWhiteList_: string[] = null;
// private consoleWrapper_:any = null;
constructor(implementation: any, plugin: Plugin, store: any) {
this.joplin_ = new Joplin(implementation.joplin, plugin, store);
// this.consoleWrapper_ = this.createConsoleWrapper(plugin.id);
this.joplin_ = new Joplin(implementation, plugin, store);
}
// Wraps console calls to allow prefixing them with "Plugin PLUGIN_ID:"
// private createConsoleWrapper(pluginId:string) {
// const wrapper:any = {};
// for (const n in console) {
// if (!console.hasOwnProperty(n)) continue;
// wrapper[n] = (...args:any[]) => {
// const newArgs = args.slice();
// newArgs.splice(0, 0, `Plugin "${pluginId}":`);
// return (console as any)[n](...newArgs);
// };
// }
// return wrapper;
// }
get joplin(): Joplin {
return this.joplin_;
}
// private requireWhiteList(): string[] {
// if (!this.requireWhiteList_) {
// this.requireWhiteList_ = builtinModules.slice();
// this.requireWhiteList_.push('fs-extra');
// }
// return this.requireWhiteList_;
// }
// get console(): any {
// return this.consoleWrapper_;
// }
// require(filePath: string): any {
// if (!this.requireWhiteList().includes(filePath)) throw new Error(`Path not allowed: ${filePath}`);
// return require(filePath);
// }
// To get webpack to work with Node module we need to set the parameter `target: "node"`, however
// when setting this, the code generated by webpack will try to access the `process` global variable,
// which won't be defined in the sandbox. So here we simply forward the variable, which makes it all work.
@ -64,24 +28,4 @@ export default class Global {
return process;
}
// setTimeout(fn: Function, interval: number) {
// return shim.setTimeout(() => {
// fn();
// }, interval);
// }
// setInterval(fn: Function, interval: number) {
// return shim.setInterval(() => {
// fn();
// }, interval);
// }
// alert(message:string) {
// return alert(message);
// }
// confirm(message:string) {
// return confirm(message);
// }
}

View File

@ -44,11 +44,11 @@ export default class Joplin {
this.workspace_ = new JoplinWorkspace(store);
this.filters_ = new JoplinFilters();
this.commands_ = new JoplinCommands();
this.views_ = new JoplinViews(implementation.views, plugin, store);
this.views_ = new JoplinViews(implementation.joplin.views, plugin, store);
this.interop_ = new JoplinInterop();
this.settings_ = new JoplinSettings(plugin);
this.contentScripts_ = new JoplinContentScripts(plugin);
this.clipboard_ = new JoplinClipboard();
this.clipboard_ = new JoplinClipboard(implementation.clipboard, implementation.nativeImage);
}
get data(): JoplinData {

View File

@ -1,28 +1,34 @@
const { clipboard, nativeImage } = require('electron');
export default class JoplinClipboard {
private electronClipboard_: any = null;
private electronNativeImage_: any = null;
public constructor(electronClipboard: any, electronNativeImage: any) {
this.electronClipboard_ = electronClipboard;
this.electronNativeImage_ = electronNativeImage;
}
public async readText(): Promise<string> {
return clipboard.readText();
return this.electronClipboard_.readText();
}
public async writeText(text: string): Promise<void> {
clipboard.writeText(text);
this.electronClipboard_.writeText(text);
}
public async readHtml(): Promise<string> {
return clipboard.readHTML();
return this.electronClipboard_.readHTML();
}
public async writeHtml(html: string): Promise<void> {
clipboard.writeHTML(html);
this.electronClipboard_.writeHTML(html);
}
/**
* Returns the image in [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) format.
*/
public async readImage(): Promise<string> {
const image = clipboard.readImage();
const image = this.electronClipboard_.readImage();
return image ? image.toDataURL() : '';
}
@ -30,7 +36,7 @@ export default class JoplinClipboard {
* Takes an image in [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) format.
*/
public async writeImage(dataUrl: string): Promise<void> {
clipboard.writeImage(nativeImage.createFromDataURL(dataUrl));
this.electronClipboard_.writeImage(this.electronNativeImage_.createFromDataURL(dataUrl));
}
/**
@ -39,7 +45,7 @@ export default class JoplinClipboard {
* For example [ 'text/plain', 'text/html' ]
*/
public async availableFormats(): Promise<string[]> {
return clipboard.availableFormats();
return this.electronClipboard_.availableFormats();
}
}

View File

@ -1,7 +1,8 @@
import { ModelType } from '../../BaseModel';
import { FileApi, MultiPutItem } from '../../file-api';
import Logger from '../../Logger';
import BaseItem, { ItemThatNeedSync } from '../../models/BaseItem';
import BaseItem from '../../models/BaseItem';
import { BaseItemEntity } from '../database/types';
const logger = Logger.create('ItemUploader');
@ -32,7 +33,7 @@ export default class ItemUploader {
this.maxBatchSize_ = v;
}
public async serializeAndUploadItem(ItemClass: any, path: string, local: ItemThatNeedSync) {
public async serializeAndUploadItem(ItemClass: any, path: string, local: BaseItemEntity) {
const preUploadItem = this.preUploadedItems_[path];
if (preUploadItem) {
if (this.preUploadedItemUpdatedTimes_[path] !== local.updated_time) {
@ -52,7 +53,7 @@ export default class ItemUploader {
await this.apiCall_('put', path, content);
}
public async preUploadItems(items: ItemThatNeedSync[]) {
public async preUploadItems(items: BaseItemEntity[]) {
if (!this.api_.supportsMultiPut) return;
const itemsToUpload: BatchItem[] = [];