Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbilas committed Aug 24, 2023
1 parent d50888a commit f42ed12
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 1 deletion.
14 changes: 13 additions & 1 deletion OkTools.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "src\Core\Core.csproj", "{C30F4B4B-DDBB-4D66-A7C0-6C71637CEC39}"
EndProject
Expand Down Expand Up @@ -32,6 +32,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PmlTool.Cli", "src\PmlTool.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core.PerfTests", "perftests\Core.PerfTests\Core.PerfTests.csproj", "{3D70F5C9-4AA8-4B3F-AB87-E23B8F6B7507}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MachMode.Cli", "src\MachMode.Cli\MachMode.Cli.csproj", "{14022DF9-B6B2-45FE-8991-07D3B00EC4DA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MachModeCli-Tests", "src\MachMode.Cli\MachModeCli-Tests.csproj", "{C875B7D7-7FF4-4732-9FE0-A7A35D077F94}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -102,5 +106,13 @@ Global
{3D70F5C9-4AA8-4B3F-AB87-E23B8F6B7507}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3D70F5C9-4AA8-4B3F-AB87-E23B8F6B7507}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3D70F5C9-4AA8-4B3F-AB87-E23B8F6B7507}.Release|Any CPU.Build.0 = Release|Any CPU
{14022DF9-B6B2-45FE-8991-07D3B00EC4DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{14022DF9-B6B2-45FE-8991-07D3B00EC4DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{14022DF9-B6B2-45FE-8991-07D3B00EC4DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{14022DF9-B6B2-45FE-8991-07D3B00EC4DA}.Release|Any CPU.Build.0 = Release|Any CPU
{C875B7D7-7FF4-4732-9FE0-A7A35D077F94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C875B7D7-7FF4-4732-9FE0-A7A35D077F94}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C875B7D7-7FF4-4732-9FE0-A7A35D077F94}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C875B7D7-7FF4-4732-9FE0-A7A35D077F94}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
16 changes: 16 additions & 0 deletions src/MachMode.Cli/ConfigModel.cs
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;
}
10 changes: 10 additions & 0 deletions src/MachMode.Cli/MachMode.Cli.csproj
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>
13 changes: 13 additions & 0 deletions src/MachMode.Cli/MachModeCli-Tests.csproj
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>
20 changes: 20 additions & 0 deletions src/MachMode.Cli/MachModeCli.cs
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;

6 changes: 6 additions & 0 deletions src/MachMode.Cli/MachModeCli.docopt.txt
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
67 changes: 67 additions & 0 deletions src/MachMode.Cli/testdata/machmode.ps1
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"
}
}
}
80 changes: 80 additions & 0 deletions src/MachMode.Cli/testdata/machmode.yaml
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
1 change: 1 addition & 0 deletions targets/Library.targets
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="*.t.cs" />
<None Remove="*" />
</ItemGroup>
</When>
<Otherwise>
Expand Down

0 comments on commit f42ed12

Please sign in to comment.