Skip to content

Commit 6bfb6e3

Browse files
committed
Enhance null-safe checks in SmartEnv and SmartNotices
- Update SmartEnv to improve null-safe checks for the 'smart-connections' plugin, ensuring proper handling of older environments. - Modify SmartNotices constructor to use optional chaining for environment getter, enhancing robustness. - Maintain existing comments and methods unrelated to the changes.
1 parent 69e5039 commit 6bfb6e3

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

obsidian-smart-env/smart_env.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ export class SmartEnv extends BaseSmartEnv {
1111
static async create(plugin, main_env_opts = {}) {
1212
// Special handling for old Obsidian smart environments
1313
// Detect if environment has 'init_main'
14-
if (plugin.app.plugins.plugins['smart-connections'] && !plugin.app.plugins.plugins['smart-connections']?.env?.constructor?.version) {
14+
if (plugin.app.plugins.plugins['smart-connections']
15+
&& plugin.app.plugins.plugins['smart-connections'].env
16+
&& !plugin.app.plugins.plugins['smart-connections'].env.constructor.version
17+
) {
1518
const update_notice = "Detected older SmartEnv with 'init_main'. Reloading without the outdated plugin. Please update Smart Connections.";
1619
// Attempt a user-visible notice if Obsidian's Notice is in scope, otherwise warn:
1720
console.warn(update_notice);

smart-notices/smart_notices.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ export class SmartNotices {
7979
* @param {Object} scope - The main plugin instance
8080
*/
8181
constructor(env, adapter=null) {
82-
this.env = env;
83-
this.env.create_env_getter(this); // sets this.env
82+
env?.create_env_getter(this); // sets this.env
8483
this.active = {};
8584
this.adapter = adapter || this.env.config.modules.smart_notices.adapter;
8685
// Make sure each notice entry has a .create() method

0 commit comments

Comments
 (0)