import settingViewControllerInst from "settingViewController/main" ; import { Range , readProfile , removeProfile , saveProfile } from "utils/profile" ; import { getObjCClassDeclar , showHUD } from "utils/common" ; import { closePanel , layoutViewController } from "./switchPanel" ; import { docProfilePreset , profilePreset , profileTempPreset } from "profile" ; import { gestureHandlers } from "./handleGestureEvent" ; import { eventHandlers } from "./handleReceivedEvent" ; import lang from "lang" ; import { dataSourcePreset } from "synthesizer" ; import { deepCopy } from "utils" ; import { UIWindow } from "types/UIKit" ; import { util as ohmymn } from "addons/ohmymn" ; import { MN } from "const" ; const SettingViewController = JSB . defineClass ( getObjCClassDeclar ( "SettingViewController" , "UITableViewController" ) , settingViewControllerInst ) ; /**
 * MN 的生命周期有点离谱，尤其是先关闭笔记本再关闭文档，
 * 如果直接关闭窗口，是不会触发关闭笔记本和文档的
 * 1. 启用插件
 * 2. 打开窗口
 * 3. 打开笔记本
 * 4. 打开文档
 * 5. 关闭笔记本
 * 6. 关闭文档
 * 7. 关闭窗口
 */ let _window ; const sceneWillConnect = ( ) => { console . log ( "打开窗口" , "lifeCycle" ) ; _window = self . window ; self . panelStatus = false ; self . profile = deepCopy ( profilePreset ) ; self . docProfile = deepCopy ( docProfilePreset ) ; self . profileTemp = deepCopy ( profileTempPreset ) ; self . dataSource = deepCopy ( dataSourcePreset ) ; self . settingViewController = new SettingViewController ( ) ; self . settingViewController . dataSource = self . dataSource ; self . settingViewController . window = self . window ; } ; const sceneDidDisconnect = ( ) => { console . log ( "关闭窗口" , "lifeCycle" ) ; if ( self . docMD5 ) saveProfile ( self . docMD5 ) ; } ; const notebookWillOpen = ( notebookid ) => { console . log ( "打开笔记本" , "lifeCycle" ) ; self . notebookid = notebookid ; eventHandlers . add ( ) ; gestureHandlers . add ( ) ; } ; const notebookWillClose = ( notebookid ) => { console . log ( "关闭笔记本" , "lifeCycle" ) ; closePanel ( ) ; eventHandlers . remove ( ) ; gestureHandlers . remove ( ) ; } ; const documentDidOpen = ( docmd5 ) => { if ( self . docMD5 ) readProfile ( Range . Doc , docmd5 ) ; else { readProfile ( Range . First , docmd5 ) ; UIApplication . sharedApplication ( ) . idleTimerDisabled = self . profile . ohmymn . screenAlwaysOn ; ohmymn . detectUpdate ( ) ; } console . log ( "打开文档" , "lifeCycle" ) ; self . docMD5 = docmd5 ; } ; const documentWillClose = ( docmd5 ) => { console . log ( "关闭文档" , "lifeCycle" ) ; saveProfile ( docmd5 ) ; } ; const addonDidConnect = ( ) => { console . log ( "插件启用" , "lifeCycle" ) ; } ; const addonWillDisconnect = ( ) => { console . log ( "插件停用" , "lifeCycle" ) ; showHUD ( lang . addon_life_cycle . remove , 2 , _window ) ; removeProfile ( ) ; } ; const sceneWillResignActive = ( ) => { console . log ( "应用进入后台" , "lifeCycle" ) ; if ( self . docMD5 ) saveProfile ( self . docMD5 ) ; } ; const sceneDidBecomeActive = ( ) => { layoutViewController ( ) ; console . log ( "应用进入前台" , "lifeCycle" ) ; } ; export const clsMethons = { addonWillDisconnect } ; export default { sceneWillConnect , sceneDidDisconnect , sceneWillResignActive , sceneDidBecomeActive , notebookWillClose , documentWillClose , notebookWillOpen , documentDidOpen } ;