milis-plymouth.script 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. /**************************************************************************
  2. *
  3. * Copyright (C) 2011 The Xubuntu Community
  4. * Copyright (C) 2009 Canonical Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * Written by: Mad Nick <dr.madnick@gmail.com>
  20. *
  21. **************************************************************************/
  22. /*
  23. * Related to the screen */
  24. screen_width = Window.GetWidth();
  25. screen_height = Window.GetHeight();
  26. screen_x = Window.GetX();
  27. screen_y = Window.GetY();
  28. /**/
  29. /*
  30. * Images, check bits per pixel
  31. * and load images accordingly */
  32. background_image = Image("wallpaper.png");
  33. passw_dialog_input_image = Image("passw-dialog.png");
  34. bullet_image = Image("test.png");
  35. bpp = Window.GetBitsPerPixel();
  36. if (bpp == 4) {
  37. logotype_image = Image("logo_16bit.png");
  38. progress_meter_image = Image("progress-meter_16bit.png");
  39. progress_fade_image = Image("progress-fade_16bit.png");
  40. fsck_progress_meter_image = Image("progress-meter_16bit.png");
  41. fsck_progress_fade_image = Image("fsck-fade_16bit.png");
  42. }
  43. else {
  44. logotype_image = Image("logo.png");
  45. progress_meter_image = Image("progress-meter.png");
  46. progress_fade_image = Image("progress-fade.png");
  47. fsck_progress_meter_image = Image("progress-meter.png");
  48. fsck_progress_fade_image = Image("fsck-fade.png");
  49. }
  50. /**/
  51. /*
  52. * Sprites */
  53. ratio = screen_height / screen_width;
  54. background_ratio = background_image.GetHeight() / background_image.GetWidth();
  55. factor = 0;
  56. if (ratio > background_ratio) {
  57. factor = screen_height / background_image.GetHeight();
  58. }
  59. else {
  60. factor = screen_width / background_image.GetWidth();
  61. }
  62. scaled = background_image.Scale(background_image.GetWidth() * factor, background_image.GetHeight() * factor);
  63. background_sprite = Sprite(scaled);
  64. background_sprite.SetX(screen_x + screen_width / 2 - scaled.GetWidth() / 2);
  65. background_sprite.SetY(screen_y + screen_height / 2 - scaled.GetHeight() / 2);
  66. logotype_sprite = Sprite(logotype_image);
  67. fsck_progress_meter_sprite = Sprite(fsck_progress_meter_image);
  68. fsck_progress_fade_sprite = Sprite(fsck_progress_fade_image.Scale(1, fsck_progress_fade_image.GetHeight()));
  69. passw_dialog_input_sprite = Sprite(passw_dialog_input_image);
  70. passw_lbl_sprite = Sprite();
  71. msg_label_sprite = Sprite();
  72. /**/
  73. /*
  74. * Misc */
  75. counter = 0;
  76. fade_pos_x = (screen_width / 2) - (progress_meter_image.GetWidth() / 2);
  77. fade_dir = 0; /* 0 = right, 1 = left */
  78. fsck_running = 0;
  79. fsck_dev_array;
  80. fsck_dev_counter = 0;
  81. fsck_fade_in_counter = 0;
  82. fsck_done_fading = 0;
  83. stars_array;
  84. stars_n = 0;
  85. //full_msg = "";
  86. msgs_line = [NULL,NULL,NULL,NULL,NULL];
  87. /**/
  88. /*
  89. * Debug related */
  90. debug = 0;
  91. debug_sprite = Sprite();
  92. fun debugOutput(str) {
  93. /*
  94. * This will print to the top left corner */
  95. debug_sprite.SetImage(Image.Text(str));
  96. }
  97. /**/
  98. /*
  99. * Setup the graphics properties */
  100. logotype_sprite.SetPosition(screen_x + (screen_width / 2) - (logotype_image.GetWidth() / 2), screen_y + (screen_height / 2) - (logotype_image.GetHeight() / 2));
  101. fsck_progress_meter_sprite.SetPosition(screen_x + (screen_width / 2) - (progress_meter_image.GetWidth() / 2), screen_y + (screen_height / 2) + (logotype_image.GetHeight() / 2) + 25);
  102. fsck_progress_fade_sprite.SetPosition(screen_x + (screen_width / 2) - (progress_meter_image.GetWidth() / 2), screen_y + (screen_height / 2) + (logotype_image.GetHeight() / 2) + 25);
  103. fsck_progress_meter_sprite.SetOpacity(0);
  104. fsck_progress_fade_sprite.SetOpacity(0);
  105. passw_dialog_input_sprite.SetPosition(screen_x + (screen_width / 2) - (passw_dialog_input_image.GetWidth() / 2), screen_y + (screen_height / 2) + (logotype_image.GetHeight() / 2) + 70);
  106. passw_dialog_input_sprite.SetOpacity(0);
  107. passw_lbl_sprite.SetOpacity(0);
  108. spin = 0;
  109. /*
  110. * this function only goes up to 100
  111. * because thats all thats needed for
  112. * the progress meter bar */
  113. fun atoi(str) {
  114. int = -1;
  115. for (i = 0; i <= 100; i++) {
  116. if (i + "" == str) {
  117. int = i;
  118. break;
  119. }
  120. }
  121. return int;
  122. }
  123. /*
  124. * This handler will/can be invoked
  125. * 50 times per second.
  126. *
  127. * According to the previous author of the
  128. * splash script, without this callback
  129. * the screen is not updated correctly */
  130. spinner_sprite;
  131. spinner;
  132. fun refreshHandler() {
  133. if (spin < 3.14 * 2) {
  134. spin = spin + 0.1;
  135. }
  136. else {
  137. spin = 0;
  138. }
  139. /* if fsck is running or the password is prompted, hide the spinner */
  140. if (fsck_running == 1 || passw_dialog_input_sprite.GetOpacity() == 1) {
  141. spinner_sprite.SetOpacity(0);
  142. } else {
  143. spinner = Image("spinner.png");
  144. spinner = spinner.Rotate(spin);
  145. spinner_sprite = Sprite(spinner);
  146. spinner_sprite.SetPosition(screen_x + (screen_width / 2) - (spinner.GetWidth() / 2), screen_y + (screen_height / 2) - (spinner.GetHeight() / 2) + 80);
  147. }
  148. if (fade_dir == 0) {
  149. counter++;
  150. if (counter >= 200) {
  151. fade_dir = 1;
  152. }
  153. }
  154. else {
  155. counter--;
  156. if (counter <= 0) {
  157. fade_dir = 0;
  158. }
  159. }
  160. if ((fsck_running == 1) && (fsck_done_fading == 0)) {
  161. fsck_progress_meter_sprite.SetOpacity(fsck_fade_in_counter);
  162. fsck_progress_fade_sprite.SetOpacity(fsck_fade_in_counter);
  163. if (fsck_fade_in_counter < 1) {
  164. fsck_fade_in_counter+= 0.025;
  165. }
  166. else {
  167. fsck_done_fading = 1;
  168. }
  169. }
  170. }
  171. Plymouth.SetRefreshFunction (refreshHandler);
  172. /**/
  173. /*
  174. * This function will display the password related information
  175. * when being prompt with entering a password */
  176. fun showPasswordHandler(prompt, stars) {
  177. if (passw_dialog_input_sprite.GetOpacity() == 0 && passw_lbl_sprite.GetOpacity() == 0) {
  178. passw_dialog_input_sprite.SetOpacity(1);
  179. passw_lbl_sprite.SetOpacity(1);
  180. }
  181. tmp_prompt_image = Image.Text(prompt, 1, 1, 1);
  182. passw_lbl_sprite.SetImage(tmp_prompt_image);
  183. passw_lbl_sprite.SetPosition(screen_x + (screen_width / 2) - (tmp_prompt_image.GetWidth() / 2), screen_y + (screen_height / 2) + (logotype_image.GetHeight() / 2) + 50);
  184. for(i = 0; i < stars_n; i++) {
  185. stars_array[i] = NULL;
  186. }
  187. stars_n = 0;
  188. for(i = 0; (i < stars) && (i < 15); i++) {
  189. stars_array[i] = Sprite(bullet_image);
  190. stars_array[i].SetPosition(screen_x + (((screen_width / 2) - (passw_dialog_input_image.GetWidth() / 2)) + (18 * i)) + 2, screen_y + (screen_height / 2) + (logotype_image.GetHeight() / 2) + 75);
  191. stars_n++;
  192. }
  193. }
  194. Plymouth.SetDisplayPasswordFunction(showPasswordHandler);
  195. /**/
  196. fun displayNormalHandler() {
  197. /*
  198. * Hide the password dialog and the bullets */
  199. if (passw_dialog_input_sprite.GetOpacity() == 1) {
  200. passw_dialog_input_sprite.SetOpacity(0);
  201. }
  202. if (passw_lbl_sprite.GetOpacity() == 1) {
  203. passw_lbl_sprite.SetOpacity(0);
  204. }
  205. for(i = 0; i < stars_n; i++) {
  206. stars_array[i] = NULL;
  207. }
  208. }
  209. Plymouth.SetDisplayNormalFunction(displayNormalHandler);
  210. fun strlen(string) {
  211. i = 0;
  212. while (String(string).CharAt(i)) {
  213. i++;
  214. }
  215. return i;
  216. }
  217. /*
  218. * This function will display the most current message */
  219. fun messageHandler(msg) {
  220. if ((msg == "") || !msg) {
  221. return 0;
  222. }
  223. if (msg.SubString(0, 5) == "keys:") {
  224. msg = msg.SubString(5, strlen(msg));
  225. }
  226. # Get the message without the "fsckd-cancel-msg" prefix as we don't support i18n
  227. if (msg.SubString(0, 17) == "fsckd-cancel-msg:")
  228. msg = msg.SubString(17, strlen(msg));
  229. //full_msg += msg + " ";
  230. for(i = 4; i > 0; i--) {
  231. msgs_line[i] = msgs_line[i - 1];
  232. }
  233. msgs_line[0] = Sprite(Image.Text(msg, 1, 1, 1));
  234. dist = 1;
  235. for(i = 0; i < 5; i++) {
  236. if (msgs_line[i] != NULL) {
  237. msgs_line[i].SetPosition(screen_x + (screen_width / 2) - (msgs_line[i].GetImage().GetWidth() / 2), screen_y + (screen_height - msgs_line[i].GetImage().GetHeight()) - 20*dist);
  238. dist++;
  239. }
  240. }
  241. }
  242. Plymouth.SetMessageFunction(messageHandler);
  243. /**/
  244. /*
  245. * Handles the updates passed to the plymouth daemon
  246. * for example the FSCK data */
  247. fun statusHandler(status) {
  248. tmp_char;
  249. status_array[0] = "";
  250. elem_count = 0;
  251. for (i = 0; String(status).CharAt(i) != ""; i++) {
  252. tmp_char = String(status).CharAt(i);
  253. if (tmp_char != ":") {
  254. status_array[elem_count] += tmp_char;
  255. }
  256. else {
  257. elem_count++;
  258. status_array[elem_count] = "";
  259. }
  260. }
  261. if (status_array[0] == "fsck") {
  262. already_added = 0;
  263. if (fsck_running == 0) {
  264. /*
  265. * use the dedicated message handler for this
  266. * since there is no messages about fsck checks
  267. * currently... */
  268. messageHandler("Routine disk drive check.");
  269. fsck_running = 1;
  270. }
  271. for(i = 0; i < fsck_dev_counter; i++) {
  272. /*
  273. * check if the device already exist and update
  274. * the progress only in that case */
  275. if (fsck_dev_array[i][0] == status_array[1]) {
  276. fsck_dev_array[i][1] = status_array[2]; /* progress */
  277. already_added = 1;
  278. }
  279. }
  280. /*
  281. * if the device is not added, then add it */
  282. if (already_added == 0) {
  283. fsck_dev_array[fsck_dev_counter][0] = status_array[1]; /* device */
  284. fsck_dev_array[fsck_dev_counter][1] = status_array[2]; /* progress */
  285. fsck_dev_counter++;
  286. }
  287. /*
  288. * update the progress */
  289. total = 0;
  290. for(i = 0; i < fsck_dev_counter; i++) {
  291. total += atoi(fsck_dev_array[i][1]);
  292. }
  293. if (fsck_dev_counter > 0) {
  294. /*
  295. * display the total percentage */
  296. fsck_progress_fade_sprite.SetImage(fsck_progress_fade_image.Scale((fsck_progress_meter_image.GetWidth() / 100) * (total / fsck_dev_counter), fsck_progress_fade_image.GetHeight()));
  297. }
  298. /**/
  299. /*
  300. * if the total progress is at maximum,
  301. * make the progress meter go away,
  302. * we might want to fade this out... */
  303. if (total == (100 * fsck_dev_counter)) {
  304. fsck_progress_meter_sprite.SetOpacity(0);
  305. fsck_progress_fade_sprite.SetOpacity(0);
  306. }
  307. }
  308. # systemd-fsckd pass fsckd:<number_devices>:<progress>:<l10n_string>
  309. if (status_array[0] == "fsckd") {
  310. fsck_running = 1;
  311. # remove ",x" as we only care about integers
  312. progress_str = status_array[2];
  313. progress = atoi(progress_str.SubString(0, strlen(progress_str) - 2));
  314. fsck_progress_fade_sprite.SetImage(fsck_progress_fade_image.Scale((fsck_progress_meter_image.GetWidth() / 100) * progress, fsck_progress_fade_image.GetHeight()));
  315. /*
  316. * if the total progress is at maximum,
  317. * make the progress meter go away,
  318. * we might want to fade this out... */
  319. if (progress == 100) {
  320. fsck_progress_meter_sprite.SetOpacity(0);
  321. fsck_progress_fade_sprite.SetOpacity(0);
  322. }
  323. }
  324. }
  325. Plymouth.SetUpdateStatusFunction(statusHandler);
  326. /**/