editor-main.d.ts 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  1. /**
  2. * @author zhangxin
  3. * @description creator编辑器头文件
  4. * 2020/9/4
  5. */
  6. /**@module Editor (for the Main Process) */
  7. declare module Editor {
  8. export var argv: yargs.argv
  9. /**Indicates if the application is running with --dev option.*/
  10. export var dev
  11. /**The Editor-Framework module path. Usually it is {your-app}/editor-framework/*/
  12. export var frameworkPath: string
  13. /**Indicates if the Editor-Framework App is closing.*/
  14. export readonly var isClosing: boolean
  15. /**Indicates the language used in --lang option.*/
  16. export var lang
  17. /**Absolute path for current open project.*/
  18. export var Project: { path: string }
  19. /**
  20. * Specify the log file path. By default it is saving in:
  21. * Windows: /.{app-name}/logs/{app-home}.log
  22. * Mac: /Library/Logs/{app-name}.log
  23. */
  24. export var logfile
  25. /**A table contains all version info for app and sub-modules. By default it contains App and Editor-Framework version info.*/
  26. export var versions
  27. export type Options = {
  28. i18n: Array,/**Specify i18n phrases for your application*/
  29. layout: string,/**Specify the layout file used as default layout for your application*/
  30. 'main-menu': Function,/**A function returns the main menu template*/
  31. profile: object,/**Register profile name to path table used in Editor.Profile module*/
  32. 'package-search-path:string:string': string[],/**Paths to search packages*/
  33. 'panel-window': string,/**Specify a html file that used as panel window entry page*/
  34. selection: object,/**Register selection type that used in Editor.Selection module*/
  35. theme: string,/**The name of the theme we would like to search for in theme:/** protocol*/
  36. 'theme-search-path:string:string': string[]/** Paths to search in theme:/** protocol*/
  37. }
  38. /**
  39. *
  40. * @param opts
  41. */
  42. export function init(opts: Partial<Options>)
  43. /**
  44. * Run the Editor by restoring last window or openning the a new one.
  45. * @param url The url to load for default main window
  46. * @param opts The opts to used when constructing the default main window
  47. */
  48. export function run(url: string, opts: object)
  49. /**
  50. * Reset the configuration of Editor
  51. */
  52. export function reset()
  53. /**
  54. * Load all packages under path. Once it done the callback will be invoked.
  55. * @param path
  56. * @param callback
  57. */
  58. export function loadPackagesAt(path: string, callback: Funtion)
  59. /**
  60. * Load all packages under the package-search-path:string:string which specified in Editor.init.
  61. * Once it done the callback will be invoked.
  62. * @param callback
  63. */
  64. export function loadAllPackages(callback: Funtion)
  65. /**
  66. * Require the module by Editor.url. This is good for module exists in package,
  67. * since the absolute path of package may be variant in different machine.
  68. * @example:
  69. * this is equal to require(Editor.url('packages:/**foobar/foo'))
  70. * const Foo = Editor.require('packages:/**foobar/foo');
  71. * @param url
  72. */
  73. export function require(url: string)
  74. /**
  75. * Returns the file path (if it is registered in custom protocol) or
  76. * url (if it is a known public protocol).
  77. * @param url
  78. */
  79. export function url(url: string)
  80. /**
  81. * Start watching all packages. Once it done the callback will be invoked.
  82. * @param callback
  83. */
  84. export function watchPackages(callback: Funtion)
  85. }
  86. /**@module console (for the Main Process)*/
  87. declare module Editor {
  88. /**
  89. * Clear the logs. If we specify pattern for the method, it will clear the match pattern. The method will send ipc message editor:console-clear to all windows.
  90. * @param pattern string - Specify the clear pattern
  91. * @param useRegex boolean - If we use regex for the clear pattern
  92. */
  93. export function clearLog(pattern, useRegex)
  94. /**
  95. * After we call this function, all the incoming logs will be stored in the memory, and can be queried by ipc message editor:console-query.
  96. */
  97. export function connectToConsole()
  98. /**
  99. * Log the error message and show on the console, it also shows the call stack start from the function call it. The method will sends ipc message editor:console-error to all windows.
  100. * @param ...args ... - Whatever arguments the message needs
  101. */
  102. export function error(...args)
  103. /**
  104. * Log the fatal message and show on the console, the app will quit immediately after that.
  105. * @param ...args ... - Whatever arguments the message needs
  106. */
  107. export function fatal([...args])
  108. /**
  109. * Log the failed message and show on the console The method will send ipc message editor:console-failed to all windows.
  110. * @param ...args ... - Whatever arguments the message needs
  111. */
  112. export function failed([...args])
  113. /**
  114. * Log the info message and show on the console The method will send ipc message editor:console-info to all windows.
  115. * @param args
  116. */
  117. export function info(...args)
  118. /**
  119. * Log the normal message and show on the console. The method will send ipc message editor:console-log to all windows.
  120. * @param args
  121. */
  122. export function log(...args)
  123. /**
  124. * Log the success message and show on the console The method will send ipc message editor:console-success to all windows.
  125. * @param args
  126. */
  127. export function success(...args)
  128. /**
  129. * Trace the log
  130. * @param level string - The log level
  131. * @param args
  132. */
  133. export function trace(level, ...args)
  134. /**
  135. * Log the warnning message and show on the console, it also shows the call stack start from the function call it. The method will send ipc message editor:console-warn to all windows.
  136. * @param args
  137. */
  138. export function warn(...args)
  139. Message: 'editor:console-query'
  140. /**Return logs stores in the memory in main process.*/
  141. Message: 'editor:renderer-console-error'
  142. /**Log the error message:string from renderer process.*/
  143. Message: 'editor:renderer-console-trace'
  144. /**Trace the log from renderer process.*/
  145. Message: 'editor:renderer-console-failed'
  146. /**Log the failed message:string from renderer process.*/
  147. Message: 'editor:renderer-console-info'
  148. /**Log the failed message:string from renderer process.*/
  149. Message: 'editor:renderer-console-log'
  150. /**Log the normal message:string from renderer process.*/
  151. Message: 'editor:renderer-console-success'
  152. /**Log the success message:string from renderer process.*/
  153. Message: 'editor:renderer-console-warn'
  154. /**Log the warning message:string from renderer process.*/
  155. }
  156. /**@module App */
  157. declare module Editor{
  158. declare class App{
  159. /**Indicates if application is focused */
  160. static focused
  161. /**Your application's home path. Usually it is ~/.{your-app-name} */
  162. static home
  163. /**The name of your app loaded from the name field in package.json. */
  164. static name
  165. /**Your path of your application. */
  166. static path
  167. /**The version of your app loaded from the version field in package.json. */
  168. static version
  169. /**
  170. * Emits event by name.
  171. * @param eventName string - The name of the event
  172. * @param ...args ... - Arguments
  173. */
  174. static emit(eventName, ...args?)
  175. /**
  176. * Extends the Editor.App module. More details read App Lifecycle callbacks
  177. * @param proto object - The prototype used to extends
  178. */
  179. static extends(proto)
  180. /**
  181. * Removes an event listner function.
  182. * @param eventName string - The name of the event
  183. * @param listener function - The callback function
  184. */
  185. static off(eventName, listener)
  186. /**
  187. * Adds an event listner function.
  188. * @param eventName string - The name of the event
  189. * @param listener function - The callback function
  190. */
  191. static on(eventName, listener)
  192. /**
  193. * Adds a one time event listner function.
  194. * @param eventName string - The name of the event
  195. * @param listener function - The callback function
  196. */
  197. static once(eventName, listener)
  198. Event: 'blur'
  199. //Emit when your app is blurred.
  200. Event: 'focus'
  201. //Emit when your app is focused.
  202. Event: 'quit'
  203. //Emit when Editor.App closed all window and main process services.
  204. }
  205. }
  206. /**@module Debugger (for the Main Process) */
  207. declare module Editor {
  208. declare module Debugger
  209. {
  210. /**The debug port for node inspector.*/
  211. export var debugPort
  212. /**Indicate if the node inspector is enabled.*/
  213. export var isNodeInspectorEnabled
  214. /**Indicate if the repl is enabled. */
  215. export var isReplEnabled
  216. /**
  217. * Active devtron.
  218. */
  219. export function activeDevtron()
  220. /**
  221. *Toggle the node inspector in main process.
  222. */
  223. export function toggleNodeInspector()
  224. /**
  225. *Toggle the repl in main process.
  226. */
  227. export function toggleRepl()
  228. /**
  229. *Turn on the node inspector in main process.
  230. */
  231. export function startNodeInspector()
  232. /**
  233. * Turn on the repl in main process.
  234. */
  235. export function startRepl()
  236. /**
  237. *Turn off the node inspector in main process.
  238. */
  239. export function stopNodeInspector()
  240. /**
  241. *Turn off the repl in main process.
  242. */
  243. export function stopRepl()
  244. }
  245. }
  246. /**@module DevTools (for the Main Process) */
  247. declare module Editor {
  248. declare module DevTools{
  249. /**
  250. * Focus on devtools for editorWin.
  251. * @param editorWin
  252. */
  253. export function focus(editorWin: Editor.Window)
  254. /**
  255. * Execute script in the devtools for editorWin.
  256. * @param editorWin
  257. * @param script
  258. */
  259. export function executeJavaScript(editorWin: Editor.Window, script: string)
  260. /**
  261. * Enter the inspect element mode for editorWin.
  262. * @param editorWin
  263. */
  264. export function enterInspectElementMode(editorWin: Editor.Window)
  265. }
  266. }
  267. /**@module Dialog (for the Main Process) */
  268. declare module Editor {
  269. declare module Dialog{
  270. /**
  271. * Same as dialog.showOpenDialog
  272. * @param args
  273. */
  274. export function openFile(...args)
  275. /**
  276. * Same as dialog.showSaveDialog
  277. * @param args
  278. */
  279. export function saveFile(...args)
  280. /**
  281. * Same as dialog.showMessageBox
  282. * @param args
  283. */
  284. export function messageBox(...args)
  285. Message: 'dialog:open-file'
  286. Message: 'dialog:save-file'
  287. Message: 'dialog:message:string-box'
  288. }
  289. }
  290. /**@module Ipc (for the Main Process) */
  291. declare module Editor {
  292. declare module Ipc {
  293. /**Cancel request sent to main or renderer process.*/
  294. export function cancelRequest(sessionID: string)
  295. /** opts object
  296. /** excludeSelf boolean - exclude send ipc message:string to main process when calling Editor.Ipc.sendToAll.
  297. /** Ipc option used in Editor.Ipc.sendToAll.
  298. /**
  299. *
  300. * @param opts :{excludeSelf boolean - exclude send ipc message:string to main process when calling Editor.Ipc.sendToAll.}
  301. */
  302. export function option(opts: { excludeSelf: boolean })
  303. /**
  304. * Send message:string with ...args to all opened window and to main process asynchronously.
  305. * @param message:string string - Ipc message:string.
  306. * @param args - Whatever arguments the message:string needs.
  307. * @param option - You can indicate the last argument as an IPC option by Editor.Ipc.option({...}).
  308. */
  309. export function sendToAll(message: string, ...args, option)
  310. /**
  311. * Send message:string with ...args to main process asynchronously. It is possible to add a callback as the last or the 2nd last argument to receive replies from the IPC receiver.
  312. * @param message:string string - Ipc message:string
  313. * @param args ... - Whatever arguments the message:string needs.
  314. * @param callback function - You can specify a callback function to receive IPC reply at the last or the 2nd last argument.
  315. * @param timeout number - You can specify a timeout for the callback at the last argument. If no timeout specified, it will be 5000ms.
  316. */
  317. export function sendToMain(message: string, ...args, callback: Funtion, timeout)
  318. /**
  319. * Send message:string with ...args to main process synchronized and return a result which is responded from main process.
  320. * @param message:string string - Ipc message:string.
  321. * @param args ... - Whatever arguments the message:string needs.
  322. */
  323. export function sendToMainSync(message: string, ...args)
  324. /**
  325. * Send message:string with ...args to the main window asynchronously.
  326. * @param message:string string - Ipc message:string.
  327. * @param args ... - Whatever arguments the message:string needs.
  328. */
  329. export function sendToMainWin(message: string, ...args)
  330. /**
  331. * Send message:string with ...args to main process by package name and the short name of the message:string.
  332. * @param pkgName string - Package name.
  333. * @param message:string string - Ipc message:string.
  334. * @param args ... - Whatever arguments the message:string needs.
  335. */
  336. export function sendToPackage(pkgName, message: string, ...args)
  337. /**
  338. * Send message:string with ...args to panel defined in renderer process asynchronously. It is possible to add a callback as the last or the 2nd last argument to receive replies from the IPC receiver.
  339. * @param panelID string - Panel ID.
  340. * @param message:string string - Ipc message:string.
  341. * @param args ... - Whatever arguments the message:string needs.
  342. * @param callback function - You can specify a callback function to receive IPC reply at the last or the 2nd last argument.
  343. * @param timeout number - You can specify a timeout for the callback at the last argument. If no timeout specified, it will be 5000ms.
  344. */
  345. export function sendToPanel(panelID, message: string, ...args?, callback: Funtion?, timeout?)
  346. /**
  347. * Send message:string with ...args to all opened windows asynchronously. The renderer process can handle it by listening to the message:string through the Electron.ipcRenderer module.
  348. * @param message:string string - Ipc message:string.
  349. * @param args ... - Whatever arguments the message:string needs.
  350. * @param option object - You can indicate the last argument as an IPC option by Editor.Ipc.option({...}).
  351. */
  352. /**
  353. * @example:
  354. * Send IPC message:string (main process)
  355. * Editor.Ipc.sendToWins('foobar:say-hello', 'Hello World!');
  356. * Receive IPC message:string (renderer process)
  357. * <html>
  358. * <body>
  359. * <script>
  360. * require('ipc').on('foobar:say-hello', (event, text) => {
  361. * console.log(text); //Prints "Hello World!"
  362. * })
  363. * </script>
  364. * </body>
  365. * </html>
  366. */
  367. export function sendToWins(message: string, ...args, option)
  368. }
  369. }
  370. /**@module MainMenu (for the Main Process) module for manipulating main menu items.*/
  371. declare module Editor {
  372. declare module MainMenu
  373. {
  374. /**
  375. * Apply main menu changes.
  376. */
  377. export function apply()
  378. /**
  379. * Build a template into menu item and add it to path
  380. * @param path string - Menu path
  381. * @param template array|object - Menu template
  382. */
  383. export function add(path: string, template: Partial<MenuTemplate>)
  384. /**
  385. * Init main menu.
  386. */
  387. export function init()
  388. /**
  389. * Remove menu item at path.
  390. * @param path string - Menu path
  391. */
  392. export function remove(path: string)
  393. /**
  394. *
  395. * @param path string - Menu path
  396. * @param options options object
  397. * icon NativeImage - A NativeImage
  398. * enabled boolean
  399. * visible boolean
  400. * checked boolean - NOTE: You must set your menu-item type to 'checkbox' to make it work
  401. * Set options of a menu item at path.
  402. */
  403. export function set(path: string, options: Partial<{ icon: NativeImage, enabled: boolean, visible: boolean, checked: boolean }>)
  404. /**
  405. * Build a template into menu item and update it to path
  406. * @param path string - Menu path
  407. * @param template array|object - Menu template
  408. */
  409. export function update(path: string, template: Partial<MenuTemplate>)
  410. export var menu: Editor.Menu
  411. /**Get main menu instance for debug purpose*/
  412. /**IPC Messages*/
  413. Message: 'main-menu:add'
  414. Message: 'main-menu:apply'
  415. Message: 'main-menu:init'
  416. Message: 'main-menu:remove'
  417. Message: 'main-menu:set'
  418. Message: 'main-menu:update'
  419. }
  420. }
  421. declare type MenuTemplate =
  422. {
  423. path: string /**- add a menu item by path.*/
  424. message: string/** - Ipc message:string name.*/
  425. command: string/** - A global function in main process (e.g. Editor.log).*/
  426. params: Array/** - The parameters passed through ipc.*/
  427. panel: string/** - The panelID, if specified, the message:string will send to panel.*/
  428. dev: string/** - Only show when Menu.showDev is true.*/
  429. }
  430. /**@class menu (for the Main Process),*/
  431. declare module Editor {
  432. export class Menu {
  433. constructor(template: Partial<MenuTemplate>, webContents: object)
  434. /**
  435. * Build a template into menu item and add it to path
  436. * @param path:string string - Menu path
  437. * @param template array|object - Menu template
  438. *
  439. * @example:
  440. *let editorMenu = new Editor.Menu();
  441. *editorMenu.add( 'foo/bar', {
  442. *label: foobar,
  443. *message: 'foobar:say',
  444. *params: ['foobar: hello!']
  445. *});
  446. *you can also create menu without label
  447. *it will add menu to foo/bar where bar is the menu-item
  448. *let editorMenu = new Editor.Menu();
  449. *editorMenu.add( 'foo/bar/foobar', {
  450. *message: 'foobar:say',
  451. *params: ['foobar: hello!']
  452. *});
  453. */
  454. add(path: string, template: Partial<MenuTemplate>)
  455. /**
  456. * Clear all menu item in it.
  457. */
  458. clear()
  459. /**
  460. * De-reference the native menu.
  461. */
  462. dispose()
  463. /**
  464. * Build a template into menu item and insert it to path:string at specific position
  465. * @param path:string The menu path:string
  466. * @param pos number
  467. * @param template
  468. */
  469. insert(path: string, pos: number, template: Partial<MenuTemplate>)
  470. /**
  471. * Remove menu item at path.
  472. * @param path string - Menu path
  473. */
  474. remove(path: string)
  475. /**
  476. * Reset the menu from the template.
  477. * @param template
  478. */
  479. reset(template: Partial<MenuTemplate>)
  480. /**
  481. *
  482. * @param path string - Menu path
  483. * @param options options object
  484. * icon NativeImage - A NativeImage
  485. * enabled boolean
  486. * visible boolean
  487. * checked boolean - NOTE: You must set your menu-item type to 'checkbox' to make it work
  488. * Set options of a menu item at path.
  489. */
  490. set(path: string, options: Partial<{ icon: NativeImage, enabled: boolean, visible: boolean, checked: boolean }>)
  491. /**
  492. * Build a template into menu item and update it to path
  493. * @param path string - Menu path
  494. * @param template array|object - Menu template
  495. */
  496. update(path: string, template: Partial<MenuTemplate>)
  497. /**Indicate if show dev menu*/
  498. static showDev
  499. /**
  500. * Convert the menu template to process additional keyword we added for Electron. If webContents provided, the template.message will send to the target webContents.
  501. * @param template Menu template for initialize. The template take the options of Electron's Menu Item
  502. * @param param1 A WebContents object.
  503. */
  504. static convert(template: Partial<MenuTemplate>, [webContents])
  505. /**
  506. *
  507. * @param name Name of the register menu
  508. */
  509. static getMenu(name: string)
  510. /**
  511. *
  512. * @param name Name of the register menu
  513. */
  514. static unregister(name: string)
  515. /**
  516. * @param name Name of the register menu
  517. * @param fn A function returns the menu template
  518. * @param force Force to register a menu even it was registered before
  519. */
  520. static register(name: string, fn: Function, force: boolean)
  521. /**
  522. * @example Editor.Menu.walk(menuTmpl, item => {
  523. if ( item.params ) {
  524. item.params.unshift('Hello');
  525. }
  526. if (item.message === 'foobar:say-hello') {
  527. item.enabled = false;
  528. }
  529. });
  530. * @param template Menu template for initialize. The template take the options of Electron's Menu Item
  531. * @param fn Function applied to each menu item
  532. */
  533. static walk(template: Partial<MenuTemplate>, fn: Function)
  534. Message: 'menu:popup'
  535. Message: 'menu:register'
  536. }
  537. }
  538. /**@module Package (for the Main Process) */
  539. declare module Editor {
  540. declare module Package{
  541. /**
  542. * Load a package at path:string.
  543. * @param path:string string - An absolute path:string point to a package folder
  544. * @param callback function - Callback when finish loading
  545. */
  546. export function load(path: string, callback: Funtion)
  547. /**
  548. * Unload a package at path:string.
  549. * @param path:string string - An absolute path:string point to a package folder
  550. * @param callback function - Callback when finish unloading
  551. */
  552. export function unload(path: string, callback: Funtion)
  553. /**
  554. * Reload a package at path:string.
  555. * @param path:string string - An absolute path:string point to a package folder
  556. * @param callback function - Callback when finish reloading
  557. */
  558. export function reload(path: string, callback: Funtion)
  559. /**
  560. * Find and get panel info via panelID, the panel info is the JSON object that defined in panels.{panel-name} in your package.json.
  561. * @param panelID string - The panel ID
  562. */
  563. export function panelInfo(panelID)
  564. /**
  565. * Find and get package info via path:string, the package info is the JSON object of your package.json file.
  566. * @param path:string string - The package path:string
  567. */
  568. export function packageInfo(path: string)
  569. /**
  570. * Return the path:string of the package by name.
  571. * @param name string - The package name
  572. */
  573. export function packagePath(name)
  574. /**
  575. * Add package search path:string.
  576. * @param path:string string|array - Path to add
  577. */
  578. export function addPath(path: string)
  579. /**
  580. * Remove package search path:string.
  581. * @param path:string string - Path to remove
  582. */
  583. export function removePath(path: string)
  584. /**
  585. * Reset path:string.
  586. */
  587. export function resetPath()
  588. /**
  589. * Find and return the package path:string via name.
  590. * @param name string - Package name
  591. */
  592. export function find(name)
  593. /**Return current language setting.*/
  594. export var lang
  595. /**Return package search path:string list.*/
  596. export var path: string
  597. /**Return the version of sub modules.*/
  598. export var versions
  599. Message: 'editor:package-query-info'
  600. Message: 'editor:package-query-infos'
  601. Message: 'editor:package-reload'
  602. }
  603. }
  604. /**@module Panel (for the Main Process) */
  605. declare module Editor {
  606. declare module Panel {
  607. /**
  608. * Close a panel via panelID.
  609. * @param panelID string - The panelID.
  610. * @param cb function
  611. */
  612. export function close(panelID, cb)
  613. /**
  614. * Find and return an editor window that contains the panelID.
  615. * @param panelID string - The panelID.
  616. */
  617. export function findWindow(panelID)
  618. /**
  619. * Open a panel via panelID and pass argv to it. The argv will be execute in panel's run function in renderer process.
  620. * @param panelID string - The panelID.
  621. * @param argv object - Argument store as key-value table, which will be used in panel's run function in renderer process.
  622. */
  623. export function open(panelID, argv)
  624. /**
  625. * Popup an exists panel via panelID.
  626. * @param panelID string - The panelID.
  627. */
  628. export function popup(panelID)
  629. /**
  630. * The html entry file used for standalone panel window. Default is 'editor-framework:/**static/window.html'.
  631. */
  632. export var templateUrl
  633. Message: 'editor:panel-close'
  634. Message: 'editor:panel-dock'
  635. Message: 'editor:panel-open'
  636. Message: 'editor:panel-popup'
  637. Message: 'editor:panel-query-info'
  638. }
  639. }
  640. /**@module Profile (for the Main Process)*/
  641. declare module Editor {
  642. declare module Profile {
  643. /**
  644. *
  645. * @param name string
  646. * @param type string
  647. * @param defaultProfile object - The default profile to use if the profile is not found.
  648. */
  649. export function load(name, type, defaultProfile)
  650. /**
  651. * Register profile type with the path:string you provide.
  652. * @param type string - The type of the profile you want to register.
  653. * @param path:string string - The path:string for the register type.
  654. */
  655. export function register(type, path: string)
  656. /**
  657. * Reset the registered profiles
  658. */
  659. export function reset()
  660. /**IPC Message*/
  661. Message: 'editor:load-profile'
  662. Message: 'editor:save-profile'
  663. }
  664. }
  665. /**@module Protocol (for the Main Process)*/
  666. declare module Editor {
  667. declare module Protocol{
  668. /**
  669. * Register a protocol so that Editor.url can use it to convert an url to the filesystem path:string. The fn accept an url Object via url.parse.
  670. * @param protocol string - Protocol name
  671. * @param fn function
  672. * @example:
  673. const Path = require('path:string');
  674. let _url2path = base => {
  675. return uri => {
  676. if ( uri.pathname ) {
  677. return Path.join( base, uri.host, uri.pathname );
  678. }
  679. return Path.join( base, uri.host );
  680. };
  681. };
  682. Editor.Protocol.register('editor-framework', _url2path(Editor.frameworkPath));
  683. */
  684. export function register(protocol: string, fn: Function)
  685. }
  686. }
  687. /**@class Window (for the Main Process)*/
  688. declare module Editor {
  689. /**Window class for operating editor window. */
  690. export class Window {
  691. /**
  692. *
  693. * @param name string - The window name.
  694. * @param options object - The Electron's BrowserWindow options with the following additional field
  695. * windowType string - Can be one of the list:
  696. dockable: Indicate the window contains a dockable panel
  697. float: Indicate the window is standalone, and float on top.
  698. fixed-size: Indicate the window is standalone, float on top and non-resizable.
  699. quick: Indicate the window will never destroyed, it only hides itself when it close which make it quick to show the next time.
  700. save boolean - Indicate if save the window position and size.
  701. */
  702. constructor(name, options)
  703. /**
  704. * Try to adjust the window to fit the position and size we give.
  705. * @param x number
  706. * @param y number
  707. * @param w number
  708. * @param h number
  709. */
  710. adjust(x, y, w, h)
  711. /**
  712. * Close the window.
  713. */
  714. close()
  715. /**
  716. * Closes the devtools.
  717. */
  718. closeDevTools()
  719. /**
  720. * Dereference the native window.
  721. */
  722. dispose()
  723. /**
  724. * Clear all panels docked in current window.
  725. */
  726. emptyLayout()
  727. /**
  728. * Focus on the window.
  729. */
  730. focus()
  731. /**
  732. * Force close the window.
  733. */
  734. forceClose()
  735. /**
  736. * Hide the window.
  737. */
  738. hide()
  739. /**
  740. * Load page by url, and send argv in query property of the url. The renderer process will parse the argv when the page is ready and save it in Editor.argv in renderer process.
  741. * @param editorUrl string
  742. * @param argv object
  743. */
  744. load(editorUrl, argv)
  745. /**
  746. * Minimize the window.
  747. */
  748. minimize()
  749. /**
  750. * Opens the devtools.
  751. * @param options
  752. options object
  753. mode string - Opens the devtools with specified dock state, can be right, bottom, undocked, detach. Defaults to last used dock state. In undocked mode it’s possible to dock back. In detach mode it’s not.
  754. */
  755. openDevTools(options)
  756. /**
  757. * Popup a context menu.
  758. * @param template object - The menu template.
  759. * @param x number - The x position.
  760. * @param y number - The y position.
  761. */
  762. popupMenu(template, x, y)
  763. /**
  764. * Reset the dock layout of current window via url
  765. * @param url string
  766. */
  767. resetLayout(url)
  768. /**
  769. * Restore the window.
  770. */
  771. restore()
  772. /**
  773. * Show the window.
  774. */
  775. show()
  776. /**
  777. *
  778. * Send message with ...args to renderer process asynchronously. It is possible to add a callback as the last or the 2nd last argument to receive replies from the IPC receiver.
  779. * @param message string - The message name.
  780. * @param args ... - Whatever arguments the message needs.
  781. @param callback function - You can specify a callback function to receive IPC reply at the last or the 2nd last argument.
  782. @param timeout number - You can specify a timeout for the callback at the last argument. If no timeout specified, it will be 5000ms.
  783. */
  784. send(message, ...args)
  785. /**
  786. *If the window is focused.
  787. */
  788. isFocused: boolean
  789. /**
  790. * If the window is loaded.
  791. */
  792. isLoaded: boolean
  793. /**
  794. *If this is a main window.
  795. */
  796. isMainWindow
  797. /**
  798. * If the window is minimized.
  799. */
  800. isMinimized
  801. /**
  802. * Returns the id list of the panel dock on this window.
  803. */
  804. panels
  805. /**
  806. * The url of the default layout.
  807. */
  808. static defaultLayoutUrl
  809. /** The main window.*/
  810. static main
  811. /**The current opened windows. */
  812. static windows
  813. //Static Methods
  814. /**
  815. * Add an Editor.Window to window list.
  816. * @param win Editor.Window
  817. */
  818. static addWindow(win)
  819. /**
  820. * Find window by name, by BrowserWindow instance or by WebContents instance. Returns the Editor.Window.
  821. * @param param string|BrowserWindow|WebContents
  822. */
  823. static find(param)
  824. /**
  825. * Remove an Editor.Window from window list.
  826. * @param win Editor.Window
  827. */
  828. static removeWindow(win)
  829. //IPC Messages
  830. Message: 'editor:window-center'
  831. Message: 'editor:window-focus'
  832. Message: 'editor:window-inspect-at'
  833. Message: 'editor:window-load'
  834. Message: 'editor:window-open'
  835. Message: 'editor:window-query-layout'
  836. Message: 'editor:window-remove-all-panels'
  837. Message: 'editor:window-resize'
  838. Message: 'editor:window-save-layout'
  839. }
  840. }
  841. /**@class Worker (for the Main Process)*/
  842. declare module Editor {
  843. export class Worker {
  844. /**
  845. *
  846. * @param name name string - The worker name.
  847. * @param options options object
  848. workerType string - Can be one of the list:
  849. renderer: Indicate the worker is running in a hidden window
  850. main: Indicate the worker is running is a process
  851. url string - The url of renderer worker.
  852. */
  853. constructor(name, options)
  854. /**
  855. * Close the worker.
  856. */
  857. close()
  858. /**Dereference the native window. */
  859. dispose()
  860. /**
  861. *
  862. * @param message string
  863. * @param args ... - Whatever arguments the message needs.
  864. */
  865. on(message, ...args)
  866. /**
  867. * Starts the worker.
  868. * @param argv object - The arguments
  869. * @param cb function - The callback function
  870. */
  871. start(argv, cb)
  872. }
  873. }
  874. /**@module Builder (for the Main Process)*/
  875. declare module Editor {
  876. declare module Builder {
  877. /**
  878. * @param eventName string - The name of the event
  879. * @param callback function - The event callback
  880. * options object - Callback params, the build options
  881. cb function - Need to call cb when the callback process finished
  882. */
  883. export function on(eventName, callback)
  884. /**
  885. * @param eventName string - The name of the event
  886. * @param callback function - The event callback
  887. *
  888. options object - Callback params, the build options
  889. cb function - Need to call cb when the callback process finished
  890. */
  891. export function once(eventName, callback)
  892. /**
  893. * @param eventName string - The name of the event
  894. * @param callback function - The event callback
  895. */
  896. export function removeListener(eventName, callback)
  897. // Events
  898. Event: 'build-finished'
  899. //Emit when build finished
  900. Event: 'compile-finished'
  901. //Emit when compile finished
  902. Event: 'before-change-files'
  903. //Emit before editor modifies the build files (e.g, before encryption js files)
  904. }
  905. }