-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
275 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
|
||
logger2 "github.com/ft-t/browser-switcher/pkg/logger" | ||
) | ||
|
||
func main() { | ||
logger := logger2.GetLogger() | ||
ctx := logger.WithContext(context.Background()) | ||
|
||
if err := run(ctx); err != nil { | ||
logger.Panic().Err(err).Msg("failed to run") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/exec" | ||
"slices" | ||
"syscall" | ||
|
||
"github.com/rs/zerolog" | ||
"golang.org/x/sys/windows/registry" | ||
) | ||
|
||
func findAppRegistrationPath(ctx context.Context) (string, error) { | ||
key, err := registry.OpenKey( | ||
registry.CURRENT_USER, | ||
`Software\Clients\StartMenuInternet\Browser Switcher\shell\open\command`, | ||
registry.QUERY_VALUE, | ||
) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
val, _, err := key.GetStringValue("Proxied") | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
zerolog.Ctx(ctx).Debug().Msgf("found app registration path: %s", val) | ||
|
||
return val, err | ||
} | ||
|
||
func run(ctx context.Context) error { | ||
appPath, err := findAppRegistrationPath(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
args := slices.Concat([]string{ | ||
"/C", | ||
"start", | ||
appPath, | ||
}, os.Args[1:]) | ||
|
||
cmd := exec.Command( | ||
"cmd.exe", | ||
args..., | ||
) | ||
|
||
cmd.SysProcAttr = &syscall.SysProcAttr{ | ||
HideWindow: true, | ||
CreationFlags: 0x08000000, | ||
} | ||
|
||
return cmd.Start() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package logger | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/rs/zerolog" | ||
"github.com/rs/zerolog/log" | ||
"gopkg.in/natefinch/lumberjack.v2" | ||
) | ||
|
||
func GetLogger() zerolog.Logger { | ||
currentDir := filepath.Dir(os.Args[0]) | ||
|
||
logFile := &lumberjack.Logger{ | ||
Filename: filepath.Join(currentDir, "logs", "log.log"), | ||
MaxSize: 30, | ||
MaxBackups: 3, | ||
MaxAge: 10, | ||
Compress: false, | ||
} | ||
lg := zerolog.New(zerolog.MultiLevelWriter(os.Stdout, logFile)).With().Timestamp().Logger() | ||
log.Logger = lg | ||
|
||
return lg | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
$binaryName = "BrowserSwitcher" | ||
$appPath = "I:\$binaryName.exe" | ||
$proxiedPath = "I:\${binaryName}Proxied.exe" | ||
|
||
$AppLongName = "Browser Switcher" | ||
$AppRegDescription = "Browser Switcher" | ||
$CustomProtoName = "x-browser-switcher" | ||
|
||
function Get-BrowserRegistrationPath { | ||
return "HKCU:\Software\Clients\StartMenuInternet\$AppLongName" | ||
} | ||
|
||
function Register-Browser { | ||
$softPath = "Software\Clients\StartMenuInternet\$AppLongName" | ||
$appRoot = "HKCU:\Software\Clients\StartMenuInternet\$AppLongName" | ||
$capRoot = "$appRoot\Capabilities" | ||
|
||
New-Item -Path $appRoot -Force | ||
New-Item -Path $capRoot -Force | ||
|
||
# Add basic registration | ||
Set-ItemProperty -Path $appRoot -Name "(Default)" -Value $AppLongName | ||
Set-ItemProperty -Path $capRoot -Name "ApplicationName" -Value $AppLongName | ||
Set-ItemProperty -Path $capRoot -Name "ApplicationDescription" -Value $AppRegDescription | ||
Set-ItemProperty -Path $capRoot -Name "ApplicationIcon" -Value "$appPath,0" | ||
|
||
# Supported protocols | ||
$urlAssocPath = "$capRoot\URLAssociations" | ||
New-Item -Path $urlAssocPath -Force | ||
foreach ($protocol in @("https", "http", $CustomProtoName)) { | ||
Set-ItemProperty -Path $urlAssocPath -Name $protocol -Value "BrowserSwitcherHTM" | ||
} | ||
|
||
# File associations | ||
$fileAssocPath = "$capRoot\FileAssociations" | ||
if (-not (Test-Path -Path $fileAssocPath)) { | ||
New-Item -Path $fileAssocPath -Force | ||
} | ||
|
||
# Define file extensions for HTML and related files | ||
$htmlExtensions = @(".svg", ".htm", ".html", ".shtml", ".webp", ".xht", ".xhtml", ".mht", ".mhtml", ".pdf") | ||
foreach ($ext in $htmlExtensions) { | ||
Set-ItemProperty -Path $fileAssocPath -Name $ext -Value "BrowserSwitcherHTM" | ||
} | ||
|
||
# Command registration | ||
New-Item -Path "$appRoot\DefaultIcon" -Force | ||
Set-ItemProperty -Path "$appRoot\DefaultIcon" -Name "(Default)" -Value "$appPath,0" | ||
|
||
New-Item -Path "$appRoot\shell\open\command" -Force | ||
|
||
Set-ItemProperty -Path "$appRoot\shell\open\command" -Name "(Default)" -Value "`"$appPath`"" | ||
Set-ItemProperty -Path "$appRoot\shell\open\command" -Name "Proxied" -Value "$proxiedPath" | ||
|
||
# Register capabilities | ||
Set-ItemProperty -Path "HKCU:\Software\RegisteredApplications" -Name $AppLongName -Value "$softPath\Capabilities" | ||
} | ||
|
||
function Register-Protocol { | ||
$root = "HKCU:\Software\Classes\$CustomProtoName" | ||
|
||
$registrationPath = @("Registry::HKEY_CLASSES_ROOT\BrowserSwitcherHTM", "Registry::HKEY_CLASSES_ROOT\BrowserSwitcherPDF", "Registry::HKEY_CURRENT_USER\Software\Classes\BrowserSwitcherHTM", "Registry::HKEY_CURRENT_USER\Software\Classes\BrowserSwitcherPDF") | ||
foreach ($regPath in $registrationPath) { | ||
New-Item -Path "$regPath" -Force | ||
|
||
Set-ItemProperty -Path "$regPath" -Name "(Default)" -Value "Browser Switcher HTML Document" | ||
|
||
New-Item -Path "$regPath\Application" -Force | ||
New-Item -Path "$regPath\DefaultIcon" -Force | ||
|
||
New-Item -Path "$regPath\shell" -Force | ||
New-Item -Path "$regPath\shell\open" -Force | ||
New-Item -Path "$regPath\shell\open\command" -Force | ||
|
||
Set-ItemProperty -Path "$regPath\Application" -Name "ApplicationName" -Value $AppLongName | ||
Set-ItemProperty -Path "$regPath\Application" -Name "ApplicationDescription" -Value $AppRegDescription | ||
|
||
Set-ItemProperty -Path "$regPath\DefaultIcon" -Name "(Default)" -Value "$appPath,0" | ||
Set-ItemProperty -Path "$regPath\shell\open\command" -Name "(Default)" -Value "`"$appPath`" `%1" | ||
} | ||
|
||
New-Item -Path $root -Force | ||
Set-ItemProperty -Path $root -Name "(Default)" -Value "URL:$CustomProtoName" | ||
Set-ItemProperty -Path $root -Name "URL Protocol" -Value "" | ||
|
||
$commandRoot = "$root\shell\open\command" | ||
New-Item -Path $commandRoot -Force | ||
Set-ItemProperty -Path $commandRoot -Name "(Default)" -Value "`"$appPath`" `"%1`"" | ||
} | ||
|
||
function Unregister-Browser { | ||
$appRoot = Get-BrowserRegistrationPath | ||
Remove-Item -Path $appRoot -Recurse -Force | ||
} | ||
|
||
function Unregister-Protocol { | ||
$root = "HKCU:\Software\Classes\$CustomProtoName" | ||
Remove-Item -Path $root -Recurse -Force | ||
} | ||
|
||
Register-Browser | ||
Register-Protocol |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{ | ||
"RT_GROUP_ICON": { | ||
"APP": { | ||
"0000": [ | ||
"icon.png", | ||
"icon16.png" | ||
] | ||
} | ||
}, | ||
"RT_MANIFEST": { | ||
"#1": { | ||
"0409": { | ||
"identity": { | ||
"name": "", | ||
"version": "" | ||
}, | ||
"description": "", | ||
"minimum-os": "win7", | ||
"execution-level": "as invoker", | ||
"ui-access": false, | ||
"auto-elevate": false, | ||
"dpi-awareness": "system", | ||
"disable-theming": false, | ||
"disable-window-filtering": false, | ||
"high-resolution-scrolling-aware": false, | ||
"ultra-high-resolution-scrolling-aware": false, | ||
"long-path-aware": false, | ||
"printer-driver-isolation": false, | ||
"gdi-scaling": false, | ||
"segment-heap": false, | ||
"use-common-controls-v6": false | ||
} | ||
} | ||
}, | ||
"RT_VERSION": { | ||
"#1": { | ||
"0000": { | ||
"fixed": { | ||
"file_version": "0.0.0.0", | ||
"product_version": "0.0.0.0" | ||
}, | ||
"info": { | ||
"0409": { | ||
"Comments": "", | ||
"CompanyName": "", | ||
"FileDescription": "", | ||
"FileVersion": "", | ||
"InternalName": "", | ||
"LegalCopyright": "", | ||
"LegalTrademarks": "", | ||
"OriginalFilename": "", | ||
"PrivateBuild": "", | ||
"ProductName": "", | ||
"ProductVersion": "", | ||
"SpecialBuild": "" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |