Skip to content

Commit

Permalink
Merge pull request #37 from nathan-fiscaletti/dev
Browse files Browse the repository at this point in the history
Application version: 1.3.0, Backend version: 5.9.0
  • Loading branch information
nathan-fiscaletti authored Jan 6, 2025
2 parents fec5634 + 3b48735 commit 1c24105
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 79 deletions.
2 changes: 1 addition & 1 deletion application/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kbs-electron",
"productName": "Keyboard Sounds",
"version": "1.2.3",
"version": "1.3.0",
"description": "https://keyboardsounds.net/",
"main": ".webpack/main",
"repository": {
Expand Down
46 changes: 25 additions & 21 deletions application/src/api/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ const store = new Store();

const ErrPythonVersionUnknown = 'Failed to parse python version';
const ErrPythonMissing = 'Python is not installed';
const ErrPythonVersionMismatch = 'Python Version 3.0 or higher is required';
const ErrPythonVersionMismatch = 'Python Version 3.8 or higher is required';
const ErrPythonPackageMissing = 'KeyboardSounds package is not installed';
const ErrPythonPackageVersionMismatch = 'KeyboardSounds package version mismatch';
const ErrPythonPackageVersionMismatch = 'KeyboardSounds python package version 5.9.0 or higher is required.';

const MinimumPythonVersion = '3.8.0';
const MinimumPythonPackageVersion = '5.7.2';
const MinimumPythonPackageVersion = '5.9.0';

const kbs = {
mainWindow: null,
Expand Down Expand Up @@ -364,6 +364,21 @@ const kbs = {
this.editorWindow.focus();
},

getState: function() {
return new Promise((resolve, reject) => {
this.exec('state', false).then((stdout) => {
try {
const state = JSON.parse(stdout);
resolve(state);
} catch (err) {
reject(err);
}
}).catch((err) => {
reject(err);
});
});
},

registerKbsIpcHandler: function (ipcMain, shouldNotify=()=>false) {
// Listen for incoming IPC messages.
ipcMain.on('kbs', async (event, data) => {
Expand Down Expand Up @@ -422,54 +437,43 @@ const kbs = {
lastKnownPerformNotify = performNotify;
}
if (performNotify) {
this.status().then((status) => {
this.getState().then(state => {
const status = state.status;
const stringifiedStatus = JSON.stringify(status);
if (lastKnownStatus === null || stringifiedStatus !== lastKnownStatus) {
console.log('notifying status change');
notify('kbs-status', status);
// Update the last known status
lastKnownStatus = stringifiedStatus;
}
}).catch((err) => {
console.error('Failed to fetch status:', err);
});

// Watch the app rules and notify the renderer process when they change
this.getGlobalAction().then((action) => {
const action = state.global_action;
if (lastKnownGlobalAction === null || action !== lastKnownGlobalAction) {
console.log('notifying global action change');
notify('kbs-global-action', action);
// Update the last known global action
lastKnownGlobalAction = action;
}
}).catch((err) => {
console.error('Failed to fetch global action:', err);
});

// Watch the rules and notify the renderer process when they change
this.rules().then((rules) => {
const rules = state.rules;
const stringifiedRules = JSON.stringify(rules)
if (lastKnownAppRules === null || stringifiedRules !== lastKnownAppRules) {
console.log('notifying app rules change');
notify('kbs-app-rules', rules);
// Update the last known app rules
lastKnownAppRules = stringifiedRules;
}
}).catch((err) => {
console.error('Failed to fetch app rules:', err);
});

// Watch the profiles and notify the renderer process when they change
this.profiles().then((profiles) => {
const profiles = state.profiles;
const stringifiedProfiles = JSON.stringify(profiles);
if (lastKnownProfiles === null || stringifiedProfiles !== lastKnownProfiles) {
console.log('notifying profiles change');
notify('kbs-profiles', profiles);
// Update the last known profiles
lastKnownProfiles = stringifiedProfiles;
}
}).catch((err) => {
console.error('Failed to fetch profiles:', err);
}).catch(err => {
console.error('Failed to fetch state:', err);
});
}
}, 1000);
Expand Down
2 changes: 2 additions & 0 deletions application/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const toggleWindow = () => {
show: true,
resizable: true,
minimizable: true,
skipTaskbar: false,
movable: true,
};
}

Expand Down
136 changes: 82 additions & 54 deletions application/src/ui/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,61 +353,89 @@ function App() {
</Box>
</Card>

<Card sx={{
mr: 2,
ml: 2,
mb: 1,
mt: 1,
height: "100%",
minHeight: "calc(100vh - 124px)",
maxHeight: "calc(100vh - 124px)"
}}>
<Tabs
value={selectedTab}
onChange={(_, v) => setSelectedTab(v)}
variant="fullWidth"
>
<Tooltip title="Status" arrow><Tab icon={<MonitorHeartIcon />} /></Tooltip>
<Tooltip title="Profiles" arrow><Tab icon={<LibraryMusicIcon />} /></Tooltip>
<Tooltip title="Application Rules" arrow><Tab icon={<GavelIcon />} /></Tooltip>
<Tooltip title="About" arrow><Tab icon={<InfoIcon />} /></Tooltip>
</Tabs>

{selectedTab === 0 && (
<Status
statusLoaded={statusLoaded}
status={status}
profilesLoaded={profilesLoaded}
profiles={profiles}
selectedProfile={selectedProfile}
displayVolume={displayVolume}
onProfileChanged={handleProfileChanged}
onVolumeChanged={handleVolumeChanged}
onDisplayVolumeChanged={setDisplayVolume}
/>
)}

{selectedTab === 1 && (
<Profiles statusLoaded={statusLoaded} status={status} profilesLoaded={profilesLoaded} profiles={profiles} />
)}

{selectedTab === 2 && (
<AppRules
appRules={appRules}
appRulesLoaded={appRulesLoaded}
enabledRulesAreExclusive={enabledRulesAreExclusive}
globalAction={globalAction}
onGlobalActionChanged={handleGlobalActionChanged}
/>
)}

{selectedTab === 3 && (
<Settings
appVersion={appVersion}
backEndVersion={backEndVersion} />
)}
{!statusLoaded && (
<Card sx={{
mr: 2,
ml: 2,
mb: 1,
mt: 1,
height: "100%",
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
minHeight: "calc(100vh - 124px)",
maxHeight: "calc(100vh - 124px)"
}}>
<Box sx={{
display: "flex",
flexDirection: "row",
alignItems: "center",
justifyContent: "space-between",
}}>
<CircularProgress sx={{ color: "#fff" }} size={48} />
</Box>
</Card>
)}

</Card>
{statusLoaded && (
<Card sx={{
mr: 2,
ml: 2,
mb: 1,
mt: 1,
height: "100%",
minHeight: "calc(100vh - 124px)",
maxHeight: "calc(100vh - 124px)"
}}>
<Tabs
value={selectedTab}
onChange={(_, v) => setSelectedTab(v)}
variant="fullWidth"
>
<Tooltip title="Status" arrow><Tab icon={<MonitorHeartIcon />} /></Tooltip>
<Tooltip title="Profiles" arrow><Tab icon={<LibraryMusicIcon />} /></Tooltip>
<Tooltip title="Application Rules" arrow><Tab icon={<GavelIcon />} /></Tooltip>
<Tooltip title="About" arrow><Tab icon={<InfoIcon />} /></Tooltip>
</Tabs>

{selectedTab === 0 && (
<Status
statusLoaded={statusLoaded}
status={status}
profilesLoaded={profilesLoaded}
profiles={profiles}
selectedProfile={selectedProfile}
displayVolume={displayVolume}
onProfileChanged={handleProfileChanged}
onVolumeChanged={handleVolumeChanged}
onDisplayVolumeChanged={setDisplayVolume}
/>
)}

{selectedTab === 1 && (
<Profiles statusLoaded={statusLoaded} status={status} profilesLoaded={profilesLoaded} profiles={profiles} />
)}

{selectedTab === 2 && (
<AppRules
appRules={appRules}
appRulesLoaded={appRulesLoaded}
enabledRulesAreExclusive={enabledRulesAreExclusive}
globalAction={globalAction}
onGlobalActionChanged={handleGlobalActionChanged}
/>
)}

{selectedTab === 3 && (
<Settings
appVersion={appVersion}
backEndVersion={backEndVersion} />
)}

</Card>
)}

</ThemeProvider>
);
}
Expand Down
3 changes: 2 additions & 1 deletion keyboardsounds/daemon_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def __load_status(self):
proc_name = self.__proc.name()
current_name = psutil.Process().name()
self.__is_daemon_process = proc_name == current_name
except ValueError:
except:
self.__proc = None
pass
else:
self.__is_daemon_process = False
Expand Down
20 changes: 20 additions & 0 deletions keyboardsounds/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,26 @@ def main():
elif args.action == "status":
status = dm.status(full=not args.short, short=args.short)
print(f"{status}")
elif args.action == "state":
rules = get_rules()
output = {
"global_action": rules.global_action.value,
"rules": [
{"app_path": rule.app_path, "action": rule.action.value}
for rule in rules.rules
],
"profiles": [
{
"name": profile["name"],
"author": profile["author"],
"description": profile["description"],
}
for profile in [profile.metadata() for profile in Profile.list()]
],
"status": json.loads(dm.status(full=False, short=True)),
}

print(json.dumps(output))
elif args.action == "add-profile" or args.action == "ap":
if args.zip is None:
print("Please specify a zip file for the profile to add.")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "keyboardsounds"
version = "5.8.9"
version = "5.9.0"
authors = [
{ name="Nathan Fiscaletti", email="[email protected]" },
]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="keyboardsounds",
version="5.8.9",
version="5.9.0",
description="Adds the ability to play sounds while typing on any system.",
author="Nathan Fiscaletti",
author_email="[email protected]",
Expand Down

0 comments on commit 1c24105

Please sign in to comment.