SceneDelegate.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. //
  2. // SceneDelegate.m
  3. // 唔即云相册
  4. //
  5. // Created by 余衡武 on 2021/12/8.
  6. //
  7. #import "SceneDelegate.h"
  8. #import "HWWebViewController.h"
  9. #import "CalculatorViewController.h"
  10. #import "SetUsePWDViewController.h"
  11. #import "GuideViewController.h"
  12. #import "LoginForViewController.h"
  13. #import "UseAccountManage.h"
  14. #import "PlayerViewController.h"
  15. #import "BaseNavigationController.h"
  16. #import "MySetViewController.h"
  17. @interface SceneDelegate ()<SetUsePWDViewControllerDelegate,GuideViewControllerDelegate,LoginForViewControllerDelegate>
  18. @property(nonatomic, strong) CalculatorViewController *calculatorVC;
  19. @end
  20. @implementation SceneDelegate
  21. - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
  22. if (scene) {
  23. UIWindowScene *windowScene = (UIWindowScene *)scene;
  24. self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
  25. self.window.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
  26. // 初始化数据库
  27. [self initBrowserWindow];
  28. // 加载主页面
  29. [self enterMainVCFromScene];
  30. [self.window makeKeyAndVisible];
  31. }
  32. }
  33. /** 进入登录界面 - 内部使用 */
  34. - (void)enterLoginVCFromScene {
  35. // UIViewController *vc = [[UIViewController alloc] init];
  36. // vc.view.backgroundColor = [UIColor redColor];
  37. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  38. // self.window.rootViewController = nvc;
  39. }
  40. /** 主界面 - 内部使用 */
  41. - (void)enterMainVCFromScene {
  42. // GuideViewController
  43. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  44. if (haveGuide) {
  45. ;
  46. }else {
  47. GuideViewController *guiDeVC = [[GuideViewController alloc] init];
  48. guiDeVC.delegate = self;
  49. self.window.rootViewController = guiDeVC;
  50. return;
  51. }
  52. NSString *launchAppPWDPath = [self documentPathForAccount:@"" fileFolder:@"LaunchPWD"];
  53. NSString *str = [[NSString alloc] initWithContentsOfFile:launchAppPWDPath encoding:(NSUTF8StringEncoding) error:nil];
  54. if (!str || [str isEqualToString:@"0"])
  55. {
  56. SetUsePWDViewController *loginVC = [[SetUsePWDViewController alloc] init];
  57. loginVC.delegate = self;
  58. self.window.rootViewController = loginVC;
  59. return;
  60. }
  61. NSDictionary *data = [[UseAccountManage shareInstance] getLoginInfo];
  62. if (data == nil || ![[data allKeys] containsObject:@"token"]){
  63. /*判断是否有登录 没有登录时提醒登录*/
  64. LoginForViewController *loginVC = [[LoginForViewController alloc] init];
  65. loginVC.delegate = self;
  66. self.window.rootViewController = loginVC;
  67. return;
  68. }
  69. // PlayerViewController *playerRootVC = [[PlayerViewController alloc] init];
  70. // BaseNavigationController *playerNav = [[BaseNavigationController alloc] initWithRootViewController:playerRootVC];
  71. // self.window.rootViewController = playerNav;
  72. // return;
  73. MySetViewController *playerRootVC = [[MySetViewController alloc] init];
  74. BaseNavigationController *playerNav = [[BaseNavigationController alloc] initWithRootViewController:playerRootVC];
  75. self.window.rootViewController = playerNav;
  76. // NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  77. //
  78. // if (dataArray.count == 0) { // 浏览器没有窗口
  79. // // 加载首页
  80. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  81. // vc.webUrl = Const_HomeUrl;
  82. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  83. // self.window.rootViewController = nvc;
  84. //
  85. // }else {
  86. // // 浏览器当前窗口索引ID
  87. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  88. // NSString *where = [NSString stringWithFormat:@"where %@=%ld",bg_sqlKey(@"ID"),(long)ID];
  89. // NSArray* finfAlls = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  90. // BaseModel *model = finfAlls.firstObject;
  91. //
  92. // // 加载网页
  93. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  94. // vc.webUrl = model.webUrl;
  95. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  96. // self.window.rootViewController = nvc;
  97. // }
  98. }
  99. - (void)setPwdOk{
  100. [self enterMainVCFromScene];
  101. // NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  102. //
  103. // if (dataArray.count == 0) { // 浏览器没有窗口
  104. // // 加载首页
  105. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  106. // vc.webUrl = Const_HomeUrl;
  107. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  108. // self.window.rootViewController = nvc;
  109. //
  110. // }else {
  111. // // 浏览器当前窗口索引ID
  112. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  113. // NSString *where = [NSString stringWithFormat:@"where %@=%ld",bg_sqlKey(@"ID"),(long)ID];
  114. // NSArray* finfAlls = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  115. // BaseModel *model = finfAlls.firstObject;
  116. //
  117. // // 加载网页
  118. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  119. // vc.webUrl = model.webUrl;
  120. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  121. // self.window.rootViewController = nvc;
  122. // }
  123. }
  124. /** 登录界面 - 外部使用*/
  125. + (void)enterLoginVC {
  126. // SetPWDViewController *vc = [[SetPWDViewController alloc] init];
  127. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  128. // UIWindow *keyWindow = [iTools getKeyWindow];
  129. // keyWindow.rootViewController = nvc;
  130. }
  131. /** 主界面 - 外部使用 */
  132. + (void)enterMainVC {
  133. // AlbumHomeViewController *vc = [[AlbumHomeViewController alloc] init];
  134. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  135. // UIWindow *keyWindow = [iTools getKeyWindow];
  136. // keyWindow.rootViewController = nvc;
  137. }
  138. - (void)sceneDidDisconnect:(UIScene *)scene {
  139. }
  140. - (void)sceneDidBecomeActive:(UIScene *)scene {
  141. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  142. if (haveGuide) {
  143. ;
  144. }else {
  145. return;
  146. }
  147. [self showCalculatorVC];
  148. }
  149. - (void)sceneWillResignActive:(UIScene *)scene {
  150. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  151. if (haveGuide) {
  152. ;
  153. }else {
  154. return;
  155. }
  156. [self showCalculatorVC];
  157. }
  158. - (void)sceneWillEnterForeground:(UIScene *)scene {
  159. }
  160. - (void)sceneDidEnterBackground:(UIScene *)scene {
  161. BOOL haveGuide = [HWDataManager getBoolWithKey:Const_Have_Show_Guide];
  162. if (haveGuide) {
  163. ;
  164. }else {
  165. return;
  166. }
  167. [self showCalculatorVC];
  168. }
  169. #pragma mark 初始化数据库-DB_BrowserWindows_TableName
  170. - (void)initBrowserWindow {
  171. // 浏览器当前所有窗口
  172. NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  173. // 浏览器当前窗口索引ID
  174. NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  175. NSString *IDValue = [NSString stringWithFormat:@"%ld", ID];
  176. NSString *where = [NSString stringWithFormat:@"where %@=%@",bg_sqlKey(@"ID"),bg_sqlValue(IDValue)];
  177. NSArray *modelArr = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  178. if (dataArray.count == 0) { // 浏览器没有窗口
  179. BaseModel *model = [[BaseModel alloc] init];
  180. model.ID = 0;
  181. model.name = @"主页";
  182. // model.iconFile = imageUrl;
  183. model.webUrl = Const_HomeUrl;
  184. // 写入数据库
  185. model.bg_tableName = DB_BrowserWindows_TableName;
  186. [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  187. HLog(@"BaseModel写入:%@", isSuccess ? @"成功":@"失败");
  188. }];
  189. // 浏览器当前窗口索引ID
  190. [HWDataManager setIntegerWithKey:BrowserWindowsCurrentID value:0];
  191. }else if (modelArr.count == 0) { // 新建窗口
  192. BaseModel *model = [[BaseModel alloc] init];
  193. model.ID = ID;
  194. model.name = @"主页";
  195. // model.iconFile = imageUrl;
  196. model.webUrl = Const_HomeUrl;
  197. // 写入数据库
  198. model.bg_tableName = DB_BrowserWindows_TableName;
  199. [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  200. HLog(@"BaseModel写入:%@", isSuccess ? @"成功":@"失败");
  201. }];
  202. }else { // 更新窗口数据
  203. // 浏览器当前窗口索引ID
  204. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  205. //
  206. // BaseModel *model = [[BaseModel alloc] init];
  207. // model.ID = ID;
  208. // model.name = @"主页";
  209. //// model.iconFile = imageUrl;
  210. // model.webUrl = Const_HomeUrl;
  211. //
  212. // // 更新数据库
  213. // model.bg_tableName = DB_BrowserWindows_TableName;
  214. // [model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
  215. // HLog(@"BaseModel更新: %@", isSuccess ? @"成功":@"失败");
  216. // }];
  217. }
  218. }
  219. #pragma mark 获取当前屏幕的截图
  220. //- (UIImage *)getScreenShotImage {
  221. // CGSize size = [UIScreen mainScreen].bounds.size;
  222. // CGFloat scale = [UIScreen mainScreen].scale;
  223. // UIGraphicsBeginImageContextWithOptions(size, YES, scale);
  224. // [self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
  225. // UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
  226. // UIGraphicsEndImageContext();
  227. // return image;
  228. //}
  229. #pragma mark 计算器伪装视图
  230. /*CalculatorViewController*/
  231. - (void)showCalculatorVC{
  232. NSString *launchAppPWDPath = [self documentPathForAccount:@"" fileFolder:@"LaunchPWD"];
  233. NSString *str = [[NSString alloc] initWithContentsOfFile:launchAppPWDPath encoding:(NSUTF8StringEncoding) error:nil];
  234. if (!str || [str isEqualToString:@""])
  235. {
  236. return;
  237. }
  238. [self closeCalculatorVC];
  239. _calculatorVC = [[CalculatorViewController alloc] init];
  240. _calculatorVC.pwd = str;
  241. [self.window addSubview:_calculatorVC.view];
  242. /*浏览器*/
  243. // _webVC = [[HWWebViewController alloc] init];
  244. // [self.window addSubview:_webVC.view];
  245. }
  246. - (void)closeCalculatorVC{
  247. if (_calculatorVC){
  248. [_calculatorVC.view removeFromSuperview];
  249. }
  250. /*浏览器*/
  251. // if (_webVC){
  252. // [_webVC.view removeFromSuperview];
  253. // }
  254. }
  255. - (NSString *)documentPathForAccount:(NSString *)account fileFolder:(NSString *)fileFolder {
  256. NSString *path = DocumentPath;
  257. if (account.length != 0) {
  258. path = [NSString stringWithFormat:@"%@/%@/",DocumentPath,account];
  259. }
  260. if ([fileFolder containsString:@"/"]) {
  261. NSString *path1 = [path stringByAppendingPathComponent:fileFolder];
  262. path1 = [path1 stringByDeletingLastPathComponent];
  263. NSError *error;
  264. if (![[NSFileManager defaultManager] fileExistsAtPath:path1]) {
  265. [[NSFileManager defaultManager] createDirectoryAtPath:path1 withIntermediateDirectories:YES attributes:nil error:&error];
  266. }
  267. }else{
  268. NSError *error;
  269. if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
  270. [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
  271. }
  272. }
  273. return [path stringByAppendingPathComponent:fileFolder];
  274. }
  275. - (void)startUseBtnBePressed{
  276. [self enterMainVCFromScene];
  277. // NSString *launchAppPWDPath = [self documentPathForAccount:@"" fileFolder:@"LaunchPWD"];
  278. // NSString *str = [[NSString alloc] initWithContentsOfFile:launchAppPWDPath encoding:(NSUTF8StringEncoding) error:nil];
  279. // if (!str || [str isEqualToString:@"0"])
  280. // {
  281. // SetUsePWDViewController *loginVC = [[SetUsePWDViewController alloc] init];
  282. // loginVC.delegate = self;
  283. // self.window.rootViewController = loginVC;
  284. //
  285. // return;
  286. // }
  287. //
  288. // NSArray *dataArray = [BaseModel bg_findAll:DB_BrowserWindows_TableName];
  289. //
  290. // if (dataArray.count == 0) { // 浏览器没有窗口
  291. // // 加载首页
  292. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  293. // vc.webUrl = Const_HomeUrl;
  294. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  295. // self.window.rootViewController = nvc;
  296. //
  297. // }else {
  298. // // 浏览器当前窗口索引ID
  299. // NSInteger ID = [HWDataManager getIntegerWithKey:BrowserWindowsCurrentID];
  300. // NSString *where = [NSString stringWithFormat:@"where %@=%ld",bg_sqlKey(@"ID"),(long)ID];
  301. // NSArray* finfAlls = [BaseModel bg_find:DB_BrowserWindows_TableName where:where];
  302. // BaseModel *model = finfAlls.firstObject;
  303. //
  304. // // 加载网页
  305. // HWWebViewController *vc = [[HWWebViewController alloc] init];
  306. // vc.webUrl = model.webUrl;
  307. // UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
  308. // self.window.rootViewController = nvc;
  309. // }
  310. }
  311. - (void)loginOk{
  312. [self enterMainVCFromScene];
  313. }
  314. @end