-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto power switching with start on boot / resume / unlock screen, rem…
…oved export config notice for updates.
- Loading branch information
Showing
3 changed files
with
93 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** @format */ | ||
|
||
import { setG14ControlPlan } from './IPCEvents/G14ControlPlans'; | ||
import { whichCharger } from './IPCEvents/WMI/HardwareControl'; | ||
import { Notification } from 'electron'; | ||
import getLogger from './Logger'; | ||
|
||
const LOGGER = getLogger('StartupPlan'); | ||
|
||
const applyPlan = async (plano: G14ControlPlan, config: G14Config) => { | ||
let plan = plano; | ||
if (typeof plano === 'string') { | ||
plan = config.plans.find((pln) => pln.name === plano); | ||
} else { | ||
plan = plano; | ||
} | ||
|
||
LOGGER.info(`Recieved plan:\n${JSON.stringify(plan, null, 2)}`); | ||
let curve: FanCurveConfig; | ||
if (plan.fanCurve) { | ||
curve = config.fanCurves.find((curv) => { | ||
return curv.name === plan.fanCurve; | ||
}) as FanCurveConfig; | ||
} | ||
let radj: RyzenadjConfigNamed; | ||
if (plan.ryzenadj) { | ||
radj = config.ryzenadj.options.find((rdj) => { | ||
return rdj.name === plan.ryzenadj; | ||
}); | ||
} | ||
|
||
if ((curve || !plan.fanCurve) && (radj || !plan.ryzenadj)) { | ||
let full: FullG14ControlPlan = { | ||
name: plan.name, | ||
fanCurve: curve, | ||
ryzenadj: radj, | ||
armouryCrate: plan.armouryCrate, | ||
boost: plan.boost, | ||
windowsPlan: plan.windowsPlan, | ||
graphics: plan.graphics, | ||
}; | ||
let result = await setG14ControlPlan(full); | ||
if (result) { | ||
return true; | ||
} else { | ||
LOGGER.error('Failed to set G14Control plan.'); | ||
return false; | ||
} | ||
} else { | ||
LOGGER.info( | ||
`Could not find curve or ryzenadj plan with names:\nryzen: ${plan.ryzenadj}\ncurve: ${plan.fanCurve}` | ||
); | ||
return false; | ||
} | ||
}; | ||
|
||
export const initStartupPlan = async (config: G14Config) => { | ||
let { autoSwitch } = config; | ||
if (autoSwitch && autoSwitch.enabled) { | ||
let result = await whichCharger(); | ||
if (result) { | ||
let { ac, dc, usb } = result; | ||
if ((ac || usb) && autoSwitch.acPlan) { | ||
let result = await applyPlan(autoSwitch.acPlan, config); | ||
if (result) { | ||
new Notification({ | ||
title: 'Auto Switching', | ||
body: 'Switched to: ' + autoSwitch.acPlan.name, | ||
}).show(); | ||
} | ||
} else if (dc && autoSwitch.dcPlan) { | ||
let result = await applyPlan(autoSwitch.dcPlan, config); | ||
if (result) { | ||
new Notification({ | ||
title: 'Auto Switching', | ||
body: 'Switched to: ' + autoSwitch.dcPlan.name, | ||
}).show(); | ||
} | ||
} | ||
} | ||
} | ||
}; |
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