Skip to content

Commit

Permalink
Refactoring OpenLink, Teamsy bgs
Browse files Browse the repository at this point in the history
  • Loading branch information
Thierry Dalon committed Nov 24, 2023
1 parent f3d7a48 commit e6e1d73
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 101 deletions.
115 changes: 96 additions & 19 deletions Lib/PowerTools.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions Lib/Teamsy.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
82 changes: 2 additions & 80 deletions NWS.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
}
Expand Down Expand Up @@ -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") {
Expand Down
4 changes: 2 additions & 2 deletions docs/_pages/Teamsy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e6e1d73

Please sign in to comment.