Skip to content

Commit

Permalink
Solara
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarAliKml committed Sep 25, 2024
1 parent 84a65ef commit 8ac85fc
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
15 changes: 15 additions & 0 deletions solara/lib/core/brands/brands_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,23 @@ def add_brand(brand_name, brand_key)
end
end

def has_current_brand
value = File.exist?(FilePath.current_brand)
Solara.logger.debug("No current brand!") unless value
value
end

def current_brand
unless has_current_brand
return nil
end
JSON.parse(File.read(FilePath.current_brand))
end

def set_current_brand_content_changed(brand_key, changed)
unless has_current_brand
return nil
end
unless is_current_brand(brand_key)
return false
end
Expand All @@ -71,6 +83,9 @@ def set_current_brand_content_changed(brand_key, changed)
end

def is_current_brand(brand_key)
unless has_current_brand
return false
end
current_brand['key'] == brand_key
end

Expand Down
2 changes: 1 addition & 1 deletion solara/lib/core/dashboard/handler/brand_icon_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def mount
brand_key = req.query['brand_key']
filepath = FilePath.launcher_icon(brand_key)
if File.exist?(filepath)
res.body = File.read(filepath)
res.body = File.binread(filepath) # Use binread for binary files
res['Content-Type'] = 'image/png' # Adjust as necessary
else
res.status = 404
Expand Down
16 changes: 15 additions & 1 deletion solara/lib/core/doctor/doctor_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ def visit_project!
Solara.logger.end_step("Project Health Check")
end

def ensure_switched
unless File.exist?(FilePath.current_brand)
message = <<-MESSAGE
It looks like you haven't switched to a brand yet!
You can open the dashboard by running 'solara dashboard' in your terminal and make the switch there.
Alternatively, you can execute 'solara switch YOUR_BRAND_KEY_HERE' in your terminal.
MESSAGE
Solara.logger.error(message)
return false
end
return true
end

private

def ensure_initialized!
Expand All @@ -31,4 +44,5 @@ def ensure_initialized!
exit 1
end
end
end

end
4 changes: 4 additions & 0 deletions solara/lib/core/scripts/solara_status_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def start
end

def current_brand_draft
unless DoctorManager.new.ensure_switched
return
end

current_brand = BrandsManager.instance.current_brand
unless current_brand
return
Expand Down
6 changes: 4 additions & 2 deletions solara/lib/solara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,10 @@ def ensure_platform
end
end

def check_project_health
DoctorManager.new.visit_project!
def check_project_health(ensure_switched: false)
manager = DoctorManager.new
manager.visit_project!
manager.ensure_switched if ensure_switched
end

def validate_brand_key(brand_key, ignore_if_nil: false, ignore_brand_check: false, message: nil)
Expand Down

0 comments on commit 8ac85fc

Please sign in to comment.