wizardwindow.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /* global $ */
  2. const { remote, ipcRenderer } = require('electron')
  3. const fs = require('fs')
  4. const path = require('path')
  5. const appSettings = remote.require('electron-settings')
  6. const LiveMe = remote.getGlobal('LiveMe')
  7. const DataManager = remote.getGlobal('DataManager')
  8. let currentStage = 1
  9. let lmtExists = false
  10. let lmtkExists = false
  11. let wait = false
  12. let tempvar = { index: 0, max: 0, list: [] }
  13. let TRANSITION_TIME = 200
  14. $(function () {
  15. /**
  16. * LiveMe Tools --> LiveMe Tools/favorites.json
  17. * LiveMe Toolkit --> liveme-toolkit/bookmarks.json
  18. */
  19. if (fs.existsSync(path.join(remote.app.getPath('appData'), 'LiveMeTools', 'favorites.json'))) {
  20. lmtExists = true
  21. }
  22. if (fs.existsSync(path.join(remote.app.getPath('appData'), 'liveme-toolkit', 'bookmarks.json'))) {
  23. lmtkExists = true
  24. }
  25. $('main').show()
  26. $('#stage1').animate({ opacity: 1.0 }, TRANSITION_TIME)
  27. })
  28. function goStage2 () {
  29. $('#stage1').animate({ opacity: 0.0 }, TRANSITION_TIME)
  30. if (lmtExists) {
  31. $('#stage3').animate({ opacity: 1.0 }, TRANSITION_TIME)
  32. } else if (lmtkExists) {
  33. $('#stage4').animate({ opacity: 1.0 }, TRANSITION_TIME)
  34. } else {
  35. $('#stage5').animate({ opacity: 1.0 }, TRANSITION_TIME)
  36. }
  37. }
  38. function goStage4 (i) {
  39. if (i === 1) {
  40. // Import LMT
  41. $('#wait').show()
  42. $('#wait .message').html('Importing Favorites...')
  43. fs.readFile(path.join(remote.app.getPath('appData'), 'LiveMeTools', 'favorites.json'), 'utf8', function (err, data) {
  44. if (err) {
  45. $('#stage3').animate({ opacity: 0.0 }, TRANSITION_TIME)
  46. if (lmtkExists) {
  47. $('#stage4').animate({ opacity: 1.0 }, TRANSITION_TIME)
  48. } else {
  49. $('#stage5').animate({ opacity: 1.0 }, TRANSITION_TIME)
  50. }
  51. } else {
  52. let list = JSON.parse(data)
  53. for (let i = 0; i < list.length; i++) {
  54. let t1 = Math.floor((new Date()).getTime() / 1000) - 86400
  55. let t2 = Math.floor((new Date()).getTime() / 1000) - 604800
  56. let u = {
  57. uid: list[i].uid,
  58. shortid: list[i].short_id,
  59. signature: list[i].usign,
  60. sex: list[i].sex,
  61. face: list[i].face,
  62. nickname: list[i].uname,
  63. counts: {
  64. replays: 0,
  65. friends: 0,
  66. followers: 0,
  67. followings: 0
  68. },
  69. last_viewed: t1,
  70. newest_replay: t2
  71. }
  72. DataManager.addBookmark(u)
  73. }
  74. $('#wait .message').html('Importing Download History...')
  75. fs.readFile(path.join(remote.app.getPath('appData'), 'LiveMeTools', 'downloadHistory.json'), 'utf8', function (err, data) {
  76. if (err) {
  77. $('#wait').hide()
  78. $('#stage3').animate({ opacity: 0.0 }, TRANSITION_TIME)
  79. if (lmtkExists) {
  80. $('#stage4').animate({ opacity: 1.0 }, TRANSITION_TIME)
  81. } else {
  82. $('#stage5').animate({ opacity: 1.0 }, TRANSITION_TIME)
  83. }
  84. } else {
  85. let list = JSON.parse(data)
  86. for (let i = 0; i < list.length; i++) {
  87. DataManager.addWatched(list[i])
  88. DataManager.addDownloaded(list[i])
  89. }
  90. }
  91. $('#wait').hide()
  92. $('#stage3').animate({ opacity: 0.0 }, TRANSITION_TIME)
  93. if (lmtkExists) {
  94. $('#stage4').animate({ opacity: 1.0 }, TRANSITION_TIME)
  95. } else {
  96. $('#stage5').animate({ opacity: 1.0 }, TRANSITION_TIME)
  97. }
  98. })
  99. }
  100. })
  101. } else {
  102. $('#stage3').animate({ opacity: 0.0 }, TRANSITION_TIME)
  103. if (lmtkExists) {
  104. $('#stage4').animate({ opacity: 1.0 }, TRANSITION_TIME)
  105. } else {
  106. $('#stage5').animate({ opacity: 1.0 }, TRANSITION_TIME)
  107. }
  108. }
  109. }
  110. function goStage5 (i) {
  111. if (i === 1) {
  112. // Import LMTK
  113. $('#wait').show()
  114. $('#wait .message').html('Importing Favorites...')
  115. fs.readFile(path.join(remote.app.getPath('appData'), 'liveme-toolkit', 'favorites.json'), 'utf8', function (err, data) {
  116. if (err) {
  117. $('#wait').hide()
  118. $('#stage4').animate({ opacity: 0.0 }, TRANSITION_TIME)
  119. $('#stage5').animate({ opacity: 1.0 }, TRANSITION_TIME)
  120. } else {
  121. let list = JSON.parse(data)
  122. for (let i = 0; i < list.length; i++) {
  123. let t1 = Math.floor((new Date()).getTime() / 1000) - 86400
  124. let t2 = Math.floor((new Date()).getTime() / 1000) - 604800
  125. let u = {
  126. uid: list[i].uid,
  127. shortid: list[i].short_id,
  128. signature: list[i].usign,
  129. sex: list[i].sex,
  130. face: list[i].face,
  131. nickname: list[i].uname,
  132. counts: {
  133. replays: 0,
  134. friends: 0,
  135. followers: 0,
  136. followings: 0
  137. },
  138. last_viewed: t1,
  139. newest_replay: t2
  140. }
  141. DataManager.addBookmark(u)
  142. }
  143. $('#wait .message').html('Importing History...')
  144. fs.readFile(path.join(remote.app.getPath('appData'), 'liveme-toolkit', 'download_history.json'), 'utf8', function (err, data) {
  145. if (err) {
  146. $('#wait').hide()
  147. $('#stage4').animate({ opacity: 0.0 }, TRANSITION_TIME)
  148. $('#stage5').animate({ opacity: 1.0 }, TRANSITION_TIME)
  149. } else {
  150. let list = JSON.parse(data)
  151. for (let i = 0; i < list.length; i++) {
  152. DataManager.addDownloaded(list[i])
  153. DataManager.addWatched(list[i])
  154. }
  155. }
  156. fs.readFile(path.join(remote.app.getPath('appData'), 'liveme-toolkit', 'viewed.json'), 'utf8', function (err, data) {
  157. if (err) {
  158. $('#wait').hide()
  159. $('#stage4').animate({ opacity: 0.0 }, TRANSITION_TIME)
  160. $('#stage5').animate({ opacity: 1.0 }, TRANSITION_TIME)
  161. } else {
  162. let list = JSON.parse(data)
  163. for (let i = 0; i < list.length; i++) {
  164. DataManager.addViewed(list[i][1])
  165. }
  166. }
  167. $('#wait').hide()
  168. $('#stage4').animate({ opacity: 0.0 }, TRANSITION_TIME)
  169. $('#stage5').animate({ opacity: 1.0 }, TRANSITION_TIME)
  170. })
  171. })
  172. }
  173. })
  174. } else {
  175. $('#wait').hide()
  176. $('#stage4').animate({ opacity: 0.0 }, TRANSITION_TIME)
  177. $('#stage5').animate({ opacity: 1.0 }, TRANSITION_TIME)
  178. }
  179. }
  180. function goStage6 () {
  181. $('#stage5').animate({ opacity: 0.0 }, TRANSITION_TIME)
  182. $('#stage6').animate({ opacity: 1.0 }, TRANSITION_TIME)
  183. tempvar.list = DataManager.getAllBookmarks()
  184. tempvar.index = 0
  185. tempvar.max = tempvar.list.length
  186. setTimeout(() => {
  187. processBookmarksThread()
  188. }, TRANSITION_TIME)
  189. }
  190. function processBookmarksThread () {
  191. setTimeout(() => {
  192. if (tempvar.index === tempvar.max) {
  193. DataManager.enableWrites()
  194. DataManager.saveToDisk()
  195. ipcRenderer.send('show-main')
  196. window.close()
  197. } else {
  198. setTimeout(() => processBookmarksThread(), TRANSITION_TIME)
  199. }
  200. $('#progressbar div').css({ width: ((tempvar.index / tempvar.max) * 100) + '%' })
  201. if (tempvar.index < tempvar.max) { tempvar.index++; _updateBookmark(tempvar.index) }
  202. if (tempvar.index < tempvar.max) { tempvar.index++; _updateBookmark(tempvar.index) }
  203. if (tempvar.index < tempvar.max) { tempvar.index++; _updateBookmark(tempvar.index) }
  204. if (tempvar.index < tempvar.max) { tempvar.index++; _updateBookmark(tempvar.index) }
  205. if (tempvar.index < tempvar.max) { tempvar.index++; _updateBookmark(tempvar.index) }
  206. }, 200)
  207. }
  208. function _updateBookmark (i) {
  209. if (tempvar.list[i] === undefined) return
  210. LiveMe.getUserInfo(tempvar.list[i].uid).then(user => {
  211. if (user === undefined) return
  212. let b = DataManager.getSingleBookmark(user.user_info.uid)
  213. b.counts.replays = user.count_info.video_count
  214. b.counts.friends = user.count_info.friends_count
  215. b.counts.followers = user.count_info.follower_count
  216. b.counts.followings = user.count_info.following_count
  217. b.signature = user.user_info.usign
  218. b.sex = user.user_info.sex
  219. b.face = user.user_info.face
  220. b.nickname = user.user_info.uname
  221. b.shortid = user.user_info.short_id
  222. DataManager.updateBookmark(b)
  223. })
  224. }