Skip to content

Commit

Permalink
fix: inconsistency in command for opening widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger committed Sep 27, 2024
1 parent f2d7b1a commit 84d38fe
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
6 changes: 3 additions & 3 deletions packages/client-api/src/desktop/desktop-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import type { ProviderConfig } from '~/providers';
const logger = createLogger('desktop-commands');

export const desktopCommands = {
startWidget,
openWidgetDefault,
listenProvider,
unlistenProvider,
setAlwaysOnTop,
setSkipTaskbar,
};

function startWidget(configPath: string): Promise<void> {
return invoke<void>('start_widget', { configPath });
function openWidgetDefault(configPath: string): Promise<void> {
return invoke<void>('open_widget_default', { configPath });
}

function listenProvider(args: {
Expand Down
8 changes: 5 additions & 3 deletions packages/client-api/src/desktop/widgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ export function currentWidget(): Widget {
}

/**
* Opens a new widget instance by a relative path to its config file.
* Opens a widget by its config path. Uses its default placements.
*
* Config path is relative within the Zebar config directory.
*/
export async function startWidget(configPath: string) {
export async function openWidgetDefault(configPath: string) {
// Ensure the config path ends with '.zebar.json'.
const filePath = configPath.endsWith('.zebar.json')
? configPath
Expand All @@ -58,5 +60,5 @@ export async function startWidget(configPath: string) {
filePath,
);

return desktopCommands.startWidget(absolutePath);
return desktopCommands.openWidgetDefault(absolutePath);
}
2 changes: 1 addition & 1 deletion packages/client-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export * from './providers';
export {
currentWidget,
currentWindow,
startWidget,
openWidgetDefault,
type Widget,
type Window,
} from './desktop';
6 changes: 3 additions & 3 deletions packages/desktop/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ pub enum CliCommand {
/// Opens a widget by its config path. Uses its default placements.
///
/// Config path is relative within the Zebar config directory (e.g.
/// `zebar open-widget ./material/config.yaml`).
/// `zebar open-widget-default ./material/config.yaml`).
///
/// Starts Zebar if it is not already running.
OpenWidgetDefaults(OpenWidgetDefaultsArgs),
OpenWidgetDefault(OpenWidgetDefaultArgs),

/// Opens all widgets that are set to launch on startup.
///
Expand All @@ -47,7 +47,7 @@ pub enum CliCommand {
}

#[derive(Args, Clone, Debug, PartialEq)]
pub struct OpenWidgetDefaultsArgs {
pub struct OpenWidgetDefaultArgs {
/// Relative file path to widget config within the Zebar config
/// directory.
pub config_path: PathBuf,
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
};

#[tauri::command]
pub async fn start_widget(
pub async fn open_widget_default(
config_path: String,
config: State<'_, Arc<Config>>,
widget_factory: State<'_, Arc<WidgetFactory>>,
Expand Down
6 changes: 3 additions & 3 deletions packages/desktop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn start_app(cli: Cli) -> anyhow::Result<()> {
task::block_in_place(|| {
block_on(async move {
let config_dir_override = match cli.command() {
CliCommand::OpenWidgetDefaults(args) => args.config_dir,
CliCommand::OpenWidgetDefault(args) => args.config_dir,
CliCommand::Startup(args) => args.config_dir,
_ => None,
};
Expand Down Expand Up @@ -166,7 +166,7 @@ fn start_app(cli: Cli) -> anyhow::Result<()> {
})
})
.invoke_handler(tauri::generate_handler![
commands::start_widget,
commands::open_widget_default,
commands::listen_provider,
commands::unlisten_provider,
commands::set_always_on_top,
Expand Down Expand Up @@ -273,7 +273,7 @@ async fn open_widgets_by_cli_command(
widget_factory: Arc<WidgetFactory>,
) -> anyhow::Result<()> {
let widget_configs = match cli.command() {
CliCommand::OpenWidgetDefaults(args) => {
CliCommand::OpenWidgetDefault(args) => {
let widget_config = config
.widget_config_by_path(&config.join_config_dir(&args.config_path))
.await?
Expand Down

0 comments on commit 84d38fe

Please sign in to comment.