Skip to content

Commit

Permalink
feat(sender): use clipboard on mac while use url in ios devices
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenlx committed Aug 23, 2021
1 parent 0c37e13 commit faf52b7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/modules/sender.ts
Expand Up @@ -2,9 +2,9 @@ import { MbBookNote } from "@alx-plugins/marginnote";

import { ReturnBody, Selection } from "../return";
import { getBody_Note, getBody_Sel, getBody_Toc } from "./parser";
import { showHUD } from "./tools";
import { copy, isMac, showHUD } from "./tools";
import getText from "./translate";
import { ObjToUrl } from "./url-obj";
import { ObjToJson, ObjToUrl } from "./url-obj";

export const SendToc = (src: MbBookNote): void => {
try {
Expand All @@ -18,4 +18,6 @@ export const SendSel = (src: Selection): void => send(getBody_Sel(src));
export const SendNote = (src: MbBookNote): void => send(getBody_Note(src));

const send = (body: ReturnBody) =>
Application.sharedInstance().openURL(NSURL.URLWithString(ObjToUrl(body)));
isMac()
? copy(ObjToJson(body))
: Application.sharedInstance().openURL(NSURL.URLWithString(ObjToUrl(body)));
4 changes: 4 additions & 0 deletions src/modules/tools.ts
@@ -1,3 +1,5 @@
import { osType } from "@alx-plugins/marginnote";

import { scanObject } from "./scan";

export const getWordCount = (src: string) => {
Expand Down Expand Up @@ -48,3 +50,5 @@ const debug = (obj: any) => {
*/
export const getObjCClassDeclar = (name: string, type: string) =>
`${name} : ${type}`;

export const isMac = () => Application.sharedInstance().osType === osType.macOS;
2 changes: 0 additions & 2 deletions src/modules/url-obj.ts
Expand Up @@ -6,10 +6,8 @@ import URLParse from "url-parse";

import { PREFIX, PREFIX_REGEX, VERSION } from "../const";
import { DataType, ReturnBody } from "../return";
import { copy } from "./tools";

export const ObjToUrl = (obj: ReturnBody): string => {
// copy(JSON.stringify(obj));
const url = URLParse("obsidian://mncomp"),
{ type, sendTime, last, data } = obj,
qsObj: QsObj = {
Expand Down

0 comments on commit faf52b7

Please sign in to comment.