Author Topic: FireFox Management App for Windows  (Read 4327 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
FireFox Management App for Windows
« on: December 09, 2018, 04:54:17 pm »
When I got upgraded to Firefox Quantum, I noticed my session tab manager was no longer supported. It seems updates can rip away some of our favorite things. Dammit, I must be channeling Oprah again.

Anyway, I decided I wanted to lean some new tricks and make an app I could use to manage Firefox. This is a work in progress and it uses some keywords that are only supported in Windows, and Windows API calls. It will not work properly in Linux or Mac.

Since the days of easily finding and reading urls from the temporary internet files folder in earlier editions of Windows is long gone, I decided to take advantage of _SCREENCLICK and _SCREENPRINT to find and read urls displayed in the browser. It can save them to a file, so sessions can be named and reloaded.

WARNING: It works for me, but be aware it makes single clicks to your screen. That should be OK if the browser is covering your screen, and OK if it isn't, provided you don't have your system set to activate things on a single click. My desktop is default, two clicks to activate a program.

The program makes session files with .ses extension. You can drag them to Notepad to read them.

The program makes a settings file called session-manager-settings.dat upon RUN.

It uses Bing.com so a window title can be found by the API. You could make a local html file and title it to fit the program. That would load faster. I may get around to that sometime.

You will need to map "Close" and "Load Previous Session" to take advantage of those two features. You can click either and the program will take you to the settings screen, so you can map them. Basically all that involves is choosing "close" or "Load Previous Session" and the program will make an image of the browser and prompt you to click, say the Close tab, on that image. It will record and save the coordinates. If you go "Back" to the menu, you can click "Close" and the program will click the X button on the browser.

Anyway, it's a work in progress, but I've run out of time and need to get busy on other projects, so this may be as far as I get for awhile.

Code: QB64: [Select]
  1. REDIM SHARED tabx(1000) AS INTEGER, taby(1000) AS INTEGER
  2. REDIM SHARED settings$(100), session$(100)
  3. REDIM SHARED title$, findbrowsertitle$, numofspaces%, inputindex, inputcount, word$(1000), crow%, ccol%
  4. REDIM SHARED scindent%, srindent%, fw%, fh%, cwidth%, rheight%, num%, p1%, p2%, p3%, p4%, fileextension$
  5. REDIM SHARED maxwinheight%, mintopindent%, browsertab$, hwnd%&, ClassName, WindowName$, nVirtKey, nCmdShow
  6.  
  7.     FUNCTION FindWindowA%& (BYVAL ClassName AS _OFFSET, WindowName$) 'find process handle by title
  8.     FUNCTION GetKeyState% (BYVAL nVirtKey AS LONG) 'Windows virtual key presses
  9.     FUNCTION ShowWindow& (BYVAL hwnd AS _OFFSET, BYVAL nCmdShow AS LONG) 'maximize process
  10.     FUNCTION GetForegroundWindow%& 'find currently focused process handle
  11.     FUNCTION SetForegroundWindow& (BYVAL hwnd AS _OFFSET) 'set foreground window process(focus)
  12.  
  13. title$ = "FireFox Session Manager" 'Title of program window
  14. _TITLE title$ 'Set program title
  15. findbrowsertitle$ = "Bing - mozilla firefox"
  16. browsertab$ = "bing.com"
  17. fileextension$ = ".ses"
  18. numofspaces% = 60
  19. scindent% = 10 ' To be centered to screen.
  20. mintopindent% = 5 ' Minimum rows indented from the top needed to see clickable areas above.
  21. maxwinheight% = _DESKTOPHEIGHT \ _FONTHEIGHT - mintopindent%
  22.  
  23. IF maxwinheight% > 42 THEN
  24.     maxwinheight% = 42
  25.     rheight% = 42 - 4 ' Last width that supports font size 16 height.
  26.     rheight% = maxwinheight% - 4 ' -4 is to keep window bottom above taskbar.
  27.  
  28. CALL setscreen
  29.  
  30. IF _FILEEXISTS("session-manager-settings.dat") THEN
  31.     RESTORE settingslist
  32.     REDIM settings$(100)
  33.     OPEN "session-manager-settings.dat" FOR OUTPUT AS #2
  34.     i = 0
  35.     DO
  36.         READ a$
  37.         IF LCASE$(a$) = "eof" THEN EXIT DO
  38.         i = i + 1
  39.         settings$(i) = a$ + "," + "(Undefined)"
  40.         PRINT #2, settings$(i)
  41.     LOOP
  42.     CLOSE #2
  43.  
  44. RESTORE tasklist
  45. i = 0
  46. crow% = 9
  47.     READ a$, action$
  48.     IF LCASE$(a$) = "eof" THEN EXIT DO
  49.     a$ = LTRIM$(STR$(i)) + ") " + a$
  50.     IF w4 < LEN(a$) THEN w4 = LEN(a$)
  51. ccol% = cwidth% \ 2 - w4 \ 2
  52. w3 = 0
  53. w4 = w4 + 2 ' margin buffer for menu box.
  54. heading$ = "FireFox Session Menu"
  55. LOCATE crow% - 2, ccol% + (w4 - 2) \ 2 - LEN(heading$) \ 2
  56. PRINT heading$;
  57. LOCATE crow%, ccol%
  58. RESTORE tasklist
  59.     READ a$, action$
  60.     IF LCASE$(a$) = "eof" THEN EXIT DO
  61.     w3 = w3 + 1
  62.     a$ = LTRIM$(STR$(w3)) + ") " + a$
  63.     PRINT a$;
  64.     LOCATE crow% + w3, ccol%
  65. p1% = ccol%: p2% = ccol% + w4: p3% = crow%: p4% = crow% + w3 ' selection parameters
  66.  
  67. CALL box(w3, w4)
  68.  
  69. CALL selection(w3, b$)
  70.  
  71. RESTORE tasklist
  72. FOR i = 1 TO VAL(b$)
  73.     READ a$, action$
  74.     a$ = LTRIM$(STR$(i)) + ") " + a$
  75.  
  76. CALL highlight(a$, b$)
  77.  
  78.     CASE 1 ' Firefox Full Screen
  79.         CALL startbrowser
  80.         RUN
  81.     CASE 2 ' Firefox minimized
  82.         CALL startbrowser
  83.         _DELAY .1
  84.         CALL minimizewindow
  85.         RUN
  86.     CASE 3
  87.         task$ = "load previous session" ' Load Previous Session.
  88.         CALL taskactions(task$, flag)
  89.         IF flag THEN flag = 0: CALL makesettings
  90.         RUN
  91.     CASE 4
  92.         SHELL _HIDE "dir /b *." + fileextension$ + ">tmp.tmp"
  93.         OPEN "tmp.tmp" FOR INPUT AS #1
  94.         w3 = 0: REDIM session$(100)
  95.         DO UNTIL EOF(1)
  96.             LINE INPUT #1, a$
  97.             IF INSTR(a$, fileextension$) <> 0 THEN ' Strip off file extension.
  98.                 a$ = RTRIM$(MID$(a$, 1, INSTR(a$, fileextension$) - 1))
  99.             END IF
  100.             w3 = w3 + 1
  101.             session$(w3) = a$
  102.         LOOP
  103.         CLOSE #1
  104.         w4 = 0
  105.         IF w3 > 1 THEN ' More than one saved session in database.
  106.             FOR j = 1 TO w3
  107.                 IF LEN(session$(j)) > w4 THEN w4 = LEN(session$(j))
  108.             NEXT
  109.             crow% = 10
  110.             ccol% = cwidth% \ 2 - w4 \ 2
  111.             p1% = ccol%: p2% = ccol% + w4: p3% = crow%: p4% = crow% + w3 ' selection parameters
  112.             w4 = w4 + 2 ' margin buffer for menu box.
  113.             CLS
  114.             LOCATE crow%, ccol%
  115.             FOR j = 1 TO w3
  116.                 PRINT session$(j)
  117.                 LOCATE , ccol%
  118.             NEXT
  119.             heading$ = "Click to Load Session"
  120.             LOCATE crow% - 3, ccol% + (w4 - 2) \ 2 - LEN(heading$) \ 2
  121.             PRINT heading$;
  122.             heading$ = "Back  |  Quit"
  123.             LOCATE crow% - 2, ccol% + (w4 - 2) \ 2 - LEN(heading$) \ 2
  124.             COLOR 3, 0
  125.             PRINT heading$;
  126.             COLOR 7, 0
  127.             LOCATE crow%, ccol%
  128.  
  129.             CALL box(w3, w4)
  130.  
  131.             DO
  132.                 CALL selection(w3, b$)
  133.  
  134.                 IF b$ = "run" THEN RUN
  135.                 IF b$ = "esc" THEN SYSTEM
  136.                 IF VAL(b$) > 0 THEN EXIT DO
  137.             LOOP
  138.             a$ = session$(VAL(b$))
  139.  
  140.             CALL highlight(a$, b$)
  141.  
  142.         ELSE
  143.             b$ = "1" ' Only one selection.
  144.         END IF
  145.  
  146.         OPEN session$(VAL(b$)) + fileextension$ FOR INPUT AS #1
  147.         DO UNTIL EOF(1)
  148.             LINE INPUT #1, a$
  149.             SHELL _HIDE "firefox.exe " + a$
  150.             _DELAY .2
  151.         LOOP
  152.         _DELAY 2
  153.         RUN
  154.     CASE 5
  155.         task$ = "session"
  156.         CALL mapping(task$)
  157.         _DELAY 3
  158.         RUN
  159.     CASE 6
  160.         task$ = "close"
  161.         CALL taskactions(task$, flag)
  162.         IF flag THEN flag = 0: CALL makesettings
  163.         RUN
  164.     CASE 7
  165.         CALL makesettings
  166.         RUN
  167.     CASE 8
  168.         SYSTEM
  169.  
  170. tasklist:
  171. DATA FireFox Full Screen,Starting FireFox...
  172. DATA FireFox Minimized,Starting FireFox Minimized...
  173. DATA FireFox Load Previous Session,Starting Firefox Last Session...
  174. DATA Load a Saved Session,Loading Session Menu...
  175. DATA Map a New Session,Map a New Session...
  176. DATA Close Firefox,Close Firefox...
  177. DATA Settings,Go to Settings...
  178. DATA Quit,Quit
  179.  
  180. programcommands:
  181. DATA back,run
  182. DATA quit,esc
  183.  
  184. settingslist:
  185. DATA Load Previous Session
  186.  
  187. SUB mouse (x%, y%, mb%, rb%)
  188. x% = _MOUSEX
  189. y% = _MOUSEY
  190. mb% = _MOUSEBUTTON(1)
  191. rb% = _MOUSEBUTTON(2)
  192.  
  193. SUB mapping (task$)
  194. hwnd%& = FindWindowA(0, title$ + CHR$(0)) 'find this program's process handle
  195. oldx% = -1: w = 0: v = 0: num% = 0
  196.     IF oldx% <> x% OR oldy% <> y% THEN
  197.         IF dispon% = 0 THEN
  198.             CLS
  199.  
  200.             CALL startbrowser
  201.  
  202.             CALL focusapp
  203.  
  204.             IF task$ = "session" THEN
  205.                 LOCATE crow%, ccol%
  206.                 PRINT "Open all websites you want"
  207.                 LOCATE , ccol%
  208.                 PRINT "saved in this session."
  209.                 PRINT
  210.                 LOCATE , ccol%
  211.                 PRINT "Click the taskbar icon to"
  212.                 LOCATE , ccol%
  213.                 PRINT "record and save session..."
  214.  
  215.                 DO
  216.                     _LIMIT 30
  217.                     FGwin%& = GetForegroundWindow%&
  218.                     CALL mouse(x%, y%, mb%, rb%)
  219.                     IF mb% THEN EXIT DO
  220.                     b$ = INKEY$
  221.                     IF b$ = CHR$(27) THEN SYSTEM
  222.                     IF b$ <> "" THEN EXIT DO
  223.                     IF FGwin%& <> hwnd%& THEN EXIT DO ' Exit when Firefox is clicked.
  224.                 LOOP
  225.                 'Minimize here.
  226.                 CALL minimizewindow
  227.                 _DELAY 1
  228.                 CLS
  229.                 LOCATE crow% + 1, ccol%
  230.                 PRINT "Working..."
  231.                 DO
  232.                     _LIMIT 30
  233.                     FGwin%& = GetForegroundWindow%&
  234.                     _DELAY 1
  235.                     IF FGwin%& = hwnd%& THEN EXIT DO ' Exit when program window is restored from task bar.
  236.                 LOOP
  237.                 CALL restorewindow
  238.             END IF
  239.  
  240.             CLS
  241.             _DELAY .1
  242.             z& = SetForegroundWindow&(hwnd%&) 'set focus
  243.  
  244.             GOSUB putimage
  245.  
  246.             LOCATE crow% + 1, ccol%
  247.  
  248.             SELECT CASE task$
  249.                 CASE "session"
  250.                     PRINT "Left click the tabs you want saved in this session."
  251.                     PRINT: LOCATE , ccol%
  252.                     PRINT "Right click anywhere when finished..."
  253.                 CASE "close"
  254.                     PRINT "Left click the [X] Close symbol in Firefox."
  255.                 CASE "load previous session"
  256.                     SELECT CASE num%
  257.                         CASE 0
  258.                             PRINT "Click browser: " + CHR$(34) + "History" + CHR$(34)
  259.                             PRINT
  260.                         CASE 1
  261.                             LOCATE , ccol%
  262.                             PRINT "Click: " + CHR$(34) + "Restore Previous Session"
  263.                     END SELECT
  264.             END SELECT
  265.         END IF
  266.         LOCATE crow% + 6, ccol%
  267.         PRINT "Row ="; y%; "   "; "Column ="; x%; "   ";
  268.         oldx% = x%: oldy% = y%
  269.     END IF
  270.     x% = _MOUSEX
  271.     y% = _MOUSEY
  272.     mb% = _MOUSEBUTTON(1)
  273.     rb% = _MOUSEBUTTON(2)
  274.     IF mb% THEN
  275.         mb% = 0
  276.         'PRINT "Confirmed: Row ="; y%; "   Column ="; x%,
  277.         num% = num% + 1
  278.         tabx(num%) = x%
  279.         taby(num%) = y%
  280.         DO: i = _MOUSEINPUT: LOOP UNTIL _MOUSEBUTTON(1) = 0
  281.         SELECT CASE task$
  282.             CASE "close"
  283.                 EXIT SUB
  284.             CASE "load previous session"
  285.                 CALL minimizewindow
  286.                 _DELAY .1
  287.                 _SCREENCLICK x%, y%
  288.                 _DELAY .25
  289.                 GOSUB putimage
  290.                 _DELAY .25
  291.                 CALL restorewindow
  292.                 LOCATE 10, 75
  293.                 FOR i = 1 TO 3
  294.                     LOCATE , 75
  295.                     PRINT SPACE$(40)
  296.                 NEXT
  297.                 LOCATE 11, 75
  298.                 PRINT " Click " + CHR$(34) + "Restore Previous Session" + CHR$(34)
  299.                 DO
  300.                     CALL mouse(x%, y%, mb%, rb%)
  301.                     IF mb% THEN EXIT DO
  302.                 LOOP
  303.                 num% = num% + 1
  304.                 tabx(num%) = x%
  305.                 taby(num%) = y%
  306.                 CALL setscreen
  307.                 EXIT SUB
  308.         END SELECT
  309.     ELSE
  310.         IF rb% AND task$ = "session" THEN
  311.             _SCREENHIDE
  312.             SCREEN 0
  313.             WIDTH cwidth%, rheight%
  314.             _SCREENMOVE scindent% * fw%, srindent% * fh%
  315.             CLS
  316.             _DELAY .25
  317.             REDIM url$(num%)
  318.             FOR i = 1 TO num%
  319.                 _SCREENCLICK tabx(i), taby(i)
  320.                 _DELAY .25
  321.                 _SCREENCLICK 700, 80 ' Firefox URL input field.
  322.                 _DELAY .1
  323.                 _SCREENPRINT CHR$(1) ' Select the URL.
  324.                 _DELAY .1
  325.                 _SCREENPRINT CHR$(3) ' Copy the URL.
  326.                 _DELAY .25
  327.                 url$(i) = _CLIPBOARD$
  328.             NEXT
  329.             _SCREENSHOW
  330.             _DELAY .1
  331.             sdate$ = MID$(DATE$, 7, 4) + "-" + MID$(DATE$, 1, 2) + "-" + MID$(DATE$, 4, 2)
  332.             LOCATE 2, 2
  333.             PRINT "Name and Save this Session as: "; sdate$ + ": ";
  334.             yy% = CSRLIN: xx% = POS(0)
  335.             COLOR 0, 7
  336.             LOCATE , xx% - 1
  337.             PRINT SPACE$(60 + 2);
  338.             COLOR 7, 0
  339.             LOCATE yy%, xx%
  340.             PRINT
  341.             _DELAY .25
  342.             PRINT
  343.             FOR i = 1 TO num%
  344.                 LOCATE , 2
  345.                 PRINT LTRIM$(STR$(i)); ") "; MID$(url$(i), 1, cwidth% - 5)
  346.             NEXT
  347.             LOCATE yy%, xx%
  348.  
  349.             z& = SetForegroundWindow&(hwnd%&) 'Set focus for key input.
  350.  
  351.             CALL keyinput(word$, b$, flag)
  352.  
  353.             CALL savefile(word$, sdate$, url$())
  354.  
  355.             EXIT SUB
  356.         END IF
  357.     END IF
  358.  
  359. putimage:
  360. _SCREENMOVE 0, -25 ' Hides title bar above computer top screen margin.
  361. _PUTIMAGE (0, 0), img&
  362. dispon% = -1
  363.  
  364. SUB keyinput (word$, b$, flag)
  365. startpos% = POS(1) - LEN(word$)
  366. endpos% = startpos% + numofspaces%
  367.  
  368.     COLOR 7, 0
  369.     xx% = CSRLIN: yy% = POS(1)
  370.     LOCATE 1, 1
  371.     DO
  372.         ii = ii + 1
  373.         IF word$(ii) = "" THEN EXIT DO
  374.         PRINT ii; word$(ii)
  375.     LOOP
  376.     COLOR 0, 7
  377.     LOCATE xx%, yy%, 1, 7, 7
  378.     ii = 0
  379.     DO
  380.         b$ = INKEY$
  381.         IF b$ <> "" THEN EXIT DO
  382.     LOOP
  383.     xx% = CSRLIN: yy% = POS(1)
  384.  
  385.     SELECT CASE b$
  386.         CASE CHR$(0) + "H"
  387.             REM DOS-KEY-LIKE REPLACE INPUT
  388.             IF inputindex > 0 THEN
  389.                 IF word$ = "" THEN
  390.                     inputindex = inputindex - 1: word$ = word$(inputindex)
  391.                 ELSE
  392.                     word$ = word$(inputindex): inputindex = inputindex - 1
  393.                 END IF
  394.                 flag = -1
  395.                 EXIT SUB
  396.             END IF
  397.         CASE CHR$(0) + "K"
  398.             mov% = -1: GOSUB action
  399.         CASE CHR$(0) + "M"
  400.             mov% = 1: GOSUB action
  401.         CASE CHR$(0) + "S"
  402.             GOSUB wash: GOSUB delete
  403.         CASE CHR$(0) + "R"
  404.             IF ins% = 0 THEN ins% = -1 ELSE ins% = 0
  405.             IF ins% = 0 THEN LOCATE , , 1, 7, 7 ELSE LOCATE , , 1, 7, 30
  406.         CASE CHR$(0) + "O"
  407.             IF word$ <> "" THEN LOCATE xx%, startpos% + LEN(word$)
  408.         CASE CHR$(0) + "G"
  409.             LOCATE xx%, startpos%
  410.         CASE CHR$(8)
  411.             IF yy% > startpos% THEN
  412.                 LOCATE , POS(1) - 1
  413.                 yy% = POS(1)
  414.                 GOSUB wash: GOSUB delete
  415.             END IF
  416.         CASE CHR$(13)
  417.             COLOR 7, 0
  418.             LOCATE , , 1, 7, 0
  419.             EXIT SUB
  420.         CASE CHR$(27)
  421.             COLOR 7, 0: SYSTEM
  422.         CASE CHR$(32) TO CHR$(126)
  423.             key$ = b$: GOSUB action
  424.     END SELECT
  425.     mov% = 0: key$ = ""
  426.  
  427. action:
  428. IF POS(1) + mov% >= startpos% AND POS(1) + mov% < endpos% THEN
  429.     DO
  430.         IF key$ <> "" THEN
  431.             SELECT CASE ins%
  432.                 CASE 0
  433.                     IF LEN(word$) + LEN(key$) > endpos% - startpos% THEN EXIT DO
  434.                     word$ = MID$(word$, 1, POS(1) - startpos%) + key$ + MID$(word$, POS(1) - startpos% + 1)
  435.                 CASE -1
  436.                     word$ = MID$(word$, 1, POS(1) - startpos%) + key$ + MID$(word$, POS(1) - startpos% + 2)
  437.             END SELECT
  438.         END IF
  439.         IF POS(1) - startpos% >= LEN(word$) - LEN(key$) AND key$ <> "" OR key$ = "" OR ins% = -1 THEN
  440.             IF key$ = "" AND mov% = 1 THEN IF POS(1) - startpos% = LEN(word$) THEN EXIT DO
  441.             LOCATE , POS(1) + mov%: PRINT key$;
  442.         ELSE
  443.             LOCATE xx%, startpos%: PRINT MID$(word$, 1, yy% - startpos%); key$;: yy2% = POS(1): PRINT MID$(word$, yy% - startpos% + 2);: LOCATE xx%, yy2%
  444.         END IF
  445.         EXIT DO
  446.     LOOP
  447.  
  448. wash:
  449. IF POS(1) >= startpos% AND word$ <> "" AND POS(1) - startpos% < LEN(word$) THEN
  450.     LOCATE xx%, startpos% + LEN(word$) - 1
  451.     PRINT " ";
  452.     LOCATE xx%, yy%
  453.  
  454. delete:
  455. IF POS(1) - startpos% = 0 THEN
  456.     word$ = MID$(word$, 2)
  457.     word$ = MID$(word$, 1, POS(1) - startpos%) + MID$(word$, POS(1) - startpos% + 2)
  458. PRINT MID$(word$, yy% - startpos% + 1);: LOCATE xx%, yy%
  459.  
  460. SUB savefile (word$, sdate$, url$())
  461. OPEN sdate$ + " " + word$ + fileextension$ FOR OUTPUT AS #2
  462. FOR i = 1 TO num%
  463.     PRINT #2, url$(i)
  464.  
  465. SUB savesettings (b$)
  466. OPEN "session-manager-settings.dat" FOR OUTPUT AS #2
  467. i = 0
  468.     i = i + 1
  469.     IF settings$(i) = "" OR i = 100 THEN EXIT DO
  470.     IF INSTR(settings$(i), ")") THEN
  471.         settings$(i) = LTRIM$(MID$(settings$(i), INSTR(settings$(i), ")") + 1)) ' Strip off any number.
  472.     END IF
  473.     PRINT #2, settings$(i)
  474.  
  475. SUB box (w3, w4)
  476. LOCATE crow% - 1, ccol% - 2: PRINT CHR$(218);: PRINT STRING$(w4, 196) + CHR$(191)
  477. FOR j = 1 TO w3
  478.     LOCATE , ccol% - 2
  479.     PRINT CHR$(179);
  480.     LOCATE , ccol% + w4 - 1: PRINT CHR$(179)
  481. LOCATE , ccol% - 2: PRINT CHR$(192) + STRING$(w4, 196) + CHR$(217)
  482.  
  483. SUB selection (w3, b$)
  484. b$ = ""
  485.     _LIMIT 30
  486.     CALL mouse(x%, y%, mb%, rb%)
  487.     IF mb% THEN
  488.         IF p1% <= x% AND p2% >= x% AND p3% <= y% AND p4% >= y% THEN
  489.             b$ = CHR$(49 + y% - crow%)
  490.         END IF
  491.         IF VAL(b$) = 0 THEN ' Check for program choices above menu items.
  492.             cmd$ = CHR$(SCREEN(y%, x%))
  493.             IF LTRIM$(cmd$) = "" THEN
  494.                 IF x% > 1 THEN cmd$ = CHR$(SCREEN(y%, x% - 1)) + cmd$ ' Look left
  495.                 IF x% < cwidth% THEN cmd$ = cmd$ + CHR$(SCREEN(y%, x% + 1)) ' Look right
  496.                 cmd$ = RTRIM$(LTRIM$(cmd$))
  497.                 IF LEN(cmd$) <> 3 THEN cmd$ = "" ' Not in middle of a word."
  498.             END IF
  499.             IF cmd$ <> "" THEN
  500.                 cmd$ = ""
  501.                 FOR i = x% TO 1 STEP -1
  502.                     cmd$ = CHR$(SCREEN(y%, i)) + cmd$
  503.                     IF INSTR(cmd$, SPACE$(2)) THEN EXIT FOR ' IMPORTANT Only allows 1-space between clickable words.
  504.                 NEXT
  505.                 cmd$ = LTRIM$(cmd$)
  506.                 IF cmd$ = "" THEN j = 0 ELSE j = 1
  507.                 FOR i = x% + j TO cwidth%
  508.                     cmd$ = cmd$ + CHR$(SCREEN(y%, i))
  509.                     IF INSTR(cmd$, SPACE$(2)) THEN EXIT FOR
  510.                 NEXT
  511.                 cmd$ = LTRIM$(RTRIM$(LCASE$(cmd$)))
  512.             END IF
  513.             IF cmd$ <> "" THEN
  514.                 RESTORE programcommands
  515.                 b$ = ""
  516.                 DO
  517.                     READ a$, action$
  518.                     IF LCASE$(a$) = "eof" THEN EXIT DO
  519.                     IF LCASE$(a$) = cmd$ THEN b$ = action$: EXIT DO
  520.                 LOOP
  521.             END IF
  522.         END IF
  523.     ELSE
  524.         b$ = INKEY$
  525.     END IF
  526.     IF b$ = CHR$(27) THEN SYSTEM
  527.     IF VAL(b$) <= w3 AND VAL(b$) <> 0 OR LEN(b$) > 1 THEN EXIT DO
  528.  
  529. SUB highlight (a$, b$)
  530. LOCATE crow% + VAL(b$) - 1, ccol%
  531. COLOR 14, 0
  532. PRINT a$;
  533. COLOR 7, 0
  534. _DELAY .25
  535.  
  536. SUB taskactions (task$, flag)
  537. REDIM settings$(100)
  538. IF _FILEEXISTS("session-manager-settings.dat") THEN
  539.     OPEN "session-manager-settings.dat" FOR INPUT AS #1
  540.     i = 0
  541.     DO UNTIL EOF(1)
  542.         i = i + 1
  543.         INPUT #1, a$, action$
  544.         settings$(i) = a$ + "," + action$
  545.     LOOP
  546.     CLOSE #1
  547.     flag = -1
  548.  
  549. IF flag THEN
  550.     flag = 0
  551.     FOR j = 1 TO i
  552.         IF INSTR(LCASE$(settings$(j)), LCASE$(task$)) <> 0 THEN
  553.             flag = -1
  554.             a$ = MID$(settings$(j), INSTR(settings$(j), ",") + 1)
  555.             EXIT FOR
  556.         END IF
  557.     NEXT
  558.     IF flag THEN
  559.         IF INSTR(LCASE$(a$), "(undefined)") <> 0 THEN
  560.             CLS
  561.             LOCATE crow%, ccol%
  562.             PRINT "This feature requires making a"
  563.             LOCATE , ccol%
  564.             PRINT "setting before it can be used."
  565.             PRINT
  566.             LOCATE , ccol%
  567.             PRINT "Opening the settings screen..."
  568.             _DELAY 4
  569.             CLS
  570.             EXIT SUB
  571.         END IF
  572.         flag = 0
  573.         SELECT CASE LCASE$(task$)
  574.             CASE "load previous session"
  575.                 CALL startbrowser
  576.             CASE "close"
  577.                 ' Taskkill could be substituted here but may report an ff crash on next start up.
  578.                 CALL startbrowser ' Ensures browser is running full screen before _SCREENCLICK.
  579.                 REM x& = ShowWindow&(hwnd%&, 0) ' Closes Firefox but loses restore last session info.
  580.         END SELECT
  581.         DO
  582.             x% = VAL(a$)
  583.             a$ = MID$(a$, INSTR(a$, "-") + 1)
  584.             y% = VAL(a$)
  585.             _SCREENCLICK y%, x%
  586.             _DELAY 1
  587.             IF INSTR(a$, "|") = 0 THEN EXIT DO
  588.             a$ = MID$(a$, INSTR(a$, "|") + 1)
  589.         LOOP
  590.     END IF
  591.     CLS
  592.     PRINT " ERROR: sessions-settings.dat file is missing."
  593.     PRINT
  594.     PRINT " Rerun program to re-install default data."
  595.     END
  596.  
  597. SUB makesettings
  598.     REDIM settings$(100) ' Load the settings data again.
  599.     RESTORE settingslist
  600.     IF _FILEEXISTS("session-manager-settings.dat") THEN
  601.         CLS
  602.         OPEN "session-manager-settings.dat" FOR INPUT AS #1
  603.         i = 0: w4 = 0
  604.         DO UNTIL EOF(1)
  605.             i = i + 1
  606.             INPUT #1, a$, action$
  607.             settings$(i) = LTRIM$(STR$(i)) + ") " + a$ + "," + action$
  608.             a$ = MID$(settings$(i), 1, INSTR(settings$(i), ",") - 1) ' Do not include actions in menu.
  609.             IF LEN(a$) > w4 THEN w4 = LEN(a$)
  610.         LOOP
  611.         CLOSE #1
  612.         w3 = i
  613.         w4 = w4 + 2
  614.         crow% = 10
  615.         ccol% = cwidth% \ 2 - w4 \ 2
  616.         p1% = ccol%: p2% = ccol% + w4: p3% = crow%: p4% = crow% + w3 ' selection parameters
  617.         heading$ = "Settings"
  618.         LOCATE crow% - 3, ccol% + (w4 - 2) \ 2 - LEN(heading$) \ 2
  619.         PRINT heading$;
  620.         heading$ = "Back  |  Quit"
  621.         LOCATE crow% - 2, ccol% + (w4 - 2) \ 2 - LEN(heading$) \ 2
  622.         COLOR 3, 0
  623.         PRINT heading$;
  624.         COLOR 7, 0
  625.         LOCATE crow%, ccol%
  626.  
  627.         FOR i = 1 TO w3
  628.             LOCATE , ccol%
  629.             PRINT MID$(settings$(i), 1, INSTR(settings$(i), ",") - 1)
  630.         NEXT
  631.  
  632.         CALL box(w3, w4)
  633.  
  634.         CALL selection(w3, b$)
  635.  
  636.         a$ = MID$(settings$(VAL(b$)), 1, INSTR(settings$(VAL(b$)), ",") - 1)
  637.  
  638.         CALL highlight(a$, b$)
  639.  
  640.         IF b$ = "run" THEN RUN
  641.         IF b$ = "esc" THEN SYSTEM
  642.  
  643.         CLS
  644.         task$ = LCASE$(MID$(settings$(VAL(b$)), 1, INSTR(settings$(VAL(b$)), ",") - 1))
  645.         task$ = LTRIM$(MID$(task$, INSTR(task$, ")") + 1)) ' strip off number if present.
  646.         LOCATE crow% + 1, ccol%
  647.         PRINT "Working..."
  648.  
  649.         CALL mapping(task$)
  650.  
  651.         a$ = MID$(settings$(VAL(b$)), 1, INSTR(settings$(VAL(b$)), ","))
  652.         a$ = LTRIM$(MID$(a$, INSTR(a$, ")") + 1)) ' Strip off any number.
  653.         FOR i = 1 TO num%
  654.             a$ = a$ + LTRIM$(STR$(taby(i))) + "-" + LTRIM$(STR$(tabx(i))) + "|"
  655.         NEXT
  656.         a$ = MID$(a$, 1, LEN(a$) - 1)
  657.         settings$(VAL(b$)) = a$
  658.  
  659.         CALL savesettings(b$)
  660.  
  661.         CALL setscreen
  662.     ELSE
  663.         CLS
  664.         PRINT " ERROR: sessions-settings.dat file is missing."
  665.         PRINT
  666.         PRINT " Rerun program to re-install default data."
  667.         END
  668.     END IF
  669.     task$ = "": a$ = "": b$ = ""
  670.  
  671. SUB setscreen
  672. srindent% = _DESKTOPHEIGHT \ _FONTHEIGHT - maxwinheight% ' To be indented from the top.
  673. cwidth% = _DESKTOPWIDTH \ _FONTWIDTH - scindent% * 2
  674. WIDTH cwidth%, rheight%
  675. fw% = _FONTWIDTH: fh% = _FONTHEIGHT
  676. ' Now that WIDTH has been set, the font heigh can be used to calculate window size.
  677. _SCREENMOVE scindent% * fw%, srindent% * fh%
  678.  
  679. SUB startbrowser
  680. hwnd%& = FindWindowA(0, findbrowsertitle$ + CHR$(0))
  681. IF hwnd%& = 0 THEN
  682.     SHELL _DONTWAIT _HIDE "firefox.exe " + browsertab$
  683. i = 0
  684. DO ' Wait until title is registerd.
  685.     i = i + 1
  686.     hwnd%& = FindWindowA(0, findbrowsertitle$ + CHR$(0))
  687.     _DELAY .2
  688.     IF hwnd%& THEN EXIT DO
  689. LOOP UNTIL i = 100
  690.  
  691. CALL maximizewindow
  692.  
  693.  
  694. SUB maximizewindow
  695. x& = ShowWindow&(hwnd%&, 3) ' Maximize window from FindWindowA.
  696. z& = SetForegroundWindow&(hwnd%&)
  697.  
  698. SUB minimizewindow
  699. x& = ShowWindow&(hwnd%&, 2) ' Minimize window from FindWindowA.
  700.  
  701. SUB restorewindow
  702. x& = ShowWindow&(hwnd%&, 1) ' Restore window from FindWindowA.
  703. z& = SetForegroundWindow&(hwnd%&)
  704.  
  705. SUB focusapp
  706. hwnd%& = FindWindowA(0, title$ + CHR$(0))
  707. z& = SetForegroundWindow&(hwnd%&)
  708.  


Pete
« Last Edit: December 09, 2018, 04:55:44 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: FireFox Management App for Windows
« Reply #1 on: December 11, 2018, 07:18:16 pm »
Cool!
Thanks to share.
Programming isn't difficult, only it's  consuming time and coffee

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: FireFox Management App for Windows
« Reply #2 on: December 23, 2018, 08:42:27 pm »
Do you think this program could be modified to shutdown certain web pages if they are opened? like some kind of super parental controller?
Granted after becoming radioactive I only have a half-life!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: FireFox Management App for Windows
« Reply #3 on: December 24, 2018, 10:43:12 pm »
Do you think this program could be modified to shutdown certain web pages if they are opened? like some kind of super parental controller?

No. The reason is it cannot shut down a tab. On the other hand, if a website you don't want your kids to visit is opened, like FreeBasic.com, it could just end the whole browser session. Now if a kid could figure out that taking the browser out of full screen mode and just run it in a window, just below the top of the screen, the _SCREENCLICK coordinates would no longer be valid and the program would fail to work. So _SCRRENCLICK programming is a bit Mickey Mouse, but it if you are not trying to thwart it, it does get the job done.

Pete

Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/