From e6e1d7308aae576706c5bdebaf634f31c05c317d Mon Sep 17 00:00:00 2001 From: Thierry Dalon Date: Fri, 24 Nov 2023 14:15:01 +0100 Subject: [PATCH] Refactoring OpenLink, Teamsy bgs --- Lib/PowerTools.ahk | 115 +++++++++++++++++++++++++++++++++++------- Lib/Teamsy.ahk | 3 ++ NWS.ahk | 82 +----------------------------- docs/_pages/Teamsy.md | 4 +- 4 files changed, 103 insertions(+), 101 deletions(-) diff --git a/Lib/PowerTools.ahk b/Lib/PowerTools.ahk index b3325e6..268c103 100644 --- a/Lib/PowerTools.ahk +++ b/Lib/PowerTools.ahk @@ -231,32 +231,50 @@ return Config } ; ---------------------------------------------------------------------- PowerTools_SetConfig(){ -RegRead, Config, HKEY_CURRENT_USER\Software\PowerTools, Config -DefListConfig := "Default|Ini" -If FileExist("Lib/ET.ahk") - DefListConfig := DefListConfig . "|ET" -If FileExist("Lib/Conti.ahk") - DefListConfig := DefListConfig . "|Conti|Vitesco" -Select := 0 -Loop, parse, DefListConfig, | -{ - If (A_LoopField = Config) { - Select := A_Index - break +; Config := PowerTools_SetConfig() + RegRead, Config, HKEY_CURRENT_USER\Software\PowerTools, Config + DefListConfig := "Default|Ini" + If FileExist("Lib/ET.ahk") + DefListConfig := DefListConfig . "|ET" + If FileExist("Lib/Conti.ahk") + DefListConfig := DefListConfig . "|Conti|Vitesco" + Select := 0 + Loop, parse, DefListConfig, | + { + If (A_LoopField = Config) { + Select := A_Index + break + } } -} -Config := ListBox("PowerTools Config","Select your configuration:",DefListConfig,Select) -If (Config="") - return -PowerTools_RegWrite("Config",Config) -return Config + Config := ListBox("PowerTools Config","Select your configuration:",DefListConfig,Select) + If (Config="") + return + PowerTools_RegWrite("Config",Config) + return Config } ; eofun +; ------------------------------------------------------------------------------------------------------------------- +PowerTools_IniRead(Section,Key) { + ; PowerTools_IniRead(Section,Key) + ; return "ERROR" if key was not found in PowerTools.ini File + IniRead, OutputVar, PowerTools.ini,%Section%,%Key% + return OutputVar + } ; eofun + ; ------------------------------------------------------------------------------------------------------------------- + ; ------------------------------------------------------------------------------------------------------------------- + PowerTools_IniWrite(Var,Section,Key) { + ; PowerTools_IniWrite(Var,Section,Key) + ; ErrorLevel is returned + IniWrite, %Var%, PowerTools.ini, %Section%, %Key% + } ; eofun +; ------------------------------------------------------------------------------------------------------------------- + + ; ------------------------------------------------------------------------------------------------------------------- PowerTools_RegRead(Prop){ RegRead, OutputVar, HKEY_CURRENT_USER\Software\PowerTools, %Prop% return OutputVar -} +} ; eofun ; ------------------------------------------------------------------------------------------------------------------- PowerTools_RegWrite(Prop, Value){ @@ -599,3 +617,62 @@ PowerTools_ErrDlg(Text,sUrl:=""){ return } ; eofun + + +; ------------------------------------------------------------------------------------------------------------------- +; Open Link in Default browser - See https://tdalon.blogspot.com/2023/06/ahk-browser-link-redirector.html +PowerTools_OpenLink(sUrl) { ; @fun_open_link@ + ; Based on PowerTools.ini files [Browsers] and [BrowserRules] definition + + ;sUrl := IntelliPaste_CleanUrl(sUrl) + + If InStr(sUrl,"teams.microsoft.com") { ; remove browser leftover window + Try { ; in case Teams library is not provided with this OpenLink function + FunStr := "Teams_OpenUrl" ; hide function from compiler + %FunStr%(sUrl) + Return + } + } + + If !FileExist("PowerTools.ini") { + PowerTools_ErrDlg("OpenLink: No PowerTools.ini file found!") + GoTo OpenDefault + } + + ProjectKey := RegExReplace(sKey,"\-.*$") + IniRead, BrowserRules, PowerTools.ini,BrowserRules + If (BrowserRules="ERROR") { ; Section [BrowserRules] not found + PowerTools_ErrDlg("No section [BrowserRules] in PowerTools.ini file was found!") + GoTo OpenDefault + } + + Loop Parse, BrowserRules,`n,`r + { + RegExMatch(A_LoopField,"(.*)=(.*)",sMatch) + Loop Parse, sMatch2, CSV + { + If InStr(sUrl,A_LoopField) { + BrowserName := sMatch1 + break + } + } + If BrowserName + break + } + + If BrowserName { ; not empty + IniRead, BrowserCmd, PowerTools.ini,Browsers,%BrowserName% + If (BrowserCmd="ERROR") { ; Section [BrowserRules] not found + PowerTools_ErrDlg("OpenLink: No Browser Key matching BrowserName=" . BrowserName . " found in section [Browsers] in PowerTools.ini file!") + return + } + sCmd = "%BrowserCmd%" "%sUrl%" ; Reading String in Ini files removes trailing quotes + Run, %sCmd% + return + } + + OpenDefault: + Run, "%sUrl%" ; Default Browser + return + + } ; eofun End Function OpenLink \ No newline at end of file diff --git a/Lib/Teamsy.ahk b/Lib/Teamsy.ahk index 7802bb7..ea34b56 100644 --- a/Lib/Teamsy.ahk +++ b/Lib/Teamsy.ahk @@ -47,6 +47,9 @@ Case "bgf","bgo","backgrounds","cbg": Case "bg": Teams_MeetingBackgroundSet(sInput) return +Case "bgn": + Teams_BackgroundFile2Name("","w") + return Case "bgs": ; open background settings via Ctrl+Shift+P depreciated ;Teams_MeetingShortcuts("bg") Teams_MeetingBackgroundSettings() diff --git a/NWS.ahk b/NWS.ahk index f411b10..934df0a 100644 --- a/NWS.ahk +++ b/NWS.ahk @@ -314,7 +314,7 @@ return #IfWinActive, ahk_group OpenLinks ; Open in Default Browser (incl. Office applications) - see OpenLink function -; Shift Mouse click +; Shift Mouse click OpenLink +LButton:: ; Clip_All := ClipboardAll ; Save the entire clipboard to a variable Clipboard = ; Empty the clipboard to allow ClipWait work @@ -344,7 +344,7 @@ sUrl := Clipboard If sUrl { ; Not empty ;sUrl := IntelliPaste_CleanUrl(sUrl) ; convert e.g. teams links to SP links ;Run %sUrl% ; Handled by BrowserTamer -> blocked by IT - OpenLink(sUrl) + PowerTools_OpenLink(sUrl) } Else { Send {LButton} } @@ -763,84 +763,6 @@ PasteCleanUrl(encode:= False){ return } - -; ------------------------------------------------------------------------------------------------------------------- -; Function OpenLink -; Open Link in Default browser - See https://tdalon.blogspot.com/2023/06/ahk-browser-link-redirector.html -OpenLink(sUrl) { ; @fun_open_link@ -; Based on PowerTools.ini files [Browsers] and [BrowserRules] definition - -;sUrl := IntelliPaste_CleanUrl(sUrl) - -If InStr(sUrl,"teams.microsoft.com") { ; remove browser leftover window - Teams_OpenUrl(sUrl) - Return -} - - -If !FileExist("PowerTools.ini") { - PowerTools_ErrDlg("OpenLink: No PowerTools.ini file found!") - GoTo OpenDefault -} - -ProjectKey := RegExReplace(sKey,"\-.*$") -IniRead, BrowserRules, PowerTools.ini,BrowserRules -If (BrowserRules="ERROR") { ; Section [BrowserRules] not found - PowerTools_ErrDlg("No section [BrowserRules] in PowerTools.ini file was found!") - GoTo OpenDefault -} - -Loop Parse, BrowserRules,`n,`r -{ - RegExMatch(A_LoopField,"(.*)=(.*)",sMatch) - Loop Parse, sMatch2, CSV - { - If InStr(sUrl,A_LoopField) { - BrowserName := sMatch1 - break - } - } - If BrowserName - break -} - -If BrowserName { ; not empty - IniRead, BrowserCmd, PowerTools.ini,Browsers,%BrowserName% - If (BrowserCmd="ERROR") { ; Section [BrowserRules] not found - PowerTools_ErrDlg("OpenLink: No Browser Key matching BrowserName=" . BrowserName . " found in section [Browsers] in PowerTools.ini file!") - return - } - sCmd = "%BrowserCmd%" "%sUrl%" ; Reading String in Ini files removes trailing quotes - Run, %sCmd% - return -} - - -OpenDefault: -Run, "%sUrl%" ; Default Browser -return - - - If SharePoint_IsUrl(sUrl) { - If InStr(sUrl,".xlsx") { - sUrl := "ms-excel:ofe|u|" . sUrl - Run, "%sUrl%" - } - } If IsIELink(sUrl) { - ;Run, %A_ProgramFiles%\Internet Explorer\iexplore.exe %sUrl% - Run, iexplore.exe "%sUrl%" - } Else If Confluence_IsUrl(sUrl) || Jira_IsUrl(sUrl) { ; JIRA or Confluence urls - ;Run, C:\Users\%A_UserName%\AppData\Local\Google\Chrome\Application\chrome.exe %sUrl% - Run, "C:\Program Files\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 3" "%sUrl%" - } Else If InStr(sUrl,"https://teams.microsoft.com/") { ; Teams url=>open by default in App - ;Run, StrReplace(sUrl, "https://","msteams://") - Run, "C:\Program Files\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 4" "%sUrl%" - } Else { - ;sUrl := IntelliPaste_CleanUrl(sUrl) ; No need to clean because handled by Redirector - Run, "C:\Program Files\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 1" "%sUrl%" - } ; End If -} ; eofun End Function OpenLink - ; ---------------------------------------------------------------------- QuickSearch(){ If GetKeyState("Ctrl") and !GetKeyState("Shift") { diff --git a/docs/_pages/Teamsy.md b/docs/_pages/Teamsy.md index 97c70c1..5afbaa1 100644 --- a/docs/_pages/Teamsy.md +++ b/docs/_pages/Teamsy.md @@ -94,11 +94,11 @@ rh(+-) | [Raise your Hand](https://tdalon.blogspot.com/2021/02/teams-raise-han le | [Leave Meeting](https://tdalon.blogspot.com/2023/11/teamsy-leave-meeting.html) sb(+-) | [Hide/Show Sharing Control bar](https://tdalon.blogspot.com/2023/10/teams-quick-share-screen.html) bg | [Set Background](https://tdalon.blogspot.com/2023/11/teams-set-background.html) +bgn | Set Background Name +bgs | Open Background Settings ### Others - - Keywords | Action --|-- lo | Love (Conversation Reaction)