Skip to content

Commit

Permalink
fix: status bar icon hidden after first run
Browse files Browse the repository at this point in the history
  • Loading branch information
muuvmuuv committed Jul 7, 2023
1 parent 00138ef commit 2efc757
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 19 deletions.
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
- [Automatically set by OS appearance](#automatically-set-by-os-appearance)
- [VS Code Settings](#vs-code-settings)
- [Execution order](#execution-order)
- [Status bar icon](#status-bar-icon)
- [Examples](#examples)
- [Development](#development)
- [Deployment](#deployment)
- [Pre-release](#pre-release)
- [Commits](#commits)

Sundial changes your theme and VS Code settings (if needed) based on your day and night
Expand All @@ -32,6 +34,9 @@ working in the night or on the day. Humans should not strain their eyes too much
Whenever you have ideas for this project, things you would like to add or you found a bug,
feel free to create an issue or start contributing! 😇

> The minimum supported VS Code version is
> [1.74.3](https://github.com/microsoft/vscode/tree/1.74.3)
<p>
<a href="https://www.buymeacoffee.com/devmuuv" target="_blank">
<img src="https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png" alt="Buy me a Gluten-free Bread" />
Expand Down Expand Up @@ -79,7 +84,8 @@ banner below:
| Sundial: Disable extension | Disables extension. |
| Sundial: Pause until next circle | Pause until next day/night circle. |

> Note: Whenever you use one of the first three commands, Sundial will be disabled.
> Note: Whenever you use one of the first three commands, Sundial will disable its
> automatic checks.
## Settings

Expand All @@ -95,13 +101,16 @@ banner below:
| `sundial.nightVariable` | _0_ | Set a variable to change the theme **X minutes** before or after sunset. |
| `sundial.daySettings` | _{}_ | An **object** of VSCode settings applied on the day. |
| `sundial.nightSettings` | _{}_ | An **object** of VSCode settings applied on the night. |
| `sundial.statusBarItemPriority` | _100_ | Set the status bar icon position (higher mean more left). |
| `sundial.interval` | _5_ | Set a interval in which sundial should check the time in **minutes**. |

> ⚠️ Don't forget to set `"window.autoDetectColorScheme": false`
> If you set the interval to zero (0) sundial will not periodically check the time but
> still when VS Code triggers some editor events.
> Any changes to sundial or VS Code settings will re-enable Sundial.
> On both `daySettings` and `nightSettings` they will override your Workbench VSCode
> settings. Please make sure both have the same properties otherwise they will not change
> since Sundial is not remembering the settings you have set before!
Expand Down Expand Up @@ -165,6 +174,13 @@ next coming will be ignored.
2. `sundial.autoLocale`
3. `sundial.sunrise` and `sundial.sunset`

### Status bar icon

![Status bar icon](https://raw.githubusercontent.com/muuvmuuv/vscode-sundial/main/assets/status-bar-icon.png)

Sundial will show a status bar icon that will toggle the current theme on click. This will
also disable all sundial automated checks.

### Examples

```jsonc
Expand Down Expand Up @@ -208,7 +224,7 @@ next coming will be ignored.
I am working with [**esbuild**](https://esbuild.github.io/) to bundle Sundial to the
smallest possible size to increase the load time in VS Code _for you_.

> Currently minimum supported VS Code Version
> The minimum supported VS Code version is
> [1.74.3](https://github.com/microsoft/vscode/tree/1.74.3)
1. Install packages via npm: `npm run install` (_pnpm_ does not work due to
Expand All @@ -221,6 +237,13 @@ smallest possible size to increase the load time in VS Code _for you_.

### Deployment

We use `release-it` to create a new release. This will automatically create a tag, release
and new changelog for us.

```
pnpm release-it --help
```

Sundial is deployed on VS Code Marketplace and Open VSX.

- VS Code Marketplace:
Expand All @@ -229,6 +252,16 @@ Sundial is deployed on VS Code Marketplace and Open VSX.
- `vsce package`
- `./node_modules/.bin/ovsx publish *.vsix -p TOKEN`

#### Pre-release

We update our version with release-it, so we must use some additional flags for `vsce`.
The version must be without pre-release identifier, because VS Code Marketplace does not
allow those.

```
pnpm vsce publish --pre-release --no-git-tag-version --no-update-package-json <pre_release_version>
```

### Commits

Sundial follows the `config-conventional` spec.
Binary file added assets/status-bar-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function configChanged(event: ConfigurationChangeEvent) {
event.affectsConfiguration('workbench.preferredDarkColorTheme') ||
event.affectsConfiguration('workbench.preferredDarkColorTheme')
) {
check()
sundial.enableExtension()
}
}

Expand Down
34 changes: 18 additions & 16 deletions src/sundial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default class Sundial {
this.nextCircle = undefined
this.automator()
this.check()
this.createStatusBarIcon()
}

/**
Expand All @@ -69,7 +70,6 @@ export default class Sundial {
log.info('Disabling Sundial')
Sundial.extensionContext.globalState.update(STATE_ENABLED, false)
this.killAutomator()
this.statusBarItem?.dispose()
}

/**
Expand Down Expand Up @@ -148,8 +148,6 @@ export default class Sundial {
}
}

this.setStatusIconToggle()

await sleep(400) // Short nap 😴

this.isRunning = false
Expand All @@ -170,22 +168,26 @@ export default class Sundial {
/**
* Set the status bar icon to toggle the theme.
*/
private setStatusIconToggle(): void {
this.statusBarItem?.dispose()

if (!this.statusBarItem) {
const { sundial } = editor.getConfig()
private createStatusBarIcon(): void {
if (this.statusBarItem) {
this.statusBarItem.dispose()
}

this.statusBarItem = window.createStatusBarItem(
StatusBarAlignment.Right,
sundial.statusBarItemPriority,
)
this.statusBarItem.command = 'sundial.toggleDayNightTheme'
this.statusBarItem.text = '$(color-mode)'
this.statusBarItem.tooltip = 'Toggle day/night theme'
const { sundial } = editor.getConfig()

Sundial.extensionContext.subscriptions.push(this.statusBarItem)
this.statusBarItem = window.createStatusBarItem(
StatusBarAlignment.Right,
sundial.statusBarItemPriority,
)
this.statusBarItem.accessibilityInformation = {
label: 'Toggle day/night theme',
role: 'button',
}
this.statusBarItem.command = 'sundial.toggleDayNightTheme'
this.statusBarItem.text = '$(color-mode)'
this.statusBarItem.tooltip = 'Toggle day/night theme'

Sundial.extensionContext.subscriptions.push(this.statusBarItem)

this.statusBarItem.show()
}
Expand Down
1 change: 1 addition & 0 deletions testProject/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"sundial.nightVariable": -60,
"sundial.daySettings": {},
"sundial.nightSettings": {},
"sundial.statusBarItemPriority": 101,
"sundial.interval": 2
}

0 comments on commit 2efc757

Please sign in to comment.