-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall.ps1
More file actions
89 lines (77 loc) · 3.13 KB
/
Copy pathInstall.ps1
File metadata and controls
89 lines (77 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<#
Creates a Desktop shortcut for TimeTracker, and optionally starts it with Windows.
Usage:
.\Install.ps1 # desktop shortcut, asks about auto-start
.\Install.ps1 -Startup # desktop shortcut + auto-start, no prompt
.\Install.ps1 -NoStartup # desktop shortcut only, no prompt
.\Install.ps1 -Uninstall # removes both shortcuts (your data is untouched)
#>
[CmdletBinding()]
param(
[switch]$Startup,
[switch]$NoStartup,
[switch]$Uninstall
)
$ErrorActionPreference = 'Stop'
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$script = Join-Path $here 'timetracker.py'
$icon = Join-Path $here 'icon.ico'
$desktopLnk = Join-Path ([Environment]::GetFolderPath('Desktop')) 'TimeTracker.lnk'
$startupLnk = Join-Path ([Environment]::GetFolderPath('Startup')) 'TimeTracker.lnk'
if ($Uninstall) {
foreach ($p in @($desktopLnk, $startupLnk)) {
if (Test-Path $p) { Remove-Item $p -Force; Write-Host "Removed $p" }
else { Write-Host "Not present: $p" }
}
Write-Host ''
Write-Host 'Shortcuts removed. Your recorded hours are still in:' -ForegroundColor Yellow
Write-Host " $HOME\Documents\TimeTracker\timetracker.db"
return
}
if (-not (Test-Path $script)) { throw "timetracker.py not found in $here" }
# --- locate pythonw.exe (windowed Python, so no console window appears) -------
$pythonw = $null
$cmd = Get-Command pythonw.exe -ErrorAction SilentlyContinue
if ($cmd) { $pythonw = $cmd.Source }
if (-not $pythonw) {
$cmd = Get-Command python.exe -ErrorAction SilentlyContinue
if ($cmd) {
$candidate = Join-Path (Split-Path -Parent $cmd.Source) 'pythonw.exe'
if (Test-Path $candidate) { $pythonw = $candidate } else { $pythonw = $cmd.Source }
}
}
if (-not $pythonw) { throw 'Python 3 was not found on PATH. Install it from python.org, then re-run.' }
Write-Host "Using: $pythonw"
if (-not (Test-Path $icon)) {
Write-Host 'Generating icon...'
& $pythonw (Join-Path $here 'make_icon.py') | Out-Null
}
function New-TTShortcut([string]$Path) {
$shell = New-Object -ComObject WScript.Shell
$lnk = $shell.CreateShortcut($Path)
$lnk.TargetPath = $pythonw
$lnk.Arguments = '"{0}"' -f $script
$lnk.WorkingDirectory = $here
$lnk.Description = 'TimeTracker - punch clock and hours widget'
if (Test-Path $icon) { $lnk.IconLocation = $icon }
$lnk.Save()
Write-Host "Created $Path" -ForegroundColor Green
}
New-TTShortcut $desktopLnk
# --- auto-start ---------------------------------------------------------------
$wantStartup = $false
if ($Startup) { $wantStartup = $true }
elseif ($NoStartup) { $wantStartup = $false }
else {
$answer = Read-Host 'Start TimeTracker automatically when Windows starts? (y/N)'
$wantStartup = $answer -match '^[Yy]'
}
if ($wantStartup) {
New-TTShortcut $startupLnk
} elseif (Test-Path $startupLnk) {
Remove-Item $startupLnk -Force
Write-Host 'Auto-start disabled.'
}
Write-Host ''
Write-Host 'Done. Launch it from the Desktop shortcut.' -ForegroundColor Green
Write-Host "Hours are stored in $HOME\Documents\TimeTracker\timetracker.db"