Skip to content

Commit

Permalink
Added code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
blotspot committed Dec 28, 2024
1 parent 0dda1ec commit 037bb72
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 32 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Obsidian WakeLock Plugin
# Screen WakeLock Plugin

This is a tniy plugin for [Obsidian](https://obsidian.md).
This is a plugin for [Obsidian](https://obsidian.md).

It's only purpose is to stop your device from dimming or locking the screen. Use it at your own leisure, as an always active screen will impact your device battery.

Expand Down
10 changes: 5 additions & 5 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ import esbuild from "esbuild";
import process from "process";
import builtins from "builtin-modules";

const banner =
`/*
const banner = `/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
`;

const prod = (process.argv[2] === "production");
const prod = process.argv[2] === "production";

const context = await esbuild.context({
banner: {
js: banner,
},
entryPoints: ["main.ts"],
entryPoints: ["src/plugin.ts"],
bundle: true,
external: [
"obsidian",
Expand All @@ -31,7 +30,8 @@ const context = await esbuild.context({
"@lezer/common",
"@lezer/highlight",
"@lezer/lr",
...builtins],
...builtins,
],
format: "cjs",
target: "es2018",
logLevel: "info",
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"id": "screen-wake-lock",
"name": "Screen WakeLock",
"version": "1.0.3",
"version": "1.0.4",
"minAppVersion": "0.15.0",
"description": "Allows to keep a wake lock on the display, using the w3 WakeLock API.",
"description": "Keeps the display awake while Obsidian is in the foreground.",
"author": "blotspot",
"authorUrl": "https://github.com/blotspot",
"fundingUrl": "https://ko-fi.com/blotspot",
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"name": "screen-wake-lock",
"version": "1.0.3",
"description": "Allows to keep a wake lock on the display, using the w3 WakeLock API.",
"version": "1.0.4",
"main": "main.js",
"scripts": {
"dev": "node esbuild.config.mjs",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"version": "node version-bump.mjs && git add manifest.json versions.json"
},
"keywords": [],
"author": "",
"author": "blotspot",
"license": "MIT",
"devDependencies": {
"@types/dom-screen-wake-lock": "^1.0.3",
Expand Down
2 changes: 1 addition & 1 deletion src/log.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export class Log {
public static devMode = true;
public static devMode = false;

public static d(msg: string) {
if (Log.devMode) {
Expand Down
11 changes: 4 additions & 7 deletions main.ts → src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { MarkdownView, Notice, Plugin, WorkspaceLeaf } from "obsidian";
import { WakeLock } from "./src/wake-lock";
import { WakeLockStatusBarItem } from "./src/statusbar";
import { Log } from "./src/log";
import {
WakeLockPluginSettings,
WakeLockPluginSettingsData,
} from "./src/settings";
import { WakeLock } from "./wake-lock";
import { WakeLockStatusBarItem } from "./statusbar";
import { Log } from "./log";
import { WakeLockPluginSettings, WakeLockPluginSettingsData } from "./settings";

export default class WakeLockPlugin extends Plugin {
private settings: WakeLockPluginSettings;
Expand Down
21 changes: 9 additions & 12 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { App, PluginSettingTab, Setting } from "obsidian";
import WakeLockPlugin from "../main";
import { App, Plugin, PluginSettingTab, Setting } from "obsidian";

interface SettingsEventMap {
active: CustomEvent<WakeLockPluginSettingsData>;
Expand Down Expand Up @@ -27,10 +26,10 @@ const TypedEventTarget = EventTarget as {
};

export class WakeLockPluginSettings extends TypedEventTarget {
context: WakeLockPlugin;
context: Plugin;
data: WakeLockPluginSettingsData;

static async load(context: WakeLockPlugin) {
static async load(context: Plugin) {
const handler = new WakeLockPluginSettings(context);
await handler.loadSettings();
context.addSettingTab(
Expand All @@ -39,7 +38,7 @@ export class WakeLockPluginSettings extends TypedEventTarget {
return handler;
}

private constructor(context: WakeLockPlugin) {
private constructor(context: Plugin) {
super();
this.context = context;
}
Expand Down Expand Up @@ -108,11 +107,7 @@ export const DEFAULT_SETTINGS: WakeLockPluginSettingsData = {
export class WakeLockSettingsTab extends PluginSettingTab {
settings: WakeLockPluginSettings;

constructor(
app: App,
plugin: WakeLockPlugin,
settings: WakeLockPluginSettings
) {
constructor(app: App, plugin: Plugin, settings: WakeLockPluginSettings) {
super(app, plugin);
this.settings = settings;
}
Expand Down Expand Up @@ -145,7 +140,7 @@ export class WakeLockSettingsTab extends PluginSettingTab {
);

new Setting(containerEl)
.setName("Hide Notifications")
.setName("Hide notifications")
.setDesc(
"Hide all notification messages about enable / disable events."
)
Expand All @@ -159,7 +154,9 @@ export class WakeLockSettingsTab extends PluginSettingTab {

new Setting(containerEl)
.setName("Show in status bar")
.setDesc("Shows the WakeLock state in the statusbar.")
.setDesc(
"Adds an icon to the status bar, showing the current WakeLock state."
)
.addToggle((toggle) =>
toggle
.setValue(this.settings.data.showInStatusBar)
Expand Down

0 comments on commit 037bb72

Please sign in to comment.