奇怪的用法增加了:通过渲染进程在思源中拉起子应用 - 链滴 (ld246.com)
上面那个帖子介绍了在新的渲染进程中拉服务的办法。
electron 的渲染进程又是有 node 环境的对吧, 所以我们可以用它来做一些奇怪的事情。
比如说直接把思源的前端代码拉到应用里跑着玩。
但是我们知道思源的源码都是 ts 嘛,所以需要搞一点点小操作,比如说把它转译成 js 之后伺服。
转译的部分挺长的就直接放 github 链接算了,老哥们应该都能够看到吧。。。。。
naive/script/coreServicies/compiler at master · leolee9086/naive (github.com)
不过直接跑是跑不了的,pdfjs.js 那里会出问题,不过只要改改就行了
·
/* Copyright 2016 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals module, __non_webpack_require__ */
"use strict";
import {addScriptSync} from '../../protyle/util/addScript'
import {Constants} from '../../constants'
addScriptSync(`${Constants.PROTYLE_CDN}/js/pdf/pdf.js`, 'pdfjsScript')
export default window["pdfjs-dist/build/pdf"]
export let __esModule = window["pdfjs-dist/build/pdf"]["__esModule"]
export let AnnotationEditorLayer = window["pdfjs-dist/build/pdf"]["AnnotationEditorLayer"]
export let AnnotationEditorParamsType = window["pdfjs-dist/build/pdf"]["AnnotationEditorParamsType"]
export let AnnotationEditorType = window["pdfjs-dist/build/pdf"]["AnnotationEditorType"]
export let AnnotationEditorUIManager = window["pdfjs-dist/build/pdf"]["AnnotationEditorUIManager"]
export let AnnotationLayer = window["pdfjs-dist/build/pdf"]["AnnotationLayer"]
export let AnnotationMode = window["pdfjs-dist/build/pdf"]["AnnotationMode"]
export let CMapCompressionType = window["pdfjs-dist/build/pdf"]["CMapCompressionType"]
export let GlobalWorkerOptions = window["pdfjs-dist/build/pdf"]["GlobalWorkerOptions"]
export let InvalidPDFException = window["pdfjs-dist/build/pdf"]["InvalidPDFException"]
export let MissingPDFException = window["pdfjs-dist/build/pdf"]["MissingPDFException"]
export let OPS = window["pdfjs-dist/build/pdf"]["OPS"]
export let PDFDataRangeTransport = window["pdfjs-dist/build/pdf"]["PDFDataRangeTransport"]
export let PDFDateString = window["pdfjs-dist/build/pdf"]["PDFDateString"]
export let PDFWorker = window["pdfjs-dist/build/pdf"]["PDFWorker"]
export let PasswordResponses = window["pdfjs-dist/build/pdf"]["PasswordResponses"]
export let PermissionFlag = window["pdfjs-dist/build/pdf"]["PermissionFlag"]
export let PixelsPerInch = window["pdfjs-dist/build/pdf"]["PixelsPerInch"]
export let RenderingCancelledException = window["pdfjs-dist/build/pdf"]["RenderingCancelledException"]
export let SVGGraphics = window["pdfjs-dist/build/pdf"]["SVGGraphics"]
export let UNSUPPORTED_FEATURES = window["pdfjs-dist/build/pdf"]["UNSUPPORTED_FEATURES"]
export let UnexpectedResponseException = window["pdfjs-dist/build/pdf"]["UnexpectedResponseException"]
export let Util = window["pdfjs-dist/build/pdf"]["Util"]
export let VerbosityLevel = window["pdfjs-dist/build/pdf"]["VerbosityLevel"]
export let XfaLayer = window["pdfjs-dist/build/pdf"]["XfaLayer"]
export let build = window["pdfjs-dist/build/pdf"]["build"]
export let createPromiseCapability = window["pdfjs-dist/build/pdf"]["createPromiseCapability"]
export let createValidAbsoluteUrl = window["pdfjs-dist/build/pdf"]["createValidAbsoluteUrl"]
export let getDocument = window["pdfjs-dist/build/pdf"]["getDocument"]
export let getFilenameFromUrl = window["pdfjs-dist/build/pdf"]["getFilenameFromUrl"]
export let getPdfFilenameFromUrl = window["pdfjs-dist/build/pdf"]["getPdfFilenameFromUrl"]
export let getXfaPageViewport = window["pdfjs-dist/build/pdf"]["getXfaPageViewport"]
export let isPdfFile = window["pdfjs-dist/build/pdf"]["isPdfFile"]
export let loadScript = window["pdfjs-dist/build/pdf"]["loadScript"]
export let renderTextLayer = window["pdfjs-dist/build/pdf"]["renderTextLayer"]
export let shadow = window["pdfjs-dist/build/pdf"]["shadow"]
export let version = window["pdfjs-dist/build/pdf"]["version"]
就是把它改得啰嗦一点..........
naive/pdfjs.js at master · leolee9086/naive (github.com)
为啥不用 vite 呢,因为一是一开始没配置好在思源里拉起 vite 老是出问题,二是改了代码之后 vite 热更新其实也没有比直接刷新快多少(主要是因为我菜)..............
还有一个地方就是思源得源码里面是有一些像这样的代码的嘛
///#if !BROWSER
///endif
这里需要一个解析工具 ,用 vite 的老哥可以试试 vite-plugin-ifdef(之前弄得挺糙得,最好自己改改再用),不用的话就直接自己弄一下条件解析就行了。
整出来反正是能够跑起来的。
这玩意有什么用呢。。。。。。
思源的编辑器比较复杂,有的时候自己改了也不大敢往仓库 pr 对吧,但是自娱自乐的时候我又不喜欢老是要去打命令行,所以就干脆在思源里面拉一个思源得了,基本实现魔改自由(并没有,因为 V 姐肝得太快所以你的魔改代码也得跟着改...... 过不了两天就觉得就跟不动了就安心当条咸鱼算了)
上面那个就是运行效果,看起来差不多是吧,其实它是这样的
然后那天看到主仓库里有个 api.ts 但是没怎么动就自己玩了一下。。。
所以说到底还是并无什么卵用.......
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于