Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:electron: Remove unneeded logger and add reload functionality #3599

Merged

Conversation

MikesGlitch
Copy link
Contributor

@MikesGlitch MikesGlitch commented Oct 7, 2024

We don't use electron-logger for anything. The logs are buried in a hidden directory and we only log the server sync status. Instead of logging there, I've put the log messages into the console (which is what the web version does). It will be easier for users to see them there.

Someone asked for the ability to reload the app inside of electron - I've enabled it in the menu.

Copy link

netlify bot commented Oct 7, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 7eeda31
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/67043999f5db8e00083287b2
😎 Deploy Preview https://deploy-preview-3599.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@MikesGlitch MikesGlitch marked this pull request as ready for review October 7, 2024 19:43
Copy link
Contributor

github-actions bot commented Oct 7, 2024

Bundle Stats — desktop-client

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
9 5.31 MB 0%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/AppliedFilters.js 20.96 kB 0%
static/js/usePreviewTransactions.js 1.64 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/narrow.js 82.55 kB 0%
static/js/wide.js 224.55 kB 0%
static/js/ReportRouter.js 1.5 MB 0%
static/js/index.js 3.33 MB 0%

Copy link
Contributor

github-actions bot commented Oct 7, 2024

Bundle Stats — loot-core

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
1 1.19 MB 0%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
kcab.worker.js 1.19 MB 0%

Copy link
Contributor

coderabbitai bot commented Oct 7, 2024

Walkthrough

The pull request introduces several changes across multiple files in the desktop-electron and loot-core packages. In packages/desktop-electron/menu.ts, the getMenu function is modified to always include a 'Reload' menu item under the 'View' submenu, removing the previous conditional check for isDev. The click handler for 'Reload' has been clarified, ensuring it checks for the existence of focusedWindow before calling focusedWindow.reload(). Additionally, a new 'Speech' submenu is added under 'Edit', and a 'Close' menu item is now present in the 'Window' submenu.

In the loot-core package, logging functionality is revised. The dependency on electron-log is removed from package.json, leading to changes in logging implementations across various files (index.api.ts, index.electron.ts, index.web.ts, and index.d.ts). The Logger type is now imported directly, and the logger object is simplified to use console logging methods instead of file-based logging. The Webpack configuration is also updated to reflect the removal of electron-log from the externals array.

Possibly related PRs

Suggested labels

:sparkles: Merged, :white_check_mark: Approved

Suggested reviewers

  • youngcw
  • joel-jeremy

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
packages/loot-core/src/platform/server/log/index.web.ts (1)

Line range hint 3-10: LGTM: Logger implementation aligns with PR objectives.

The logger object implementation correctly redirects logs to the console, aligning with the PR objective and the web version of the application. This simple approach is appropriate for the stated goals.

Consider adding an error method to the logger for consistency with common logging practices:

export const logger: Logger = {
  info: (...args) => {
    console.log(...args);
  },
  warn: (...args) => {
    console.warn(...args);
  },
  error: (...args) => {
    console.error(...args);
  },
};

This addition would provide a dedicated method for logging errors, which could be useful for distinguishing between different levels of issues in the application.

packages/loot-core/webpack/webpack.desktop.config.js (1)

Line range hint 1-45: Consider enhancing configuration clarity and maintainability.

While the current configuration is functional, consider the following suggestions to improve clarity and maintainability:

  1. Add comments explaining the purpose of each plugin and major configuration section.
  2. Consider extracting common configurations shared between browser and desktop into a separate file to reduce duplication.
  3. Use environment variables for values that might change between development and production builds (e.g., devtool setting).
  4. Consider using TypeScript for the Webpack configuration to leverage type checking and better IDE support.

Here's an example of how you could start implementing these suggestions:

 const path = require('path');
 const webpack = require('webpack');
 const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
 const browser = require('./webpack.browser.config');
+
+// Use environment variables for flexible configuration
+const isDevelopment = process.env.NODE_ENV !== 'production';
 
 /** @type {webpack.Configuration} */
 module.exports = {
   ...browser,
   target: 'node',
-  devtool: 'source-map',
+  devtool: isDevelopment ? 'eval-source-map' : 'source-map',
   output: {
     path: path.resolve(path.join(__dirname, '/../lib-dist')),
     filename: 'bundle.desktop.js',
     sourceMapFilename: 'bundle.desktop.js.map',
     libraryTarget: 'commonjs2',
   },
   resolve: {
     extensions: [
       '.electron.js',
       '.electron.ts',
       '.electron.tsx',
       '.js',
       '.ts',
       '.tsx',
       '.json',
       'pegjs',
     ],
   },
   externals: ['better-sqlite3', 'node-fetch'],
   plugins: [
+    // Ignore 'original-fs' module as it's not needed
     new webpack.IgnorePlugin({
       resourceRegExp: /original-fs/,
     }),
+    // Generate bundle analysis stats file
     new BundleAnalyzerPlugin({
       analyzerMode: 'disabled',
       generateStatsFile: true,
     }),
   ],
+  // Preserve __dirname and __filename
   node: {
     __dirname: false,
     __filename: false,
   },
 };

These changes introduce comments, use an environment variable for the devtool setting, and generally improve the readability of the configuration.

packages/loot-core/src/platform/server/log/index.electron.ts (1)

3-10: Consider the implications of using console.log in Electron

Switching from electron-log to console.log and console.warn may affect how logs are accessed, especially in production builds. In packaged Electron applications, console output might not be readily visible or accessible for debugging purposes. This change could make it harder to diagnose issues reported by users.

Consider implementing a logging strategy that balances accessibility and usability. Options include:

  • Using electron-log with adjusted settings: Configure electron-log to output to both console and file, making logs accessible during development and after deployment.
  • Implementing a custom logger: Create a logger that writes to a visible UI component or a user-accessible log file within the application.

This ensures that essential log information remains available for troubleshooting in all environments.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e653ad3 and 7eeda31.

⛔ Files ignored due to path filters (2)
  • upcoming-release-notes/3599.md is excluded by !**/*.md
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (7)
  • packages/desktop-electron/menu.ts (1 hunks)
  • packages/desktop-electron/package.json (0 hunks)
  • packages/loot-core/src/platform/server/log/index.api.ts (1 hunks)
  • packages/loot-core/src/platform/server/log/index.d.ts (0 hunks)
  • packages/loot-core/src/platform/server/log/index.electron.ts (1 hunks)
  • packages/loot-core/src/platform/server/log/index.web.ts (1 hunks)
  • packages/loot-core/webpack/webpack.desktop.config.js (1 hunks)
💤 Files with no reviewable changes (2)
  • packages/desktop-electron/package.json
  • packages/loot-core/src/platform/server/log/index.d.ts
🧰 Additional context used
📓 Learnings (1)
packages/loot-core/webpack/webpack.desktop.config.js (1)
Learnt from: MikesGlitch
PR: actualbudget/actual#3553
File: packages/desktop-electron/package.json:88-88
Timestamp: 2024-10-04T08:48:55.161Z
Learning: In the `desktop-electron` module, `loot-core`'s essential files are intentionally copied during packaging using `electron-builder`. Therefore, references to `loot-core` in the codebase are expected and should remain, even though the `loot-core` dependency is removed from `package.json`.
🔇 Additional comments (9)
packages/loot-core/src/platform/server/log/index.api.ts (3)

1-1: Improved import statement

The change to directly import the Logger type is a good practice. It enhances code readability and aligns with TypeScript best practices by importing only what's needed.


Line range hint 1-10: Summary: Changes align with PR objectives

The modifications in this file contribute effectively to the PR's goal of simplifying the logging system. By redirecting logs to the console, the implementation now aligns better with the web version of the application. The changes are minimal yet impactful, improving code clarity and maintainability.


Line range hint 3-10: Type annotation updated correctly, but verify Logger interface

The type annotation change for the logger constant is consistent with the updated import. The implementation redirects logs to the console as intended in the PR objectives.

However, it's important to verify that this implementation fully adheres to the Logger interface. The current implementation only includes info and warn methods, which might not cover all methods defined in the Logger interface.

To ensure full compliance with the Logger interface, please run the following script:

This will help us confirm that all required methods are implemented in the logger object.

✅ Verification successful

Logger interface correctly implemented

The logger object fully adheres to the Logger interface, implementing all required methods.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the Logger interface implementation

# Test: Check the Logger interface definition
echo "Checking Logger interface definition:"
ast-grep --lang typescript --pattern 'interface Logger {
  $$$
}'

# Test: Compare with the current implementation
echo "Comparing with current implementation:"
ast-grep --lang typescript --pattern 'const logger: Logger = {
  $$$
}'

Length of output: 2500

packages/loot-core/src/platform/server/log/index.web.ts (2)

1-1: LGTM: Import statement updated correctly.

The import statement has been updated to specifically import the Logger type, which aligns with the PR objective of simplifying the logging mechanism. This change improves code clarity and potentially reduces bundle size.


3-3: LGTM: Logger type annotation updated correctly.

The type annotation for the logger constant has been updated to use the imported Logger type directly. This change is consistent with the updated import statement and maintains type safety while simplifying the code.

packages/loot-core/webpack/webpack.desktop.config.js (1)

31-31: Removal of 'electron-log' from externals aligns with PR objectives.

The removal of 'electron-log' from the externals array is consistent with the PR's goal of removing the unnecessary logging mechanism. This change means that 'electron-log' will no longer be treated as an external dependency in the Webpack build process for the desktop application.

However, to ensure this change is fully implemented:

  1. Verify that all imports of 'electron-log' have been removed or replaced in the codebase.
  2. Confirm that the package.json file no longer lists 'electron-log' as a dependency.
  3. Update any documentation or comments referencing 'electron-log' usage.

Let's verify the complete removal of 'electron-log':

✅ Verification successful

Verified: 'electron-log' has been successfully removed from the codebase.

All references to 'electron-log' have been eliminated:

  • No imports or requires of 'electron-log' are present in the codebase.
  • 'electron-log' is no longer listed in the package.json dependencies or devDependencies.
  • There are no remaining 'electron-log' strings in the codebase files.

This confirms that the removal aligns with the PR objectives and does not leave any residual dependencies or references.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining references to 'electron-log'

# Test 1: Search for 'electron-log' imports or requires
echo "Searching for 'electron-log' imports or requires:"
rg --type ts --type js "(?:import|require).*['\"]electron-log['\"]"

# Test 2: Check if 'electron-log' is still in package.json
echo "Checking package.json for 'electron-log':"
jq '.dependencies["electron-log"] // .devDependencies["electron-log"] // "Not found"' package.json

# Test 3: Look for any remaining 'electron-log' string in the codebase
echo "Searching for any 'electron-log' strings in the codebase:"
rg --type ts --type js "electron-log"

Length of output: 569

packages/desktop-electron/menu.ts (2)

109-117: Approved: Reload functionality added and improved

The changes to the 'Reload' menu item in the 'View' submenu are well-implemented:

  1. The 'Reload' option is now always available, fulfilling the PR objective of adding reload functionality.
  2. The click handler has been improved with a null check for focusedWindow, enhancing code robustness.

These modifications align with the PR goals and represent a positive improvement to the application's functionality and code quality.


Line range hint 1-283: Verify additional changes mentioned in the AI summary

The AI-generated summary mentions changes to the 'Edit' and 'Window' submenus, including:

  1. Addition of a 'Speech' submenu under 'Edit'
  2. Addition of a 'Close' menu item in the 'Window' submenu

However, these changes are not visible in the provided code snippet. Could you please confirm if these changes have been implemented as described in the summary?

To verify these changes, please run the following script:

✅ Verification successful

Retrying verification of 'Speech' submenu and 'Close' menu item

The previous script failed due to an unrecognized file type. Please run the following scripts without specifying the file type:


Verification Successful: 'Speech' Submenu and 'Close' Menu Item Present

The verification scripts confirmed that both the 'Speech' submenu under the 'Edit' menu and the 'Close' menu item in the 'Window' menu are present in packages/desktop-electron/menu.ts as described in the AI summary.

  • 'Speech' submenu exists under the 'Edit' menu.
  • 'Close' menu item exists in the 'Window' menu.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the presence of 'Speech' submenu and 'Close' menu item

# Test 1: Check for 'Speech' submenu in 'Edit' menu
echo "Checking for 'Speech' submenu:"
rg --type typescript "label: 'Speech'" packages/desktop-electron/menu.ts

# Test 2: Check for 'Close' menu item in 'Window' menu
echo "Checking for 'Close' menu item:"
rg --type typescript "label: 'Close'" packages/desktop-electron/menu.ts

Length of output: 386


Script:

#!/bin/bash
# Description: Verify the presence of 'Speech' submenu and 'Close' menu item

# Test 1: Check for 'Speech' submenu in 'Edit' menu
echo "Checking for 'Speech' submenu:"
rg "label: 'Speech'" packages/desktop-electron/menu.ts

# Test 2: Check for 'Close' menu item in 'Window' menu
echo "Checking for 'Close' menu item:"
rg "label: 'Close'" packages/desktop-electron/menu.ts

Length of output: 329

packages/loot-core/src/platform/server/log/index.electron.ts (1)

1-1: ⚠️ Potential issue

Verify all logging methods are implemented in the logger object

The Logger interface is imported, and the logger object implements info and warn methods. Ensure that there are no other logging methods like debug, error, or verbose used elsewhere in the codebase that would require implementation to prevent runtime errors.

Run the following script to check for usages of other logging methods:

If this script outputs any method names, consider adding those methods to the logger implementation.

Copy link
Member

@youngcw youngcw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@MikesGlitch MikesGlitch merged commit 464d987 into actualbudget:master Oct 8, 2024
20 checks passed
@MikesGlitch MikesGlitch deleted the electron/remove-unneeded-logger branch October 8, 2024 15:46
@coderabbitai coderabbitai bot mentioned this pull request Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants