-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
d50888a
commit f42ed12
Showing
9 changed files
with
226 additions
and
1 deletion.
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 @@ | ||
class ConfigModel | ||
{ | ||
public Location[] Locations; | ||
|
||
} | ||
|
||
class Location | ||
{ | ||
public string Name; | ||
// TODO: add ways of detecting location (note that they are not necessarily mutually exclusive) | ||
} | ||
|
||
class Capability | ||
{ | ||
public string Name; | ||
} |
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,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup><OkFeatures>Core;Docopt</OkFeatures></PropertyGroup> | ||
<Import Project="$(OkTargetsRoot)Exe.targets"/> | ||
|
||
<PropertyGroup> | ||
<AssemblyName>machmode</AssemblyName> | ||
<RootNamespace /> | ||
</PropertyGroup> | ||
|
||
</Project> |
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,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup><OkFeatures>NiceIO</OkFeatures></PropertyGroup> | ||
<Import Project="$(OkTargetsRoot)Tests.targets" /> | ||
|
||
<PropertyGroup> | ||
<RootNamespace>MachModeCli.Tests</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="MachModeCli.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,20 @@ | ||
const string programVersion = "0.1"; | ||
|
||
/* | ||
* syntax: | ||
* | ||
* foo = set to this and turn everything else off | ||
* +foo = overlay this with everything else | ||
* ~foo = disable this one | ||
* | ||
* processing happens left to right and each can override previous (have a way to print out the rules as they are being evaluated) | ||
* | ||
* for now require that all locations and capabilities and profiles etc. are globally uniquely named so don't have to worry about scoping | ||
*/ | ||
|
||
var (exitCode, opt) = MachModeCliArguments.CreateParser().Parse(args, programVersion, MachModeCliArguments.Help, MachModeCliArguments.Usage); | ||
if (exitCode != null) | ||
return (int)exitCode.Value; | ||
|
||
return (int)CliExitCode.Success; | ||
|
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,6 @@ | ||
{0}, the merry machine mode manager v{1} | ||
|
||
Usage: | ||
{0} [PROFILE...] | ||
{0} --help | ||
{0} --version |
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,67 @@ | ||
#Requires -Version 7 | ||
#Requires -module powershell-yaml | ||
|
||
param( | ||
####[Parameter(Mandatory = $true)] | ||
[string]$Mode | ||
) | ||
|
||
$Mode = ($Mode -and $Mode.Length) ? $Mode : 'gaming' ####$$$$$ | ||
|
||
|
||
|
||
Set-StrictMode -Version Latest | ||
$ErrorActionPreference = 'Stop' #'Break' #'Stop' | ||
|
||
# pre-checks | ||
|
||
$asusService = Get-Service 'ASUS Link Near' | ||
if ($asusService -and ($asusService.Status -ne 'Stopped' -or $asusService.StartType -ne 'Disabled')) { | ||
Write-Warning 'Tell G-Helper to kill ASUS services' | ||
} | ||
|
||
$config = Get-Content machmode.yaml | ConvertFrom-Yaml | ||
|
||
$modesConfig = [ordered]@{} | ||
|
||
$config.modes | %{ | ||
if ($_ -is [string]) { | ||
$modesConfig[$_] = $_ | ||
} | ||
elseif ($_ -is [hashtable]) { | ||
$modesConfig[$_.keys[0]] = $_.values[0] | ||
} | ||
} | ||
|
||
$baseMode = $modesConfig[$Mode] | ||
if (!$baseMode) { | ||
Write-Error "Invalid mode $Mode (valid modes: $(($modesConfig.Keys | %{ $_ }) -join ', '))" | ||
} | ||
|
||
exit 0 | ||
|
||
foreach ($appConfig in $config.apps.GetEnumerator()) { | ||
$exeName = $appConfig.Name | ||
$shouldBeActive = ($modesConfig -contains $Mode) -or ($modesConfig -contains $baseMode) | ||
$processes = Get-Process -Name $exeName -ErrorAction SilentlyContinue | ||
|
||
if ($shouldBeActive) { | ||
if ($processes) { | ||
Write-Host "$exeName is already running" | ||
} else { | ||
Write-Host "Starting $exeName" | ||
Start-Process $appConfig.Value.path | ||
} | ||
} | ||
else { | ||
if ($processes) { | ||
foreach ($process in $processes) { | ||
Write-Host "Killing $exeName" | ||
$process.Kill() | ||
} | ||
} | ||
else { | ||
Write-Host "$exeName is not running" | ||
} | ||
} | ||
} |
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,80 @@ | ||
#file: noinspection SpellCheckingInspection | ||
|
||
# traits | ||
# | ||
# - valid: true if this is available to be selected/combined | ||
# - combine: copy the other thing and combine it with this one via add or subtract (is "soft" - the other thing may be invalid in which case it is ignored) | ||
# - require: copy validity requirement of other thing and combine with this (may be "any" or "all" expr) | ||
# - config: any of these entries, holds rules and state and validity and instructions | ||
# - target config: the final config we are accumulating and will process. user is adding/subtracting to this. | ||
|
||
# by default profiles using profiles are required, but we can do a simple combine with ? at the end | ||
# by default profiles using features are combined | ||
|
||
# entity: validity is controlled by detecting whether entity is connected/active. usually is a physical device but doesn't need to be. just needs a way to detect it. | ||
# feature: a set of processes and OS services that we can detect/start/stop when feature is activated/deactivated. may require one or more entities to be valid. | ||
# profile: can combine entities and features and other profiles. all features are activated/deactivated along with the profile. | ||
|
||
profiles: | ||
|
||
offline: -resilio -onedrive -syncthing -macrium -zerotier | ||
mobile: -kde-mover-sizer | ||
minimal: -desk | ||
endurance: minimal offline | ||
desk: streamdeck | ||
|
||
dev: jb_toolbox | ||
|
||
sfact: game lg-75 | ||
game: steam razer | ||
|
||
features: | ||
|
||
# gaming | ||
streamdeck: { select: streamdeck_xl, path: '%ProgramFiles%\Elgato\StreamDeck\StreamDeck.exe' } | ||
steam: { path: '%ProgramFiles(x86)%\Steam\Steam.exe' } | ||
razer: | ||
require: razer_* | ||
path: | ||
- razer1 | ||
- razer2 | ||
service: razer* | ||
oculus: { service: oculus* } | ||
lg-75: { require: lg_wide, action: resolution=75% } | ||
|
||
# dev | ||
jb_toolbox: '%LOCALAPPDATA%\JetBrains\Toolbox\bin\jetbrains-toolbox.exe' | ||
|
||
# online | ||
resilio: '%APPDATA%\Resilio Sync\Resilio Sync.exe' | ||
|
||
# general | ||
everything: [ | ||
path: '~\scoop\apps\everything\current\Everything.exe', | ||
service: everything | ||
] | ||
ferdium: '~\scoop\apps\ferdium-nightly\current\Ferdium.exe' | ||
powertoys: '%LOCALAPPDATA%\PowerToys\PowerToys.exe' | ||
kde-mover-sizer: '~\.local\share\bin\KDE Mover-Sizer for Windows x64\KDE Mover-Sizer.exe' | ||
#malwarebytes | ||
macrium: { service: ? warn-active: path: reflect-monitor.exe } | ||
|
||
# default startup stuff | ||
groupy: { service: '*groupy*' } | ||
samsung: { service: 'samsung*' } | ||
zerotier: { service: ZeroTier One } | ||
rog-basics: { service: ROG Live Service } | ||
onedrive: { ?? } | ||
syncthing: { ?? } | ||
|
||
entities: | ||
|
||
streamdeck_xl: {} # detect with usb query | ||
razer_naga: {} # detect with usb query | ||
razer_tartarus: {} # detect with usb query | ||
razer_firefly: {} # detect with usb query | ||
lg_wide: {} # detect with monitor query | ||
gaming_dock: {} # can detect w mac addr | ||
kensington_dock: {} # can detect w mac addr | ||
power: {} # charging/charged | ||
online: {} # can ping microsoft |
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